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
15 return {'number': current - 1, 'title': None, 'url': None,
16 'get_dict': urlencode(get_dict)}
18 return {'number': None, 'title': fallback_title, 'url': fallback}
21 @register.inclusion_tag('fnpdjango/prevnext/next.html', takes_context=True)
22 def next_page(context, fallback=None, fallback_title=None):
23 current = context['page_obj'].number
24 page_range = context['paginator'].page_range
25 if current < page_range[-1]:
26 get_dict = copy(context['request'].GET)
27 get_dict['page'] = current + 1
29 return {'number': current + 1, 'title': None, 'url': None,
30 'get_dict': urlencode(get_dict)}
32 return {'number': None, 'title': fallback_title, 'url': fallback}
35 @register.inclusion_tag('fnpdjango/prevnext/prevnext.html', takes_context=True)
36 def prevnext(context):