<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import sys <EOL> from flask import request , url_for , Markup <EOL> __version__ = '<STR_LIT>' <EOL> PY2 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> <EOL> _bs_prev_page = '<STR_LIT>' <EOL> PREV_PAGES = dict ( bootstrap = _bs_prev_page , <EOL> bootstrap2 = _bs_prev_page , <EOL> bootstrap3 = _bs_prev_page , <EOL> foundation = '<STR_LIT>' , <EOL> ) <EOL> _bs_next_page = '<STR_LIT>' <EOL> NEXT_PAGES = dict ( bootstrap = _bs_next_page , <EOL> bootstrap2 = _bs_next_page , <EOL> bootstrap3 = _bs_next_page , <EOL> foundation = '<STR_LIT>' , <EOL> ) <EOL> CURRENT_PAGES = dict ( bootstrap = '<STR_LIT>' , <EOL> bootstrap3 = '<STR_LIT>' , <EOL> foundation = '<STR_LIT>' , <EOL> ) <EOL> CURRENT_PAGES . update ( bootstrap2 = CURRENT_PAGES [ '<STR_LIT>' ] ) <EOL> LINK = '<STR_LIT>' <EOL> FA_LINK = '<STR_LIT>' <EOL> GAP_MARKERS = dict ( bootstrap = '<STR_LIT>' , <EOL> foundation = '<STR_LIT>' , <EOL> ) <EOL> GAP_MARKERS . update ( bootstrap2 = GAP_MARKERS [ '<STR_LIT>' ] , <EOL> bootstrap3 = GAP_MARKERS [ '<STR_LIT>' ] , <EOL> ) <EOL> _bs_prev_disabled_page = '<STR_LIT>' <EOL> PREV_DISABLED_PAGES = dict ( bootstrap = _bs_prev_disabled_page , <EOL> bootstrap2 = _bs_prev_disabled_page , <EOL> bootstrap3 = _bs_prev_disabled_page , <EOL> foundation = FA_LINK , <EOL> ) <EOL> _bs_next_disabled_page = '<STR_LIT>' <EOL> NEXT_DISABLED_PAGES = dict ( bootstrap = _bs_next_disabled_page , <EOL> bootstrap2 = _bs_next_disabled_page , <EOL> bootstrap3 = _bs_next_disabled_page , <EOL> foundation = FA_LINK , <EOL> ) <EOL> PREV_LABEL = '<STR_LIT>' <EOL> NEXT_LABEL = '<STR_LIT>' <EOL> RECORD_NAME = '<STR_LIT>' <EOL> DISPLAY_MSG = '''<STR_LIT>''' <EOL> SEARCH_MSG = '''<STR_LIT>''' <EOL> CSS_LINKS = dict ( bootstrap = '<STR_LIT>' , <EOL> bootstrap2 = '<STR_LIT>' , <EOL> bootstrap3 = '<STR_LIT>' , <EOL> foundation = '<STR_LIT>' , <EOL> ) <EOL> CSS_LINKS_END = dict ( bootstrap = '<STR_LIT>' , <EOL> bootstrap2 = '<STR_LIT>' , <EOL> bootstrap3 = '<STR_LIT>' , <EOL> foundation = '<STR_LIT>' , <EOL> ) <EOL> F_ALIGNMENT = '<STR_LIT>' <EOL> class Pagination ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , found = <NUM_LIT:0> , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> self . found = found <EOL> self . page = kwargs . get ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . per_page = kwargs . get ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . inner_window = kwargs . get ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> self . outer_window = kwargs . get ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . prev_label = kwargs . get ( '<STR_LIT>' ) or PREV_LABEL <EOL> self . next_label = kwargs . get ( '<STR_LIT>' ) or NEXT_LABEL <EOL> self . search = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . total = kwargs . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . format_total = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . format_number = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . display_msg = kwargs . get ( '<STR_LIT>' ) or DISPLAY_MSG <EOL> self . search_msg = kwargs . get ( '<STR_LIT>' ) or SEARCH_MSG <EOL> self . record_name = kwargs . get ( '<STR_LIT>' ) or RECORD_NAME <EOL> self . css_framework = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) <EOL> if self . css_framework not in CURRENT_PAGES : <EOL> self . css_framework = '<STR_LIT>' <EOL> self . bs_version = kwargs . get ( '<STR_LIT>' ) or <NUM_LIT:2> <EOL> if self . css_framework . startswith ( '<STR_LIT>' ) : <EOL> if self . bs_version in ( <NUM_LIT:3> , '<STR_LIT:3>' ) : <EOL> self . css_framework = '<STR_LIT>' <EOL> self . link_size = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . link_size : <EOL> if self . css_framework == '<STR_LIT>' : <EOL> self . link_size = '<STR_LIT>' <EOL> else : <EOL> self . link_size = '<STR_LIT>' . format ( self . link_size ) <EOL> self . alignment = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . alignment and self . css_framework . startswith ( '<STR_LIT>' ) : <EOL> self . alignment = '<STR_LIT>' . format ( self . alignment ) <EOL> self . href = kwargs . get ( '<STR_LIT>' , None ) <EOL> self . show_single_page = kwargs . get ( '<STR_LIT>' , False ) <EOL> self . current_page_fmt = CURRENT_PAGES [ self . css_framework ] <EOL> self . link_css_fmt = CSS_LINKS [ self . css_framework ] <EOL> self . gap_marker_fmt = GAP_MARKERS [ self . css_framework ] <EOL> self . prev_disabled_page_fmt = PREV_DISABLED_PAGES [ self . css_framework ] <EOL> self . next_disabled_page_fmt = NEXT_DISABLED_PAGES [ self . css_framework ] <EOL> self . prev_page_fmt = PREV_PAGES [ self . css_framework ] <EOL> self . next_page_fmt = NEXT_PAGES [ self . css_framework ] <EOL> self . css_end_fmt = CSS_LINKS_END [ self . css_framework ] <EOL> def page_href ( self , page ) : <EOL> if self . href : <EOL> page = <NUM_LIT:1> if page is None else page <EOL> url = self . href . format ( page ) <EOL> else : <EOL> url = url_for ( self . endpoint , page = page , ** self . args ) <EOL> return url . decode ( '<STR_LIT:utf8>' ) if PY2 else url <EOL> @ property <EOL> def total_pages ( self ) : <EOL> current_total = self . found if self . search else self . total <EOL> pages = divmod ( current_total , self . per_page ) <EOL> return pages [ <NUM_LIT:0> ] + <NUM_LIT:1> if pages [ <NUM_LIT:1> ] else pages [ <NUM_LIT:0> ] <EOL> @ property <EOL> def has_prev ( self ) : <EOL> return self . page > <NUM_LIT:1> <EOL> @ property <EOL> def has_next ( self ) : <EOL> return self . page < self . total_pages <EOL> @ property <EOL> def endpoint ( self ) : <EOL> return request . endpoint <EOL> @ property <EOL> def args ( self ) : <EOL> if PY2 : <EOL> request_args = request . args . iteritems ( multi = True ) <EOL> view_args = request . view_args . iteritems ( ) <EOL> else : <EOL> request_args = request . args . items ( multi = True ) <EOL> view_args = request . view_args . items ( ) <EOL> args = { } <EOL> for k , value in list ( request_args ) + list ( view_args ) : <EOL> if k == '<STR_LIT>' : <EOL> continue <EOL> if k not in args : <EOL> args [ k ] = value <EOL> elif not isinstance ( args [ k ] , list ) : <EOL> args [ k ] = [ args [ k ] , value ] <EOL> else : <EOL> args [ k ] . append ( value ) <EOL> return args <EOL> @ property <EOL> def prev_page ( self ) : <EOL> if self . has_prev : <EOL> page = self . page - <NUM_LIT:1> if self . page > <NUM_LIT:2> else None <EOL> url = self . page_href ( page ) <EOL> return self . prev_page_fmt . format ( url , self . prev_label ) <EOL> return self . prev_disabled_page_fmt . format ( self . prev_label ) <EOL> @ property <EOL> def next_page ( self ) : <EOL> if self . has_next : <EOL> url = self . page_href ( self . page + <NUM_LIT:1> ) <EOL> return self . next_page_fmt . format ( url , self . next_label ) <EOL> return self . next_disabled_page_fmt . format ( self . next_label ) <EOL> @ property <EOL> def first_page ( self ) : <EOL> if self . has_prev : <EOL> return LINK . format ( self . page_href ( None ) , <NUM_LIT:1> ) <EOL> return self . current_page_fmt . format ( <NUM_LIT:1> ) <EOL> @ property <EOL> def last_page ( self ) : <EOL> if self . has_next : <EOL> url = self . page_href ( self . total_pages ) <EOL> return LINK . format ( url , self . total_pages ) <EOL> return self . current_page_fmt . format ( self . page ) <EOL> @ property <EOL> def pages ( self ) : <EOL> if self . total_pages < self . inner_window * <NUM_LIT:2> - <NUM_LIT:1> : <EOL> return range ( <NUM_LIT:1> , self . total_pages + <NUM_LIT:1> ) <EOL> pages = [ ] <EOL> win_from = self . page - self . inner_window <EOL> win_to = self . page + self . inner_window <EOL> if win_to > self . total_pages : <EOL> win_from -= win_to - self . total_pages <EOL> win_to = self . total_pages <EOL> if win_from < <NUM_LIT:1> : <EOL> win_to = win_to + <NUM_LIT:1> - win_from <EOL> win_from = <NUM_LIT:1> <EOL> if win_to > self . total_pages : <EOL> win_to = self . total_pages <EOL> if win_from > self . inner_window : <EOL> pages . extend ( range ( <NUM_LIT:1> , self . outer_window + <NUM_LIT:1> + <NUM_LIT:1> ) ) <EOL> pages . append ( None ) <EOL> else : <EOL> pages . extend ( range ( <NUM_LIT:1> , win_to + <NUM_LIT:1> ) ) <EOL> if win_to < self . total_pages - self . inner_window + <NUM_LIT:1> : <EOL> if win_from > self . inner_window : <EOL> pages . extend ( range ( win_from , win_to + <NUM_LIT:1> ) ) <EOL> pages . append ( None ) <EOL> pages . extend ( range ( self . total_pages - <NUM_LIT:1> , self . total_pages + <NUM_LIT:1> ) ) <EOL> elif win_from > self . inner_window : <EOL> pages . extend ( range ( win_from , self . total_pages + <NUM_LIT:1> ) ) <EOL> else : <EOL> pages . extend ( range ( win_to + <NUM_LIT:1> , self . total_pages + <NUM_LIT:1> ) ) <EOL> return pages <EOL> def single_page ( self , page ) : <EOL> if page == self . page : <EOL> return self . current_page_fmt . format ( page ) <EOL> if page == <NUM_LIT:1> : <EOL> return self . first_page <EOL> if page == self . total_pages : <EOL> return self . last_page <EOL> return LINK . format ( self . page_href ( page ) , page ) <EOL> def _get_single_page_link ( self ) : <EOL> s = [ self . link_css_fmt . format ( self . link_size , self . alignment ) ] <EOL> s . append ( self . prev_page ) <EOL> s . append ( self . single_page ( <NUM_LIT:1> ) ) <EOL> s . append ( self . next_page ) <EOL> s . append ( self . css_end_fmt ) <EOL> if self . css_framework == '<STR_LIT>' and self . alignment : <EOL> s . insert ( <NUM_LIT:0> , F_ALIGNMENT . format ( self . alignment ) ) <EOL> s . append ( '<STR_LIT>' ) <EOL> return Markup ( '<STR_LIT>' . join ( s ) ) <EOL> @ property <EOL> def links ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . total_pages <= <NUM_LIT:1> : <EOL> if self . show_single_page : <EOL> return self . _get_single_page_link ( ) <EOL> return '<STR_LIT>' <EOL> s = [ self . link_css_fmt . format ( self . link_size , self . alignment ) ] <EOL> s . append ( self . prev_page ) <EOL> for page in self . pages : <EOL> s . append ( self . single_page ( page ) if page else self . gap_marker_fmt ) <EOL> s . append ( self . next_page ) <EOL> s . append ( self . css_end_fmt ) <EOL> if self . css_framework == '<STR_LIT>' and self . alignment : <EOL> s . insert ( <NUM_LIT:0> , F_ALIGNMENT . format ( self . alignment ) ) <EOL> s . append ( '<STR_LIT>' ) <EOL> return Markup ( '<STR_LIT>' . join ( s ) ) <EOL> @ property <EOL> def info ( self ) : <EOL> '''<STR_LIT>''' <EOL> start = <NUM_LIT:1> + ( self . page - <NUM_LIT:1> ) * self . per_page <EOL> end = start + self . per_page - <NUM_LIT:1> <EOL> if end > self . total : <EOL> end = self . total if not self . search else self . found <EOL> if start > self . total : <EOL> start = self . total if not self . search else self . found <EOL> s = [ '<STR_LIT>' ] <EOL> page_msg = self . search_msg if self . search else self . display_msg <EOL> if self . format_total : <EOL> total_text = '<STR_LIT>' . format ( self . total ) <EOL> else : <EOL> total_text = '<STR_LIT>' . format ( self . total ) <EOL> if self . format_number : <EOL> start_text = '<STR_LIT>' . format ( start ) <EOL> end_text = '<STR_LIT>' . format ( end ) <EOL> else : <EOL> start_text = start <EOL> end_text = end <EOL> s . append ( page_msg . format ( found = self . found , <EOL> total = total_text , <EOL> start = start_text , <EOL> end = end_text , <EOL> record_name = self . record_name , <EOL> ) <EOL> ) <EOL> s . append ( '<STR_LIT>' ) <EOL> return Markup ( '<STR_LIT>' . join ( s ) ) </s>
