Give Pagination.get_page_url() a request instead of path and GET

Makes calling Pagination.get_page_url() much simpler.
This commit is contained in:
Elrond 2011-05-21 16:38:34 +02:00
parent c0bf3c807b
commit 0e84c707cb
2 changed files with 7 additions and 10 deletions

View File

@ -21,15 +21,13 @@
<div class=pagination> <div class=pagination>
{% if pagination.has_prev %} {% if pagination.has_prev %}
<a href={{ pagination.get_page_url(request.path_info, <a href={{ pagination.get_page_url(request, pagination.page-1) }}>&laquo; Prev</>
pagination.page-1, request.GET) }}>&laquo; Prev</>
{% endif %} {% endif %}
{%- for page in pagination.iter_pages() %} {%- for page in pagination.iter_pages() %}
{% if page %} {% if page %}
{% if page != pagination.page %} {% if page != pagination.page %}
<a href={{ pagination.get_page_url(request.path_info, <a href={{ pagination.get_page_url(request, page) }}>{{ page }}</a>
page, request.GET) }}>{{ page }}</a>
{% else %} {% else %}
<strong>{{ page }}</strong> <strong>{{ page }}</strong>
{% endif %} {% endif %}
@ -39,8 +37,7 @@
{%- endfor %} {%- endfor %}
{% if pagination.has_next %} {% if pagination.has_next %}
<a href={{ pagination.get_page_url(request.path_info, <a href={{ pagination.get_page_url(request, pagination.page+1) }}>Next &raquo;</a>
pagination.page+1, request.GET) }}>Next &raquo;</a>
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}

View File

@ -29,8 +29,6 @@ from mediagoblin import globals as mgoblin_globals
import urllib import urllib
from math import ceil from math import ceil
import copy import copy
import decorators
from webob import exc
TESTS_ENABLED = False TESTS_ENABLED = False
def _activate_testing(): def _activate_testing():
@ -353,11 +351,13 @@ class Pagination(object):
yield num yield num
last = num last = num
def get_page_url(self, path_info, page_no, get_params=None): def get_page_url(self, request, page_no):
""" """
Get a new page based of the path_info, the new page number, Get a new page based of the request, the new page number,
and existing get parameters. and existing get parameters.
""" """
path_info = request.path_info
get_params = request.GET
new_get_params = copy.copy(get_params or {}) new_get_params = copy.copy(get_params or {})
new_get_params['page'] = page_no new_get_params['page'] = page_no
return "%s?%s" % ( return "%s?%s" % (