diff options
author | Aamir Khan <syst3m.w0rm@gmail.com> | 2012-08-11 11:35:43 +0530 |
---|---|---|
committer | Aamir Khan <syst3m.w0rm@gmail.com> | 2012-08-11 11:35:43 +0530 |
commit | 8a681b27fb1e2644a1330ed6e5581232ee1eb107 (patch) | |
tree | 961237b5309d10e6fb652481a91c03894c3fdcdb | |
parent | 276b6ec8e34695bb7ddb0a2bf5ea6470b355b499 (diff) | |
download | hyperkitty-8a681b27fb1e2644a1330ed6e5581232ee1eb107.tar.gz hyperkitty-8a681b27fb1e2644a1330ed6e5581232ee1eb107.tar.xz hyperkitty-8a681b27fb1e2644a1330ed6e5581232ee1eb107.zip |
Issue 15: Add pagination next | prev in web interface
-rw-r--r-- | hyperkitty/middleware.py | 31 | ||||
-rw-r--r-- | hyperkitty/templates/month_view.html | 5 | ||||
-rw-r--r-- | hyperkitty/templates/paginator.html | 27 | ||||
-rw-r--r-- | hyperkitty/views/list.py | 9 |
4 files changed, 71 insertions, 1 deletions
diff --git a/hyperkitty/middleware.py b/hyperkitty/middleware.py new file mode 100644 index 0000000..d53dfb8 --- /dev/null +++ b/hyperkitty/middleware.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 1998-2012 by the Free Software Foundation, Inc. +# +# This file is part of HyperKitty. +# +# HyperKitty is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# HyperKitty is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# HyperKitty. If not, see <http://www.gnu.org/licenses/>. +# +# Author: Aamir Khan <syst3m.w0rm@gmail.com> +# + +class PaginationMiddleware(object): + """ + Inserts a variable representing the current page onto the request object if + it exists in either **GET** or **POST** portions of the request. + """ + def process_request(self, request): + try: + request.page = int(request.REQUEST['page']) + except (KeyError, ValueError, TypeError): + request.page = 1 diff --git a/hyperkitty/templates/month_view.html b/hyperkitty/templates/month_view.html index e8b42bc..96c8fc9 100644 --- a/hyperkitty/templates/month_view.html +++ b/hyperkitty/templates/month_view.html @@ -77,9 +77,12 @@ </div> <!-- End of thread --> {% empty %} - Sorry no emails could be found for your search. + Sorry no emails could be found for your search. {% endfor %} + + {% include "paginator.html" %} </div> + <div id="archives"> {% for key, value in archives_length|sort %} <h3>{{ key }}</h3> diff --git a/hyperkitty/templates/paginator.html b/hyperkitty/templates/paginator.html new file mode 100644 index 0000000..170d8b4 --- /dev/null +++ b/hyperkitty/templates/paginator.html @@ -0,0 +1,27 @@ +{% load i18n %} +<div class="pager"> + {% if has_previous %} + <span class="page"> + <a href="?page={{ previous }}">< Prev</a> + </span> + {% endif %} + + {% if show_first %} + <span class="page"><a href="?page=1">1</a></span> + <span class="ellipsis">...</span> + {% endif %} + {% for linkpage in page_numbers %} + {% ifequal linkpage page %} + <span class="current">{{ page }}</span> + {% else %} + <span class="page"><a href="?page={{ linkpage }}">{{ linkpage }}</a></span> + {% endifequal %} + {% endfor %} + {% if show_last %} + <span class="ellipsis">...</span> + <span class="page"><a href="?page=last">{{ pages }}</a></span> + {% endif %} + {% if has_next %} + <span class="page"><a href="?page={{ next }}">Next ></a></span> + {% endif %} +</div> diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py index b68d220..a0856a0 100644 --- a/hyperkitty/views/list.py +++ b/hyperkitty/views/list.py @@ -104,12 +104,21 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None): c = RequestContext(request, { 'list_name' : list_name, + 'objects': threads.object_list, + 'page': pageNo, + 'has_previous': threads.has_previous(), + 'has_next': threads.has_next(), + 'previous': threads.previous_page_number(), + 'next': threads.next_page_number(), + 'is_first': pageNo == 1, + 'is_last': pageNo == paginator.num_pages, 'list_address': mlist_fqdn, 'search_form': search_form, 'month': month_string, 'month_participants': len(participants), 'month_discussions': len(threads), 'threads': threads, + 'pages' : paginator.object_list, 'archives_length': archives_length, }) return HttpResponse(t.render(c)) |