@register.inclusion_tag('rapidsms/templatetags/paginator.html', takes_context=True)
def paginator(context, page, prefix=''):
 dom_id = (prefix + 'paginator')
 page_param = (prefix + 'page')
 request = context['request']
 def _link(page_number):
  return _self_link(request, **{page_param: page_number})
 def _page(number):
  return {'number': number, 'link': _link(number), 'active': (page.number == number)}
 num_border_links = min(settings.PAGINATOR_BORDER_LINKS, page.paginator.num_pages)
 num_adjacent_links = min(settings.PAGINATOR_ADJACENT_LINKS, page.paginator.num_pages)
 last_page_number = (page.paginator.num_pages + 1)
 pages = set([page.number])
 for p in range(1, (num_border_links + 1)):
  pages.add(p)
 for p in range((last_page_number - num_border_links), last_page_number):
  pages.add(p)
 first_adjacent = max(1, (page.number - num_adjacent_links))
 last_adjacent = min(((page.number + num_adjacent_links) + 1), last_page_number)
 for p in range(first_adjacent, last_adjacent):
  pages.add(p)
 page_links = []
 pages = sorted(pages)
 for i in range((len(pages) - 1)):
  page_links.append(_page(pages[i]))
  gap = (pages[(i + 1)] - pages[i])
  if (gap == 2):
   page_links.append(_page((pages[i] + 1)))
  elif (gap > 2):
   page_links.append(None)
 if pages:
  page_links.append(_page(pages[(-1)]))
 subcontext = {'dom_id': dom_id, 'page_links': page_links}
 if (page.number > 1):
  subcontext.update({'prev_page_link': _link(page.previous_page_number())})
 if (page.number < page.paginator.num_pages):
  subcontext.update({'next_page_link': _link(page.next_page_number())})
 return subcontext

@ register . inclusion_tag ( 'rapidsms/templatetags/paginator.html' , takes_context = True ) def paginator ( context , page , prefix = '' ) : dom_id = ( prefix + 'paginator' ) page_param = ( prefix + 'page' ) request = context [ 'request' ] def _link ( page_number ) : return _self_link ( request , ** { page_param : page_number } ) def _page ( number ) : return { 'number' : number , 'link' : _link ( number ) , 'active' : ( page . number == number ) } num_border_links = min ( settings . PAGINATOR_BORDER_LINKS , page . paginator . num_pages ) num_adjacent_links = min ( settings . PAGINATOR_ADJACENT_LINKS , page . paginator . num_pages ) last_page_number = ( page . paginator . num_pages + 1 ) pages = set ( [ page . number ] ) for p in range ( 1 , ( num_border_links + 1 ) ) : pages . add ( p ) for p in range ( ( last_page_number - num_border_links ) , last_page_number ) : pages . add ( p ) first_adjacent = max ( 1 , ( page . number - num_adjacent_links ) ) last_adjacent = min ( ( ( page . number + num_adjacent_links ) + 1 ) , last_page_number ) for p in range ( first_adjacent , last_adjacent ) : pages . add ( p ) page_links = [ ] pages = sorted ( pages ) for i in range ( ( len ( pages ) - 1 ) ) : page_links . append ( _page ( pages [ i ] ) ) gap = ( pages [ ( i + 1 ) ] - pages [ i ] ) if ( gap == 2 ) : page_links . append ( _page ( ( pages [ i ] + 1 ) ) ) elif ( gap > 2 ) : page_links . append ( None ) if pages : page_links . append ( _page ( pages [ ( - 1 ) ] ) ) subcontext = { 'dom_id' : dom_id , 'page_links' : page_links } if ( page . number > 1 ) : subcontext . update ( { 'prev_page_link' : _link ( page . previous_page_number ( ) ) } ) if ( page . number < page . paginator . num_pages ) : subcontext . update ( { 'next_page_link' : _link ( page . next_page_number ( ) ) } ) return subcontext
render list of pages .