Commit 8bada24b authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Add pagination

parent de1fbb85
......@@ -84,8 +84,9 @@ ASTAKOS_QUOTA_HOLDER_URL ''
ASTAKOS_SERVICES {'cyclades': {'url':'https://node1.example.com/ui/', 'quota': {'vm': 2}}, Cloud service default url and quota
'pithos+': {'url':'https://node2.example.com/ui/', 'quota': {
'diskspace': 50 * 1024 * 1024 * 1024}}})
AQUARIUM_URL '' The billing (aquarium) URI
ASTAKOS_AQUARIUM_URL '' The billing (aquarium) URI
e.g. ``http://localhost:8888/user``
ASTAKOS_PAGINATE_BY 10 Number of object to be displayed per page
=================================== ============================================================================= ===========================================================================================
Administrator functions
......
......@@ -133,3 +133,5 @@ EMAIL_CHANGE_EMAIL_SUBJECT = getattr(settings, 'ASTAKOS_EMAIL_CHANGE_EMAIL_SUBJE
PASSWORD_RESET_EMAIL_SUBJECT = getattr(settings, 'ASTAKOS_PASSWORD_RESET_EMAIL_SUBJECT',
'Password reset on %s alpha2 testing' % SITENAME)
# Set how many objects should be displayed per page
PAGINATE_BY = getattr(settings, 'ASTAKOS_PAGINATE_BY', 10)
......@@ -39,12 +39,101 @@
</ul>
{% endif %}
{% with object_list|enabled:is_search as object_list %}
{% with page_obj.object_list|enabled:is_search as object_list %}
{% if object_list %}
{% with object_list|split:user as d %}
{% with d|lookup:'own' as mine %}
{% if mine %}
<div class="full-dotted">
<div class="full-dotted">
<table class="alt-style complex">
<caption>
{% if is_search %}
SEARCH RESULTS
{% else %}
I PARTICIPATE IN
{% endif %}
</caption>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Issued</th>
<th>Expires</th>
<th>Enrolled</th>
<th>Enrollment status</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for o in object_list %}
<tr class="{% cycle 'tr1' 'tr2' %}">
<td><a href="{% url group_detail o.id %}" title="visit group page">{{o.name|cut:"http://"|cut:"/" }}</a></td>
<td>{{o.kind|capfirst}}</td>
<td>{{o.issue_date|date:"d/m/Y"}}</td>
<td>{{o.expiration_date|date:"d/m/Y"}}</td>
<td>{{ o.approved_members|length }}</td>
<td>
{% if user in o.approved_members %}
Registered
<form action="{% url group_leave o.id %}" method="post" class="link-like">{% csrf_token %}
<input type="submit" value="LEAVE GROUP" />
</form>
{% else %}
{% if user in o.members %}
Pending
{% else %}
Not member
<form action="{% url group_join o.id %}" method="post" class="link-like">{% csrf_token %}
<input type="submit" value="JOIN GROUP" />
</form>
{% endif %}
{% endif %}
</td>
<td><a href="#" class="more-info" title="more info">&nbsp;</a></td>
</tr>
<tr class="{% cycle 'tmore1' 'tmore2' %}" style="display:none">
<td colspan="8" class="info-td">
<div>
<p>{{o.desc}}</p>
<p>{% if o.homepage%}
Visit it group's home page: <a href="{{ o.homepage }}">{{ o.homepage }}</a>
{% else %}
There is no homepage for this group yet.
{% endif %}
</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}{% if q %}&q={{q}}{% endif %}">previous</a>
{% endif %}
<span class="current">
Page {{ page_obj.number }} of {{ paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}{% if q %}&q={{q}}{% endif %}">next</a>
{% endif %}
</span>
</div>
{% else %}
{% if mine %}
<div class="full-dotted">
<table class="alt-style complex" id="">
<caption>MY GROUPS</caption>
<thead>
......@@ -61,7 +150,7 @@
</tr>
</thead>
<tbody>
{% for o in mine %}
{% for o in mine.object_list %}
<tr class="{% cycle 'tr1' 'tr2' %}">
<td><a href="{% url group_detail o.id %}" title="visit group page">{{o.name|cut:"http://"|cut:"/" }}</a></td>
<td>{{o.kind|capfirst}}</td>
......@@ -77,7 +166,7 @@
<div>
<p>{{o.desc}}</p>
<p>{% if o.homepage%}
Vistit group's home page: <a href="{{ o.homepage }}">{{ o.homepage }}</a>
Visit it group's home page: <a href="{{ o.homepage }}">{{ o.homepage }}</a>
{% else %}
There is no homepage for this group yet.
{% endif %}
......@@ -88,13 +177,25 @@
{% endfor %}
</tbody>
</table>
</div>
<div class="pagination">
<span class="step-links">
{% if mine.has_previous %}
<a href="?own_page={{ mine.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ mine.number }} of {{ mine.paginator.num_pages }}.
</span>
{% if mine.has_next %}
<a href="?own_page={{ mine.next_page_number }}">next</a>
{% endif %}
</span>
</div>
{% endif %}
{% endwith %}
{% with d|lookup:'other' as other %}
{% if other %}
<div class="full-dotted">
<div class="full-dotted">
<table class="alt-style complex">
<caption>
{% if is_search %}
......@@ -119,7 +220,7 @@
</tr>
</thead>
<tbody>
{% for o in other %}
{% for o in other.object_list %}
<tr class="{% cycle 'tr1' 'tr2' %}">
<td><a href="{% url group_detail o.id %}" title="visit group page">{{o.name|cut:"http://"|cut:"/" }}</a></td>
<td>{{o.kind|capfirst}}</td>
......@@ -156,7 +257,7 @@
<div>
<p>{{o.desc}}</p>
<p>{% if o.homepage%}
Vistit group's home page: <a href="{{ o.homepage }}">{{ o.homepage }}</a>
Visit it group's home page: <a href="{{ o.homepage }}">{{ o.homepage }}</a>
{% else %}
There is no homepage for this group yet.
{% endif %}
......@@ -169,11 +270,23 @@
</table>
</div>
<div class="pagination">
<span class="step-links">
{% if other.has_previous %}
<a href="?other_page={{ other.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ other.number }} of {{ other.paginator.num_pages }}.
</span>
{% if other.has_next %}
<a href="?other_page={{ other.next_page_number }}">next</a>
{% endif %}
</span>
</div>
{% endif %}
{% endwith %}
{% endwith %}
{% else %}
{% if is_search %}
{% if q %}
<h2>No groups found!</h2>
{% endif %}
{% endif %}
......
......@@ -31,10 +31,13 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django import template
import calendar
import datetime
from django import template
from astakos.im.settings import PAGINATE_BY
register = template.Library()
@register.filter
......@@ -79,17 +82,6 @@ def enabled(object_list, is_search):
return [g for g in object_list if g.is_enabled]
@register.filter
def split(object_list, user):
try:
d = {}
d['own'] = [g for g in object_list if user in g.owner.all()]
d['other'] = list(set(object_list) - set(d['own']))
return d
except:
return {'own': object_list, 'other': ()}
@register.filter
def month_name(month_number):
return calendar.month_name[month_number]
......@@ -98,4 +90,4 @@ def month_name(month_number):
@register.filter
def todate(value, arg = ''):
secs = int(value) / 1000
return datetime.datetime.fromtimestamp(secs)
return datetime.datetime.fromtimestamp(secs)
\ No newline at end of file
......@@ -56,6 +56,7 @@ from django.views.generic.create_update import (create_object, delete_object,
get_model_and_form_class)
from django.views.generic.list_detail import object_list, object_detail
from django.http import HttpResponseBadRequest
from django.core.paginator import Paginator, InvalidPage
from astakos.im.models import (
AstakosUser, ApprovalTerms, AstakosGroup, Resource,
......@@ -75,8 +76,7 @@ from astakos.im.functions import (send_feedback, SendMailError,
SendNotificationError)
from astakos.im.settings import (
COOKIE_NAME, COOKIE_DOMAIN, SITENAME, LOGOUT_NEXT,
LOGGING_LEVEL
)
LOGGING_LEVEL, PAGINATE_BY)
from astakos.im.tasks import request_billing
logger = logging.getLogger(__name__)
......@@ -716,12 +716,30 @@ def group_add(request, kind_name='default'):
@signed_terms_required
@login_required
def group_list(request):
q = request.user.astakos_groups.none()
list = request.user.astakos_groups.select_related().all()
return object_list(request, queryset=list,
extra_context=dict(
is_search=False
)
)
d = {}
d['own'] = [g for g in list if request.user in g.owner.all()]
d['other'] = list.exclude(id__in=(g.id for g in d['own']))
for k, queryset in d.iteritems():
paginator = Paginator(queryset, PAGINATE_BY)
page = request.GET.get('%s_page' % k, 1)
try:
page_number = int(page)
except ValueError:
if page == 'last':
page_number = paginator.num_pages
else:
# Page is not 'last', nor can it be converted to an int.
raise Http404
try:
page_obj = locals()['%s_page_obj' % k] = paginator.page(page_number)
except InvalidPage:
raise Http404
return object_list(request, queryset=q,
extra_context={'is_search':False,
'mine': locals()['own_page_obj'],
'other': locals()['other_page_obj']})
@signed_terms_required
......@@ -765,35 +783,36 @@ def group_update(request, group_id):
@signed_terms_required
@login_required
def group_search(request, extra_context=None, **kwargs):
q = request.GET.get('q')
if request.method == 'GET':
form = AstakosGroupSearchForm()
form = AstakosGroupSearchForm({'q': q} if q else None)
else:
form = AstakosGroupSearchForm(get_query(request))
if form.is_valid():
q = form.cleaned_data['q'].strip()
queryset = AstakosGroup.objects.select_related(
).filter(name__contains=q)
return object_list(
request,
queryset,
template_name='im/astakosgroup_list.html',
extra_context=dict(form=form,
is_search=True))
return render_response(
template='im/astakosgroup_list.html',
form=form,
context_instance=get_context(request, extra_context),
is_search=False
)
if q:
queryset = AstakosGroup.objects.select_related(
).filter(name__contains=q)
else:
queryset = AstakosGroup.objects.none()
return object_list(
request,
queryset,
paginate_by=PAGINATE_BY,
page=request.GET.get('page') or 1,
template_name='im/astakosgroup_list.html',
extra_context=dict(form=form,
is_search=True,
q=q))
@signed_terms_required
@login_required
def group_all(request, extra_context=None, **kwargs):
if request.method != 'POST':
return HttpResponseBadRequest(_('Bad method'))
return object_list(
request,
AstakosGroup.objects.select_related().all(),
paginate_by=PAGINATE_BY,
page=request.GET.get('page') or 1,
template_name='im/astakosgroup_list.html',
extra_context=dict(form=AstakosGroupSearchForm(),
is_search=True))
......
......@@ -122,4 +122,7 @@
#ASTAKOS_ADMIN_NOTIFICATION_EMAIL_SUBJECT = '%s alpha2 testing account created (%%(user)s)' % SITENAME
#ASTAKOS_HELPDESK_NOTIFICATION_EMAIL_SUBJECT = '%s alpha2 testing account activated (%%(user)s)' % SITENAME
#ASTAKOS_EMAIL_CHANGE_EMAIL_SUBJECT = 'Email change on %s alpha2 testing' % SITENAME
#ASTAKOS_PASSWORD_RESET_EMAIL_SUBJECT = 'Password reset on %s alpha2 testing' % SITENAME
\ No newline at end of file
#ASTAKOS_PASSWORD_RESET_EMAIL_SUBJECT = 'Password reset on %s alpha2 testing' % SITENAME
# Set how many objects should be displayed per page
#PAGINATE_BY = getattr(settings, 'ASTAKOS_PAGINATE_BY', 10)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment