2 from urllib import urlencode
3 from django.template import Library
8 @register.inclusion_tag('fnpdjango/prevnext/previous.html', takes_context=True)
9 def previous_page(context, fallback=None, fallback_title=None):
10 current = context['page_obj'].number
12 get_dict = copy(context['request'].GET)
13 get_dict['page'] = current - 1
14 return {'number': current - 1, 'title': None, 'url': None,
15 'get_dict': urlencode(get_dict)}
17 return {'number': None, 'title': fallback_title, 'url': fallback}
20 @register.inclusion_tag('fnpdjango/prevnext/next.html', takes_context=True)
21 def next_page(context, fallback=None, fallback_title=None):
22 current = context['page_obj'].number
23 page_range = context['paginator'].page_range
24 if current < page_range[-1]:
25 get_dict = copy(context['request'].GET)
26 get_dict['page'] = current + 1
27 return {'number': current + 1, 'title': None, 'url': None,
28 'get_dict': urlencode(get_dict)}
30 return {'number': None, 'title': fallback_title, 'url': fallback}
33 @register.inclusion_tag('fnpdjango/prevnext/prevnext.html', takes_context=True)
34 def prevnext(context):