<s> from django import template <EOL> from django . conf import settings <EOL> import datetime <EOL> import pytz <EOL> register = template . Library ( ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def dateToDatetimeWithoutYear ( value ) : <EOL> """<STR_LIT>""" <EOL> result = dateToDatetime ( value ) <EOL> if not result : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return result . strftime ( '<STR_LIT>' ) [ : - <NUM_LIT:3> ] <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def dateToDatetimeWithYear ( value ) : <EOL> """<STR_LIT>""" <EOL> result = dateToDatetime ( value ) <EOL> if not result : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return result . strftime ( '<STR_LIT>' ) [ : - <NUM_LIT:3> ] <EOL> def dateToDatetime ( value ) : <EOL> """<STR_LIT>""" <EOL> if not value : <EOL> return "<STR_LIT>" <EOL> date = datetime . datetime . utcfromtimestamp ( float ( str ( value ) ) / <NUM_LIT:1000> ) <EOL> return pytz . utc . localize ( date ) . astimezone ( pytz . timezone ( settings . TIME_ZONE ) ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def sumAvailable ( value ) : <EOL> """<STR_LIT>""" <EOL> result = [ x [ '<STR_LIT>' ] for x in value ] <EOL> return sum ( result ) <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def hexEncode ( value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , unicode ) : <EOL> value = value . encode ( '<STR_LIT:ascii>' , '<STR_LIT>' ) <EOL> return value <EOL> @ register . filter ( name = '<STR_LIT>' ) <EOL> def tsRange ( ts , value ) : <EOL> """<STR_LIT>""" <EOL> if not value or not ts : <EOL> return "<STR_LIT>" <EOL> time = int ( ts ) <EOL> val = int ( value ) <EOL> return "<STR_LIT>" % ( time - val , time + val ) <EOL> def genPagination ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> tokens = token . split_contents ( ) <EOL> tag_name = tokens [ <NUM_LIT:0> ] <EOL> start = tokens [ <NUM_LIT:1> ] <EOL> total = tokens [ <NUM_LIT:2> ] <EOL> openTab = tokens [ <NUM_LIT:3> ] <EOL> query = tokens [ <NUM_LIT:4> ] <EOL> indices = tokens [ <NUM_LIT:5> ] <EOL> sortField = tokens [ <NUM_LIT:6> ] <EOL> sortOrder = tokens [ <NUM_LIT:7> ] <EOL> except ValueError : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % tag_name ) <EOL> return Paginate ( start , total , openTab , query , indices , sortField , sortOrder ) <EOL> class Paginate ( template . Node ) : <EOL> def __init__ ( self , start , total , openTab , query , indices , sortField , sortOrder ) : <EOL> self . start = template . Variable ( start ) <EOL> self . total = template . Variable ( total ) <EOL> self . openTab = template . Variable ( openTab ) <EOL> self . query = template . Variable ( query ) <EOL> self . indices = template . Variable ( indices ) <EOL> self . sortField = template . Variable ( sortField ) <EOL> self . sortOrder = template . Variable ( sortOrder ) <EOL> def render ( self , context ) : <EOL> result = '<STR_LIT>' <EOL> start = int ( self . start . resolve ( context ) ) <EOL> total = int ( self . total . resolve ( context ) ) <EOL> page = ( start / settings . PAGE_SIZE ) + <NUM_LIT:1> <EOL> onclick = """<STR_LIT>""" + settings . STATIC_URL + """<STR_LIT>""" % ( self . openTab . resolve ( context ) , self . query . resolve ( context ) , self . indices . resolve ( context ) ) + """<STR_LIT>""" % ( self . sortField . resolve ( context ) , self . sortOrder . resolve ( context ) ) + """<STR_LIT>""" <EOL> if page == <NUM_LIT:1> and total > settings . PAGE_SIZE : <EOL> result += '<STR_LIT>' <EOL> result += '<STR_LIT>' <EOL> elif total > settings . PAGE_SIZE : <EOL> result += '<STR_LIT>' + onclick % <NUM_LIT:0> + '<STR_LIT>' <EOL> result += '<STR_LIT>' + onclick % ( settings . PAGE_SIZE * ( page - <NUM_LIT:2> ) ) + '<STR_LIT>' <EOL> result += '<STR_LIT>' + onclick % ( settings . PAGE_SIZE * ( page - <NUM_LIT:2> ) ) + '<STR_LIT:>>' + str ( page - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> if total > settings . PAGE_SIZE : <EOL> result += '<STR_LIT>' + str ( page ) + '<STR_LIT>' <EOL> if ( start + settings . PAGE_SIZE ) < total : <EOL> result += '<STR_LIT>' + onclick % ( settings . PAGE_SIZE * page ) + '<STR_LIT:>>' + str ( page + <NUM_LIT:1> ) + '<STR_LIT>' <EOL> if ( start + <NUM_LIT:2> * settings . PAGE_SIZE ) < total : <EOL> result += '<STR_LIT>' + onclick % ( settings . PAGE_SIZE * ( page + <NUM_LIT:1> ) ) + '<STR_LIT:>>' + str ( page + <NUM_LIT:2> ) + '<STR_LIT>' <EOL> if ( start + <NUM_LIT:3> * settings . PAGE_SIZE ) < total : <EOL> result += '<STR_LIT>' + onclick % ( settings . PAGE_SIZE * ( page + <NUM_LIT:2> ) ) + '<STR_LIT:>>' + str ( page + <NUM_LIT:3> ) + '<STR_LIT>' <EOL> if ( start + settings . PAGE_SIZE ) < total : <EOL> result += '<STR_LIT>' + onclick % ( settings . PAGE_SIZE * page ) + '<STR_LIT>' <EOL> result += '<STR_LIT>' <EOL> return result <EOL> register . tag ( '<STR_LIT>' , genPagination ) </s>
