diff --git a/src/postorius/templates/postorius/lists/held_messages.html b/src/postorius/templates/postorius/lists/held_messages.html index 924c052..d6450a8 100644 --- a/src/postorius/templates/postorius/lists/held_messages.html +++ b/src/postorius/templates/postorius/lists/held_messages.html @@ -9,7 +9,7 @@ {% block main %} {% list_nav 'list_held_messages' 'Held Messages' %} - {% if list.held|length > 0 %} + {% if held_messages|length > 0 %}
{% if form.choices.errors %} {% for error in form.choices.errors %} @@ -37,7 +37,7 @@ - {% for msg in list.held %} + {% for msg in held_messages %} {{ msg.subject }} @@ -70,6 +70,9 @@
+ + {% include 'postorius/_pagination.html' with page=held_messages %} + {% else %}

{% trans 'There are currently no held messages.' %}

{% endif %} diff --git a/src/postorius/utils.py b/src/postorius/utils.py index b87cd75..37a4011 100644 --- a/src/postorius/utils.py +++ b/src/postorius/utils.py @@ -18,6 +18,7 @@ import logging from django.conf import settings +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.shortcuts import render_to_response, redirect from django.template import RequestContext from mailmanclient import Client @@ -41,3 +42,17 @@ {'error': "Mailman REST API not available. " "Please start Mailman core."}, context_instance=RequestContext(request)) + +def paginate(request, collection, count=20): + # count is the number of items per page + paginator = Paginator(collection, count) + page = request.GET.get('page') + try: + results = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + results = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + results = paginator.page(paginator.num_pages) + return results diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index c8fe250..ec65272 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -30,7 +30,6 @@ from django.core.exceptions import ValidationError from django.utils.decorators import method_decorator from django.utils.translation import gettext as _ -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger try: from urllib2 import HTTPError except ImportError: @@ -395,9 +394,13 @@ @method_decorator(list_moderator_required) def get(self, request, *args, **kwargs): - return render_to_response('postorius/lists/held_messages.html', - {'list': self.mailing_list, 'form':HeldMessagesModerationForm()}, - context_instance=RequestContext(request)) + held_messages = utils.paginate(request, self.mailing_list.held, 20) + return render_to_response( + 'postorius/lists/held_messages.html', { + 'list': self.mailing_list, + 'held_messages': held_messages, + 'form':HeldMessagesModerationForm() + }, context_instance=RequestContext(request)) @method_decorator(list_moderator_required) def post(self, request, *args, **kwargs): @@ -520,24 +523,11 @@ logger.debug(lists) except MailmanApiError: return utils.render_api_error(request) - - # Paginate - paginator = Paginator(lists, 15) # Show 15 lists per page - page = request.GET.get('page') - try: - lists = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - lists = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - lists = paginator.page(paginator.num_pages) - choosable_domains = _get_choosable_domains(request) return render_to_response( template, { 'error': error, - 'lists': lists, + 'lists': utils.paginate(request, lists, 15), 'domain_count': len(choosable_domains), }, context_instance=RequestContext(request))