1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-21 19:37:28 +00:00

Add pagination in institutions

This commit is contained in:
zhengxie
2016-04-09 11:34:35 +08:00
parent 99f0c340e5
commit 4f1e2b849c
4 changed files with 55 additions and 7 deletions

View File

@@ -10,6 +10,7 @@
</ul> </ul>
</div> </div>
{% if users %}
<table> <table>
<tr> <tr>
<th width="36%">{% trans "Email" %}</th> <th width="36%">{% trans "Email" %}</th>
@@ -52,6 +53,11 @@
{% endfor %} {% endfor %}
</table> </table>
{% include "snippets/admin_paginator.html" %}
{% else %}
<p>{% trans "Empty" %}</p>
{% endif %}
{% endblock %} {% endblock %}
{% block extra_script %} {% block extra_script %}

View File

@@ -48,9 +48,23 @@ def info(request):
def useradmin(request): def useradmin(request):
"""List users in the institution. """List users in the institution.
""" """
# Make sure page request is an int. If not, deliver first page.
try:
current_page = int(request.GET.get('page', '1'))
per_page = int(request.GET.get('per_page', '25'))
except ValueError:
current_page = 1
per_page = 25
offset = per_page * (current_page - 1)
inst = request.user.institution inst = request.user.institution
usernames = [x.user for x in Profile.objects.filter(institution=inst.name)] usernames = [x.user for x in Profile.objects.filter(institution=inst.name)[offset:offset + per_page + 1]]
users = [User.objects.get(x) for x in usernames] if len(usernames) == per_page + 1:
page_next = True
else:
page_next = False
users = [User.objects.get(x) for x in usernames[:per_page]]
last_logins = UserLastLogin.objects.filter(username__in=[x.username for x in users]) last_logins = UserLastLogin.objects.filter(username__in=[x.username for x in users])
for u in users: for u in users:
if u.username == request.user.username: if u.username == request.user.username:
@@ -65,6 +79,11 @@ def useradmin(request):
return render_to_response('institutions/useradmin.html', { return render_to_response('institutions/useradmin.html', {
'inst': inst, 'inst': inst,
'users': users, 'users': users,
'current_page': current_page,
'prev_page': current_page - 1,
'next_page': current_page + 1,
'per_page': per_page,
'page_next': page_next,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@inst_admin_required @inst_admin_required

View File

@@ -8,6 +8,7 @@
</ul> </ul>
</div> </div>
{% if users %}
<table> <table>
<tr> <tr>
<th width="25%">{% trans "Email" %}</th> <th width="25%">{% trans "Email" %}</th>
@@ -41,6 +42,10 @@
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
{% include "snippets/admin_paginator.html" %}
{% else %}
<p>{% trans "Empty" %}</p>
{% endif %}
<div id="activate-msg" class="hide"> <div id="activate-msg" class="hide">
<p>{% trans "Activating..., please wait" %}</p> <p>{% trans "Activating..., please wait" %}</p>

View File

@@ -2272,8 +2272,7 @@ def sys_inst_admin(request):
per_page = 100 per_page = 100
offset = per_page * (current_page - 1) offset = per_page * (current_page - 1)
limit = per_page + 1 insts = Institution.objects.all()[offset:offset + per_page + 1]
insts = Institution.objects.all()[offset:offset + limit]
if len(insts) == per_page + 1: if len(insts) == per_page + 1:
page_next = True page_next = True
@@ -2282,7 +2281,7 @@ def sys_inst_admin(request):
return render_to_response( return render_to_response(
'sysadmin/sys_inst_admin.html', { 'sysadmin/sys_inst_admin.html', {
'insts': insts, 'insts': insts[:per_page],
'current_page': current_page, 'current_page': current_page,
'prev_page': current_page - 1, 'prev_page': current_page - 1,
'next_page': current_page + 1, 'next_page': current_page + 1,
@@ -2316,9 +2315,23 @@ def sys_inst_info_user(request, inst_id):
except Institution.DoesNotExist: except Institution.DoesNotExist:
raise Http404 raise Http404
# Make sure page request is an int. If not, deliver first page.
try:
current_page = int(request.GET.get('page', '1'))
per_page = int(request.GET.get('per_page', '25'))
except ValueError:
current_page = 1
per_page = 25
offset = per_page * (current_page - 1)
inst_admins = [x.user for x in InstitutionAdmin.objects.filter(institution=inst)] inst_admins = [x.user for x in InstitutionAdmin.objects.filter(institution=inst)]
usernames = [x.user for x in Profile.objects.filter(institution=inst.name)] usernames = [x.user for x in Profile.objects.filter(institution=inst.name)[offset:offset + per_page + 1]]
users = [User.objects.get(x) for x in usernames] if len(usernames) == per_page + 1:
page_next = True
else:
page_next = False
users = [User.objects.get(x) for x in usernames[:per_page]]
last_logins = UserLastLogin.objects.filter(username__in=[x.email for x in users]) last_logins = UserLastLogin.objects.filter(username__in=[x.email for x in users])
for u in users: for u in users:
_populate_user_quota_usage(u) _populate_user_quota_usage(u)
@@ -2340,6 +2353,11 @@ def sys_inst_info_user(request, inst_id):
'inst': inst, 'inst': inst,
'users': users, 'users': users,
'users_count': users_count, 'users_count': users_count,
'current_page': current_page,
'prev_page': current_page - 1,
'next_page': current_page + 1,
'per_page': per_page,
'page_next': page_next,
}, context_instance=RequestContext(request)) }, context_instance=RequestContext(request))
@login_required @login_required