<s> from collections import OrderedDict <EOL> from django . core . exceptions import PermissionDenied , ObjectDoesNotExist <EOL> from django . core . paginator import InvalidPage , Paginator <EOL> from django . db import models <EOL> from django . http import HttpResponseRedirect <EOL> from django . template . response import SimpleTemplateResponse , TemplateResponse <EOL> from django . utils . encoding import force_unicode , smart_unicode <EOL> from django . utils . html import escape , conditional_escape <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . text import capfirst <EOL> from django . utils . translation import ugettext as _ <EOL> from xadmin . util import lookup_field , display_for_field , label_for_field , boolean_icon <EOL> from base import ModelAdminView , filter_hook , inclusion_tag , csrf_protect_m <EOL> ALL_VAR = '<STR_LIT:all>' <EOL> ORDER_VAR = '<STR_LIT:o>' <EOL> PAGE_VAR = '<STR_LIT:p>' <EOL> TO_FIELD_VAR = '<STR_LIT:t>' <EOL> COL_LIST_VAR = '<STR_LIT>' <EOL> ERROR_FLAG = '<STR_LIT:e>' <EOL> DOT = '<STR_LIT:.>' <EOL> EMPTY_CHANGELIST_VALUE = _ ( '<STR_LIT>' ) <EOL> class FakeMethodField ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , verbose_name ) : <EOL> self . name = name <EOL> self . verbose_name = verbose_name <EOL> self . primary_key = False <EOL> class ResultRow ( dict ) : <EOL> pass <EOL> class ResultItem ( object ) : <EOL> def __init__ ( self , field_name , row ) : <EOL> self . classes = [ ] <EOL> self . text = '<STR_LIT>' <EOL> self . wraps = [ ] <EOL> self . tag = '<STR_LIT>' <EOL> self . tag_attrs = [ ] <EOL> self . allow_tags = False <EOL> self . btns = [ ] <EOL> self . menus = [ ] <EOL> self . is_display_link = False <EOL> self . row = row <EOL> self . field_name = field_name <EOL> self . field = None <EOL> self . attr = None <EOL> self . value = None <EOL> @ property <EOL> def label ( self ) : <EOL> text = mark_safe ( <EOL> self . text ) if self . allow_tags else conditional_escape ( self . text ) <EOL> if force_unicode ( text ) == '<STR_LIT>' : <EOL> text = mark_safe ( '<STR_LIT>' ) <EOL> for wrap in self . wraps : <EOL> text = mark_safe ( wrap % text ) <EOL> return text <EOL> @ property <EOL> def tagattrs ( self ) : <EOL> return mark_safe ( <EOL> '<STR_LIT>' % ( ( self . tag_attrs and '<STR_LIT:U+0020>' . join ( self . tag_attrs ) or '<STR_LIT>' ) , <EOL> ( self . classes and ( '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( self . classes ) ) or '<STR_LIT>' ) ) ) <EOL> class ResultHeader ( ResultItem ) : <EOL> def __init__ ( self , field_name , row ) : <EOL> super ( ResultHeader , self ) . __init__ ( field_name , row ) <EOL> self . tag = '<STR_LIT>' <EOL> self . tag_attrs = [ '<STR_LIT>' ] <EOL> self . sortable = False <EOL> self . allow_tags = True <EOL> self . sorted = False <EOL> self . ascending = None <EOL> self . sort_priority = None <EOL> self . url_primary = None <EOL> self . url_remove = None <EOL> self . url_toggle = None <EOL> class ListAdminView ( ModelAdminView ) : <EOL> """<STR_LIT>""" <EOL> list_display = ( '<STR_LIT>' , ) <EOL> list_display_links = ( ) <EOL> list_display_links_details = False <EOL> list_select_related = None <EOL> list_per_page = <NUM_LIT:50> <EOL> list_max_show_all = <NUM_LIT:200> <EOL> list_exclude = ( ) <EOL> search_fields = ( ) <EOL> paginator_class = Paginator <EOL> ordering = None <EOL> object_list_template = None <EOL> def init_request ( self , * args , ** kwargs ) : <EOL> if not self . has_view_permission ( ) : <EOL> raise PermissionDenied <EOL> request = self . request <EOL> request . session [ '<STR_LIT>' ] = ( self . model_info , self . request . META [ '<STR_LIT>' ] ) <EOL> self . pk_attname = self . opts . pk . attname <EOL> self . lookup_opts = self . opts <EOL> self . list_display = self . get_list_display ( ) <EOL> self . list_display_links = self . get_list_display_links ( ) <EOL> try : <EOL> self . page_num = int ( request . GET . get ( PAGE_VAR , <NUM_LIT:0> ) ) <EOL> except ValueError : <EOL> self . page_num = <NUM_LIT:0> <EOL> self . show_all = ALL_VAR in request . GET <EOL> self . to_field = request . GET . get ( TO_FIELD_VAR ) <EOL> self . params = dict ( request . GET . items ( ) ) <EOL> if PAGE_VAR in self . params : <EOL> del self . params [ PAGE_VAR ] <EOL> if ERROR_FLAG in self . params : <EOL> del self . params [ ERROR_FLAG ] <EOL> @ filter_hook <EOL> def get_list_display ( self ) : <EOL> """<STR_LIT>""" <EOL> self . base_list_display = ( COL_LIST_VAR in self . request . GET and self . request . GET [ COL_LIST_VAR ] != "<STR_LIT>" and self . request . GET [ COL_LIST_VAR ] . split ( '<STR_LIT:.>' ) ) or self . list_display <EOL> return list ( self . base_list_display ) <EOL> @ filter_hook <EOL> def get_list_display_links ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . list_display_links or not self . list_display : <EOL> return self . list_display_links <EOL> else : <EOL> return list ( self . list_display ) [ : <NUM_LIT:1> ] <EOL> def make_result_list ( self ) : <EOL> self . base_queryset = self . queryset ( ) <EOL> self . list_queryset = self . get_list_queryset ( ) <EOL> self . ordering_field_columns = self . get_ordering_field_columns ( ) <EOL> self . paginator = self . get_paginator ( ) <EOL> self . result_count = self . paginator . count <EOL> if not self . list_queryset . query . where : <EOL> self . full_result_count = self . result_count <EOL> else : <EOL> self . full_result_count = self . base_queryset . count ( ) <EOL> self . can_show_all = self . result_count <= self . list_max_show_all <EOL> self . multi_page = self . result_count > self . list_per_page <EOL> if ( self . show_all and self . can_show_all ) or not self . multi_page : <EOL> self . result_list = self . list_queryset . _clone ( ) <EOL> else : <EOL> try : <EOL> self . result_list = self . paginator . page ( <EOL> self . page_num + <NUM_LIT:1> ) . object_list <EOL> except InvalidPage : <EOL> if ERROR_FLAG in self . request . GET . keys ( ) : <EOL> return SimpleTemplateResponse ( '<STR_LIT>' , { <EOL> '<STR_LIT:title>' : _ ( '<STR_LIT>' ) , <EOL> } ) <EOL> return HttpResponseRedirect ( self . request . path + '<STR_LIT:?>' + ERROR_FLAG + '<STR_LIT>' ) <EOL> self . has_more = self . result_count > ( <EOL> self . list_per_page * self . page_num + len ( self . result_list ) ) <EOL> @ filter_hook <EOL> def get_result_list ( self ) : <EOL> return self . make_result_list ( ) <EOL> @ filter_hook <EOL> def post_result_list ( self ) : <EOL> return self . make_result_list ( ) <EOL> @ filter_hook <EOL> def get_list_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . queryset ( ) <EOL> if not queryset . query . select_related : <EOL> if self . list_select_related : <EOL> queryset = queryset . select_related ( ) <EOL> elif self . list_select_related is None : <EOL> related_fields = [ ] <EOL> for field_name in self . list_display : <EOL> try : <EOL> field = self . opts . get_field ( field_name ) <EOL> except models . FieldDoesNotExist : <EOL> pass <EOL> else : <EOL> if isinstance ( field . rel , models . ManyToOneRel ) : <EOL> related_fields . append ( field_name ) <EOL> if related_fields : <EOL> queryset = queryset . select_related ( * related_fields ) <EOL> else : <EOL> pass <EOL> queryset = queryset . order_by ( * self . get_ordering ( ) ) <EOL> return queryset <EOL> def _get_default_ordering ( self ) : <EOL> ordering = [ ] <EOL> if self . ordering : <EOL> ordering = self . ordering <EOL> elif self . opts . ordering : <EOL> ordering = self . opts . ordering <EOL> return ordering <EOL> @ filter_hook <EOL> def get_ordering_field ( self , field_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> field = self . opts . get_field ( field_name ) <EOL> return field . name <EOL> except models . FieldDoesNotExist : <EOL> if callable ( field_name ) : <EOL> attr = field_name <EOL> elif hasattr ( self , field_name ) : <EOL> attr = getattr ( self , field_name ) <EOL> else : <EOL> attr = getattr ( self . model , field_name ) <EOL> return getattr ( attr , '<STR_LIT>' , None ) <EOL> @ filter_hook <EOL> def get_ordering ( self ) : <EOL> """<STR_LIT>""" <EOL> ordering = list ( super ( ListAdminView , self ) . get_ordering ( ) <EOL> or self . _get_default_ordering ( ) ) <EOL> if ORDER_VAR in self . params and self . params [ ORDER_VAR ] : <EOL> ordering = [ pfx + self . get_ordering_field ( field_name ) for n , pfx , field_name in <EOL> map ( <EOL> lambda p : p . rpartition ( '<STR_LIT:->' ) , <EOL> self . params [ ORDER_VAR ] . split ( '<STR_LIT:.>' ) ) <EOL> if self . get_ordering_field ( field_name ) ] <EOL> pk_name = self . opts . pk . name <EOL> if not ( set ( ordering ) & set ( [ '<STR_LIT>' , '<STR_LIT>' , pk_name , '<STR_LIT:->' + pk_name ] ) ) : <EOL> ordering . append ( '<STR_LIT>' ) <EOL> return ordering <EOL> @ filter_hook <EOL> def get_ordering_field_columns ( self ) : <EOL> """<STR_LIT>""" <EOL> ordering = self . _get_default_ordering ( ) <EOL> ordering_fields = OrderedDict ( ) <EOL> if ORDER_VAR not in self . params or not self . params [ ORDER_VAR ] : <EOL> for field in ordering : <EOL> if field . startswith ( '<STR_LIT:->' ) : <EOL> field = field [ <NUM_LIT:1> : ] <EOL> order_type = '<STR_LIT>' <EOL> else : <EOL> order_type = '<STR_LIT>' <EOL> for attr in self . list_display : <EOL> if self . get_ordering_field ( attr ) == field : <EOL> ordering_fields [ field ] = order_type <EOL> break <EOL> else : <EOL> for p in self . params [ ORDER_VAR ] . split ( '<STR_LIT:.>' ) : <EOL> none , pfx , field_name = p . rpartition ( '<STR_LIT:->' ) <EOL> ordering_fields [ field_name ] = '<STR_LIT>' if pfx == '<STR_LIT:->' else '<STR_LIT>' <EOL> return ordering_fields <EOL> def get_check_field_url ( self , f ) : <EOL> """<STR_LIT>""" <EOL> fields = [ fd for fd in self . base_list_display if fd != f . name ] <EOL> if len ( self . base_list_display ) == len ( fields ) : <EOL> if f . primary_key : <EOL> fields . insert ( <NUM_LIT:0> , f . name ) <EOL> else : <EOL> fields . append ( f . name ) <EOL> return self . get_query_string ( { COL_LIST_VAR : '<STR_LIT:.>' . join ( fields ) } ) <EOL> def get_model_method_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> methods = [ ] <EOL> for name in dir ( self ) : <EOL> try : <EOL> if getattr ( getattr ( self , name ) , '<STR_LIT>' , False ) : <EOL> methods . append ( ( name , getattr ( self , name ) ) ) <EOL> except : <EOL> pass <EOL> return [ FakeMethodField ( name , getattr ( method , '<STR_LIT>' , capfirst ( name . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) ) ) ) <EOL> for name , method in methods ] <EOL> @ filter_hook <EOL> def get_context ( self ) : <EOL> """<STR_LIT>""" <EOL> self . title = _ ( '<STR_LIT>' ) % force_unicode ( self . opts . verbose_name ) <EOL> model_fields = [ ( f , f . name in self . list_display , self . get_check_field_url ( f ) ) <EOL> for f in ( list ( self . opts . fields ) + self . get_model_method_fields ( ) ) if f . name not in self . list_exclude ] <EOL> new_context = { <EOL> '<STR_LIT>' : force_unicode ( self . opts . verbose_name_plural ) , <EOL> '<STR_LIT:title>' : self . title , <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : model_fields , <EOL> '<STR_LIT>' : self . get_query_string ( remove = [ COL_LIST_VAR ] ) , <EOL> '<STR_LIT>' : self . has_add_permission ( ) , <EOL> '<STR_LIT>' : self . app_label , <EOL> '<STR_LIT>' : self . opts . verbose_name_plural , <EOL> '<STR_LIT>' : self . get_model_icon ( self . model ) , <EOL> '<STR_LIT>' : self . model_admin_url ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . result_headers ( ) , <EOL> '<STR_LIT>' : self . results ( ) <EOL> } <EOL> context = super ( ListAdminView , self ) . get_context ( ) <EOL> context . update ( new_context ) <EOL> return context <EOL> @ filter_hook <EOL> def get_response ( self , context , * args , ** kwargs ) : <EOL> pass <EOL> @ csrf_protect_m <EOL> @ filter_hook <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> response = self . get_result_list ( ) <EOL> if response : <EOL> return response <EOL> context = self . get_context ( ) <EOL> context . update ( kwargs or { } ) <EOL> response = self . get_response ( context , * args , ** kwargs ) <EOL> return response or TemplateResponse ( request , self . object_list_template or <EOL> self . get_template_list ( '<STR_LIT>' ) , context ) <EOL> @ filter_hook <EOL> def post_response ( self , * args , ** kwargs ) : <EOL> pass <EOL> @ csrf_protect_m <EOL> @ filter_hook <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> return self . post_result_list ( ) or self . post_response ( * args , ** kwargs ) or self . get ( request , * args , ** kwargs ) <EOL> @ filter_hook <EOL> def get_paginator ( self ) : <EOL> return self . paginator_class ( self . list_queryset , self . list_per_page , <NUM_LIT:0> , True ) <EOL> @ filter_hook <EOL> def get_page_number ( self , i ) : <EOL> if i == DOT : <EOL> return mark_safe ( u'<STR_LIT>' ) <EOL> elif i == self . page_num : <EOL> return mark_safe ( u'<STR_LIT>' % ( i + <NUM_LIT:1> ) ) <EOL> else : <EOL> return mark_safe ( u'<STR_LIT>' % ( escape ( self . get_query_string ( { PAGE_VAR : i } ) ) , ( i == self . paginator . num_pages - <NUM_LIT:1> and '<STR_LIT>' or '<STR_LIT>' ) , i + <NUM_LIT:1> ) ) <EOL> @ filter_hook <EOL> def result_header ( self , field_name , row ) : <EOL> ordering_field_columns = self . ordering_field_columns <EOL> item = ResultHeader ( field_name , row ) <EOL> text , attr = label_for_field ( field_name , self . model , <EOL> model_admin = self , <EOL> return_attr = True <EOL> ) <EOL> item . text = text <EOL> item . attr = attr <EOL> if attr and not getattr ( attr , "<STR_LIT>" , None ) : <EOL> return item <EOL> th_classes = [ '<STR_LIT>' ] <EOL> order_type = '<STR_LIT>' <EOL> new_order_type = '<STR_LIT>' <EOL> sort_priority = <NUM_LIT:0> <EOL> sorted = False <EOL> if field_name in ordering_field_columns : <EOL> sorted = True <EOL> order_type = ordering_field_columns . get ( field_name ) . lower ( ) <EOL> sort_priority = ordering_field_columns . keys ( ) . index ( field_name ) + <NUM_LIT:1> <EOL> th_classes . append ( '<STR_LIT>' % order_type ) <EOL> new_order_type = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } [ order_type ] <EOL> o_list_asc = [ ] <EOL> o_list_desc = [ ] <EOL> o_list_remove = [ ] <EOL> o_list_toggle = [ ] <EOL> make_qs_param = lambda t , n : ( '<STR_LIT:->' if t == '<STR_LIT>' else '<STR_LIT>' ) + str ( n ) <EOL> for j , ot in ordering_field_columns . items ( ) : <EOL> if j == field_name : <EOL> param = make_qs_param ( new_order_type , j ) <EOL> o_list_asc . insert ( <NUM_LIT:0> , j ) <EOL> o_list_desc . insert ( <NUM_LIT:0> , '<STR_LIT:->' + j ) <EOL> o_list_toggle . append ( param ) <EOL> else : <EOL> param = make_qs_param ( ot , j ) <EOL> o_list_asc . append ( param ) <EOL> o_list_desc . append ( param ) <EOL> o_list_toggle . append ( param ) <EOL> o_list_remove . append ( param ) <EOL> if field_name not in ordering_field_columns : <EOL> o_list_asc . insert ( <NUM_LIT:0> , field_name ) <EOL> o_list_desc . insert ( <NUM_LIT:0> , '<STR_LIT:->' + field_name ) <EOL> item . sorted = sorted <EOL> item . sortable = True <EOL> item . ascending = ( order_type == "<STR_LIT>" ) <EOL> item . sort_priority = sort_priority <EOL> menus = [ <EOL> ( '<STR_LIT>' , o_list_asc , '<STR_LIT>' , _ ( u'<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , o_list_desc , '<STR_LIT>' , _ ( u'<STR_LIT>' ) ) , <EOL> ] <EOL> if sorted : <EOL> row [ '<STR_LIT>' ] = row [ '<STR_LIT>' ] + <NUM_LIT:1> <EOL> menus . append ( ( None , o_list_remove , '<STR_LIT>' , _ ( u'<STR_LIT>' ) ) ) <EOL> item . btns . append ( '<STR_LIT>' % ( <EOL> self . get_query_string ( { ORDER_VAR : '<STR_LIT:.>' . join ( o_list_toggle ) } ) , '<STR_LIT>' if order_type == "<STR_LIT>" else '<STR_LIT>' ) ) <EOL> item . menus . extend ( [ '<STR_LIT>' % <EOL> ( <EOL> ( '<STR_LIT>' if sorted and order_type == i [ <EOL> <NUM_LIT:0> ] else '<STR_LIT>' ) , <EOL> self . get_query_string ( { ORDER_VAR : '<STR_LIT:.>' . join ( i [ <NUM_LIT:1> ] ) } ) , i [ <NUM_LIT:2> ] , i [ <NUM_LIT:3> ] ) for i in menus ] ) <EOL> item . classes . extend ( th_classes ) <EOL> return item <EOL> @ filter_hook <EOL> def result_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> row = ResultRow ( ) <EOL> row [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> row . cells = [ self . result_header ( <EOL> field_name , row ) for field_name in self . list_display ] <EOL> return row <EOL> @ filter_hook <EOL> def result_item ( self , obj , field_name , row ) : <EOL> """<STR_LIT>""" <EOL> item = ResultItem ( field_name , row ) <EOL> try : <EOL> f , attr , value = lookup_field ( field_name , obj , self ) <EOL> except ( AttributeError , ObjectDoesNotExist ) : <EOL> item . text = mark_safe ( "<STR_LIT>" % EMPTY_CHANGELIST_VALUE ) <EOL> else : <EOL> if f is None : <EOL> item . allow_tags = getattr ( attr , '<STR_LIT>' , False ) <EOL> boolean = getattr ( attr , '<STR_LIT>' , False ) <EOL> if boolean : <EOL> item . allow_tags = True <EOL> item . text = boolean_icon ( value ) <EOL> else : <EOL> item . text = smart_unicode ( value ) <EOL> else : <EOL> if isinstance ( f . rel , models . ManyToOneRel ) : <EOL> field_val = getattr ( obj , f . name ) <EOL> if field_val is None : <EOL> item . text = mark_safe ( "<STR_LIT>" % EMPTY_CHANGELIST_VALUE ) <EOL> else : <EOL> item . text = field_val <EOL> else : <EOL> item . text = display_for_field ( value , f ) <EOL> if isinstance ( f , models . DateField ) or isinstance ( f , models . TimeField ) or isinstance ( f , models . ForeignKey ) : <EOL> item . classes . append ( '<STR_LIT>' ) <EOL> item . field = f <EOL> item . attr = attr <EOL> item . value = value <EOL> if ( item . row [ '<STR_LIT>' ] and not self . list_display_links ) or field_name in self . list_display_links : <EOL> item . row [ '<STR_LIT>' ] = False <EOL> item . is_display_link = True <EOL> if self . list_display_links_details : <EOL> item_res_uri = self . model_admin_url ( "<STR_LIT>" , getattr ( obj , self . pk_attname ) ) <EOL> if item_res_uri : <EOL> if self . has_change_permission ( obj ) : <EOL> edit_url = self . model_admin_url ( "<STR_LIT>" , getattr ( obj , self . pk_attname ) ) <EOL> else : <EOL> edit_url = "<STR_LIT>" <EOL> item . wraps . append ( '<STR_LIT>' <EOL> % ( item_res_uri , edit_url , _ ( u'<STR_LIT>' ) % str ( obj ) ) ) <EOL> else : <EOL> url = self . url_for_result ( obj ) <EOL> item . wraps . append ( u'<STR_LIT>' % url ) <EOL> return item <EOL> @ filter_hook <EOL> def result_row ( self , obj ) : <EOL> row = ResultRow ( ) <EOL> row [ '<STR_LIT>' ] = True <EOL> row [ '<STR_LIT:object>' ] = obj <EOL> row . cells = [ self . result_item ( <EOL> obj , field_name , row ) for field_name in self . list_display ] <EOL> return row <EOL> @ filter_hook <EOL> def results ( self ) : <EOL> results = [ ] <EOL> for obj in self . result_list : <EOL> results . append ( self . result_row ( obj ) ) <EOL> return results <EOL> @ filter_hook <EOL> def url_for_result ( self , result ) : <EOL> return self . get_object_url ( result ) <EOL> @ filter_hook <EOL> def get_media ( self ) : <EOL> media = super ( ListAdminView , self ) . get_media ( ) + self . vendor ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . list_display_links_details : <EOL> media += self . vendor ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return media <EOL> @ inclusion_tag ( '<STR_LIT>' ) <EOL> def block_pagination ( self , context , nodes , page_type = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> paginator , page_num = self . paginator , self . page_num <EOL> pagination_required = ( <EOL> not self . show_all or not self . can_show_all ) and self . multi_page <EOL> if not pagination_required : <EOL> page_range = [ ] <EOL> else : <EOL> ON_EACH_SIDE = { '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : <NUM_LIT:3> } . get ( page_type , <NUM_LIT:3> ) <EOL> ON_ENDS = <NUM_LIT:2> <EOL> if paginator . num_pages <= <NUM_LIT:10> : <EOL> page_range = range ( paginator . num_pages ) <EOL> else : <EOL> page_range = [ ] <EOL> if page_num > ( ON_EACH_SIDE + ON_ENDS ) : <EOL> page_range . extend ( range ( <NUM_LIT:0> , ON_EACH_SIDE - <NUM_LIT:1> ) ) <EOL> page_range . append ( DOT ) <EOL> page_range . extend ( <EOL> range ( page_num - ON_EACH_SIDE , page_num + <NUM_LIT:1> ) ) <EOL> else : <EOL> page_range . extend ( range ( <NUM_LIT:0> , page_num + <NUM_LIT:1> ) ) <EOL> if page_num < ( paginator . num_pages - ON_EACH_SIDE - ON_ENDS - <NUM_LIT:1> ) : <EOL> page_range . extend ( <EOL> range ( page_num + <NUM_LIT:1> , page_num + ON_EACH_SIDE + <NUM_LIT:1> ) ) <EOL> page_range . append ( DOT ) <EOL> page_range . extend ( range ( <EOL> paginator . num_pages - ON_ENDS , paginator . num_pages ) ) <EOL> else : <EOL> page_range . extend ( range ( page_num + <NUM_LIT:1> , paginator . num_pages ) ) <EOL> need_show_all_link = self . can_show_all and not self . show_all and self . multi_page <EOL> return { <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : pagination_required , <EOL> '<STR_LIT>' : need_show_all_link and self . get_query_string ( { ALL_VAR : '<STR_LIT>' } ) , <EOL> '<STR_LIT>' : map ( self . get_page_number , page_range ) , <EOL> '<STR_LIT>' : ALL_VAR , <EOL> '<STR_LIT:1>' : <NUM_LIT:1> , <EOL> } </s>
