<s> """<STR_LIT>""" <EOL> from coffin import template <EOL> from jinja2 import contextfunction , contextfilter , Markup <EOL> from treeio . core . conf import settings <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . encoding import smart_unicode <EOL> from django . utils import translation <EOL> from django . template . defaultfilters import date as djangodate , time as djangotime <EOL> from django . db import models <EOL> from treeio . core . rendering import render_to_string <EOL> from treeio . core . models import Module , ModuleSetting <EOL> from treeio . core . rss import get_secret_key <EOL> from treeio . core import sanitizer <EOL> from treeio . finance . models import Currency <EOL> from datetime import datetime , timedelta <EOL> from dajaxice . templatetags . dajaxice_templatetags import dajaxice_js_import as dajaxice_orig_tag <EOL> import re <EOL> import base64 <EOL> import urllib <EOL> register = template . Library ( ) <EOL> def _get_modules ( request ) : <EOL> """<STR_LIT>""" <EOL> perspective = request . user . profile . get_perspective ( ) <EOL> modules = perspective . modules . filter ( display = True ) . order_by ( '<STR_LIT:title>' ) <EOL> if not modules : <EOL> modules = Module . objects . filter ( display = True ) . order_by ( '<STR_LIT:title>' ) <EOL> active = None <EOL> for module in modules : <EOL> module . type = '<STR_LIT>' <EOL> try : <EOL> import_name = module . name + "<STR_LIT:.>" + settings . HARDTREE_MODULE_IDENTIFIER <EOL> hmodule = __import__ ( import_name , fromlist = [ str ( module . name ) ] ) <EOL> urls = hmodule . URL_PATTERNS <EOL> for regexp in urls : <EOL> if re . match ( regexp , request . path ) : <EOL> active = module <EOL> module . type = hmodule . PROPERTIES [ '<STR_LIT:type>' ] <EOL> except ImportError : <EOL> pass <EOL> except AttributeError : <EOL> pass <EOL> except KeyError : <EOL> pass <EOL> return modules , active <EOL> @ contextfunction <EOL> def modules_header_block ( context ) : <EOL> "<STR_LIT>" <EOL> request = context [ '<STR_LIT>' ] <EOL> modules , active = _get_modules ( request ) <EOL> for module in modules : <EOL> module . title = _ ( module . title ) <EOL> response_format = '<STR_LIT:html>' <EOL> if '<STR_LIT>' in context : <EOL> response_format = context [ '<STR_LIT>' ] <EOL> return Markup ( render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : modules , <EOL> '<STR_LIT>' : active , <EOL> '<STR_LIT>' : request } , <EOL> response_format = response_format ) ) <EOL> register . object ( modules_header_block ) <EOL> @ contextfunction <EOL> def dajaxice_js_import ( context ) : <EOL> "<STR_LIT>" <EOL> return Markup ( dajaxice_orig_tag ( context ) ) <EOL> register . object ( dajaxice_js_import ) <EOL> @ contextfunction <EOL> def modules_active ( context ) : <EOL> "<STR_LIT>" <EOL> request = context [ '<STR_LIT>' ] <EOL> modules , active = _get_modules ( request ) <EOL> if active : <EOL> return active . name . replace ( "<STR_LIT:.>" , "<STR_LIT:->" ) <EOL> return "<STR_LIT>" <EOL> register . object ( modules_active ) <EOL> @ contextfunction <EOL> def paginate ( context , items , plength = None ) : <EOL> "<STR_LIT>" <EOL> request = context [ '<STR_LIT>' ] <EOL> skip = <NUM_LIT:0> <EOL> if '<STR_LIT>' in request . GET : <EOL> try : <EOL> skip = long ( request . GET [ '<STR_LIT>' ] ) <EOL> except Exception : <EOL> pass <EOL> if not plength : <EOL> plength = getattr ( settings , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> length = skip + plength <EOL> return items [ skip : length ] <EOL> register . object ( paginate ) <EOL> @ contextfunction <EOL> def pager ( context , items , plength = None ) : <EOL> "<STR_LIT>" <EOL> request = context [ '<STR_LIT>' ] <EOL> response_format = '<STR_LIT:html>' <EOL> if '<STR_LIT>' in context : <EOL> response_format = context [ '<STR_LIT>' ] <EOL> skip = <NUM_LIT:0> <EOL> if '<STR_LIT>' in request . GET : <EOL> try : <EOL> skip = long ( request . GET [ '<STR_LIT>' ] ) <EOL> except Exception : <EOL> pass <EOL> if not plength : <EOL> plength = getattr ( settings , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> if hasattr ( items , '<STR_LIT:count>' ) : <EOL> try : <EOL> items_length = items . count ( ) <EOL> except : <EOL> items_length = len ( items ) <EOL> else : <EOL> items_length = len ( items ) <EOL> pagenum = items_length // plength <EOL> if items_length % plength : <EOL> pagenum += <NUM_LIT:1> <EOL> maxpages = getattr ( settings , '<STR_LIT>' , <NUM_LIT:20> ) <EOL> current = skip // plength <EOL> start = current - ( maxpages // <NUM_LIT:2> ) <EOL> if pagenum - start < maxpages : <EOL> start = pagenum - maxpages <EOL> if start <= <NUM_LIT:0> : <EOL> start = <NUM_LIT:1> <EOL> pages = [ ] <EOL> if pagenum > <NUM_LIT:1> : <EOL> if current >= <NUM_LIT:1> : <EOL> pages . append ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : ( current - <NUM_LIT:1> ) * plength , '<STR_LIT>' : True } ) <EOL> else : <EOL> pages . append ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : True } ) <EOL> if start > <NUM_LIT:1> : <EOL> pages . append ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : ( start - <NUM_LIT:1> ) * plength , '<STR_LIT>' : False } ) <EOL> maxpages -= <NUM_LIT:1> <EOL> for i in range ( start , pagenum + <NUM_LIT:1> ) : <EOL> if i > ( maxpages + start + <NUM_LIT:1> ) : <EOL> pages . append ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : ( i ) * plength , '<STR_LIT>' : False } ) <EOL> break <EOL> else : <EOL> pages . append ( { '<STR_LIT>' : i , '<STR_LIT>' : ( i - <NUM_LIT:1> ) * plength } ) <EOL> if current + <NUM_LIT:1> == pagenum : <EOL> pages . append ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : current * plength , '<STR_LIT>' : True } ) <EOL> else : <EOL> pages . append ( <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : ( current + <NUM_LIT:1> ) * plength , '<STR_LIT>' : True } ) <EOL> url = request . path + "<STR_LIT:?>" <EOL> if request . GET : <EOL> for arg in request . GET : <EOL> if arg != '<STR_LIT>' : <EOL> values = request . GET . getlist ( arg ) <EOL> for value in values : <EOL> url += unicode ( arg ) + "<STR_LIT:=>" + value + "<STR_LIT:&>" <EOL> return Markup ( render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT:url>' : url , '<STR_LIT>' : pages , '<STR_LIT>' : skip } , <EOL> response_format = response_format ) ) <EOL> register . object ( pager ) <EOL> @ contextfunction <EOL> def htsort ( context , objects ) : <EOL> "<STR_LIT>" <EOL> if not objects or '<STR_LIT>' not in context : <EOL> return objects <EOL> request = context [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in request . GET or not hasattr ( objects , '<STR_LIT>' ) or not hasattr ( objects , '<STR_LIT>' ) : <EOL> return objects <EOL> args = request . GET . getlist ( '<STR_LIT>' ) <EOL> fields = objects . model . _meta . get_all_field_names ( ) <EOL> for arg in args : <EOL> field_name = arg . lstrip ( '<STR_LIT:->' ) <EOL> if field_name in fields : <EOL> field = objects . model . _meta . get_field ( field_name ) <EOL> if isinstance ( field , models . ManyToManyField ) : <EOL> agg_field = agg_arg = str ( '<STR_LIT>' % field_name ) <EOL> if arg [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> agg_arg = '<STR_LIT:->' + agg_arg <EOL> kwargs = { agg_field : models . Count ( field_name ) } <EOL> objects = objects . annotate ( ** kwargs ) . order_by ( agg_arg ) <EOL> else : <EOL> objects = objects . order_by ( arg ) <EOL> return objects . distinct ( ) <EOL> register . object ( htsort ) <EOL> @ contextfunction <EOL> def htsortlink ( context , field_name ) : <EOL> "<STR_LIT>" <EOL> if '<STR_LIT>' not in context : <EOL> return '<STR_LIT>' <EOL> request = context [ '<STR_LIT>' ] <EOL> sort_value = field_name <EOL> url = u"<STR_LIT>" % ( request . path ) <EOL> if request . GET : <EOL> for arg in request . GET : <EOL> values = request . GET . getlist ( arg ) <EOL> for value in values : <EOL> svalue = value . lstrip ( '<STR_LIT:->' ) <EOL> if arg == '<STR_LIT>' and svalue == field_name : <EOL> if value [ <NUM_LIT:0> ] != '<STR_LIT:->' : <EOL> sort_value = u'<STR_LIT>' % sort_value <EOL> else : <EOL> url += unicode ( arg ) + "<STR_LIT:=>" + value + "<STR_LIT:&>" <EOL> url += "<STR_LIT>" % sort_value <EOL> return url <EOL> register . object ( htsortlink ) <EOL> @ contextfunction <EOL> def object_tree_path ( context , object , skipself = False ) : <EOL> "<STR_LIT>" <EOL> response_format = '<STR_LIT:html>' <EOL> if '<STR_LIT>' in context : <EOL> response_format = context [ '<STR_LIT>' ] <EOL> path = object . get_tree_path ( skipself ) <EOL> return Markup ( render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT:path>' : path , '<STR_LIT>' : skipself } , <EOL> response_format = response_format ) ) <EOL> register . object ( object_tree_path ) <EOL> def htsafe ( text ) : <EOL> """<STR_LIT>""" <EOL> text = smart_unicode ( text ) <EOL> safe_string = smart_unicode ( sanitizer . clean_html ( text ) ) <EOL> return Markup ( safe_string ) <EOL> register . filter ( '<STR_LIT>' , htsafe ) <EOL> def httranslate ( text ) : <EOL> "<STR_LIT>" <EOL> return Markup ( _ ( text ) ) <EOL> register . object ( httranslate ) <EOL> @ contextfunction <EOL> def htform ( context , form ) : <EOL> "<STR_LIT>" <EOL> request = context [ '<STR_LIT>' ] <EOL> user = None <EOL> if request . user . username : <EOL> try : <EOL> user = request . user . profile <EOL> except Exception : <EOL> pass <EOL> default_timezone = settings . HARDTREE_SERVER_DEFAULT_TIMEZONE <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except : <EOL> pass <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' , user = user ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except Exception : <EOL> default_timezone = getattr ( <EOL> settings , '<STR_LIT>' ) [ default_timezone ] [ <NUM_LIT:0> ] <EOL> all_timezones = getattr ( settings , '<STR_LIT>' , [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] ) <EOL> title = all_timezones [ int ( default_timezone ) ] [ <NUM_LIT:1> ] <EOL> GMT = title [ <NUM_LIT:4> : <NUM_LIT:10> ] <EOL> sign = GMT [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> hours = int ( GMT [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> mins = int ( GMT [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> if not form . errors : <EOL> for field in form : <EOL> try : <EOL> date = datetime . strptime ( <EOL> str ( field . form . initial [ field . name ] ) , "<STR_LIT>" ) <EOL> if date : <EOL> if sign == "<STR_LIT:->" : <EOL> field . form . initial [ <EOL> field . name ] = date - timedelta ( hours = hours , minutes = mins ) <EOL> else : <EOL> field . form . initial [ <EOL> field . name ] = date + timedelta ( hours = hours , minutes = mins ) <EOL> except : <EOL> pass <EOL> return form <EOL> register . object ( htform ) <EOL> @ contextfilter <EOL> def htdate ( context , date , dateformat = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if not date : <EOL> return '<STR_LIT>' <EOL> lang = translation . get_language ( ) <EOL> localeformat = dateformat <EOL> formatspath = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> modulepath = formatspath + "<STR_LIT:.>" + lang + "<STR_LIT>" <EOL> module = __import__ ( modulepath , fromlist = [ str ( modulepath ) ] ) <EOL> localeformat = getattr ( module , dateformat , dateformat ) <EOL> except ImportError : <EOL> pass <EOL> request = context [ '<STR_LIT>' ] <EOL> user = None <EOL> if request . user . username : <EOL> try : <EOL> user = request . user . profile <EOL> except Exception : <EOL> pass <EOL> default_timezone = settings . HARDTREE_SERVER_DEFAULT_TIMEZONE <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except : <EOL> pass <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' , user = user ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except Exception : <EOL> default_timezone = getattr ( <EOL> settings , '<STR_LIT>' ) [ default_timezone ] [ <NUM_LIT:0> ] <EOL> all_timezones = getattr ( settings , '<STR_LIT>' , [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] ) <EOL> title = all_timezones [ int ( default_timezone ) ] [ <NUM_LIT:1> ] <EOL> GMT = title [ <NUM_LIT:4> : <NUM_LIT:10> ] <EOL> sign = GMT [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> hours = int ( GMT [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> mins = int ( GMT [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> if sign == "<STR_LIT:->" : <EOL> date = date - timedelta ( hours = hours , minutes = mins ) <EOL> else : <EOL> date = date + timedelta ( hours = hours , minutes = mins ) <EOL> result = djangodate ( date , localeformat ) <EOL> return Markup ( result ) <EOL> register . filter ( '<STR_LIT>' , htdate ) <EOL> @ contextfilter <EOL> def htdatetime ( context , date , dateformat = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if not date : <EOL> return '<STR_LIT>' <EOL> lang = translation . get_language ( ) <EOL> localeformat = dateformat <EOL> formatspath = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> modulepath = formatspath + "<STR_LIT:.>" + lang + "<STR_LIT>" <EOL> module = __import__ ( modulepath , fromlist = [ str ( modulepath ) ] ) <EOL> localeformat = getattr ( module , dateformat , dateformat ) <EOL> except ImportError : <EOL> pass <EOL> request = context [ '<STR_LIT>' ] <EOL> user = None <EOL> if request . user . username : <EOL> try : <EOL> user = request . user . profile <EOL> except Exception : <EOL> pass <EOL> default_timezone = settings . HARDTREE_SERVER_DEFAULT_TIMEZONE <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except : <EOL> pass <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' , user = user ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except Exception : <EOL> default_timezone = getattr ( <EOL> settings , '<STR_LIT>' ) [ default_timezone ] [ <NUM_LIT:0> ] <EOL> all_timezones = getattr ( settings , '<STR_LIT>' , [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] ) <EOL> title = all_timezones [ int ( default_timezone ) ] [ <NUM_LIT:1> ] <EOL> GMT = title [ <NUM_LIT:4> : <NUM_LIT:10> ] <EOL> sign = GMT [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> hours = int ( GMT [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> mins = int ( GMT [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> if sign == "<STR_LIT:->" : <EOL> date = date - timedelta ( hours = hours , minutes = mins ) <EOL> else : <EOL> date = date + timedelta ( hours = hours , minutes = mins ) <EOL> result = djangodate ( date , localeformat ) <EOL> return Markup ( result ) <EOL> register . filter ( '<STR_LIT>' , htdatetime ) <EOL> @ contextfilter <EOL> def httime ( context , time , timeformat = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if not time : <EOL> return '<STR_LIT>' <EOL> lang = translation . get_language ( ) <EOL> localeformat = timeformat <EOL> formatspath = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> modulepath = formatspath + "<STR_LIT:.>" + lang + "<STR_LIT>" <EOL> module = __import__ ( modulepath , fromlist = [ str ( modulepath ) ] ) <EOL> localeformat = getattr ( module , timeformat , timeformat ) <EOL> except ImportError : <EOL> pass <EOL> request = context [ '<STR_LIT>' ] <EOL> user = None <EOL> if request . user . username : <EOL> try : <EOL> user = request . user . profile <EOL> except Exception : <EOL> pass <EOL> default_timezone = settings . HARDTREE_SERVER_DEFAULT_TIMEZONE <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except : <EOL> pass <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' , user = user ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except Exception : <EOL> default_timezone = getattr ( <EOL> settings , '<STR_LIT>' ) [ default_timezone ] [ <NUM_LIT:0> ] <EOL> all_timezones = getattr ( settings , '<STR_LIT>' , [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] ) <EOL> title = all_timezones [ int ( default_timezone ) ] [ <NUM_LIT:1> ] <EOL> GMT = title [ <NUM_LIT:4> : <NUM_LIT:10> ] <EOL> sign = GMT [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> hours = int ( GMT [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> mins = int ( GMT [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> if sign == "<STR_LIT:->" : <EOL> time = time - timedelta ( hours = hours , minutes = mins ) <EOL> else : <EOL> time = time + timedelta ( hours = hours , minutes = mins ) <EOL> result = djangotime ( time , localeformat ) <EOL> return Markup ( result ) <EOL> register . filter ( '<STR_LIT>' , httime ) <EOL> @ contextfunction <EOL> def core_logo_content ( context , gif = False ) : <EOL> "<STR_LIT>" <EOL> staticpath = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> logopath = staticpath + '<STR_LIT>' <EOL> if gif : <EOL> logopath += '<STR_LIT>' <EOL> mimetype = '<STR_LIT>' <EOL> else : <EOL> logopath += '<STR_LIT>' <EOL> mimetype = '<STR_LIT>' <EOL> customlogo = '<STR_LIT>' <EOL> try : <EOL> conf = ModuleSetting . get_for_module ( '<STR_LIT>' , '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> customlogo = getattr ( <EOL> settings , '<STR_LIT>' , '<STR_LIT>' ) + conf . value <EOL> except : <EOL> pass <EOL> logofile = '<STR_LIT>' <EOL> if customlogo : <EOL> try : <EOL> logofile = open ( customlogo , '<STR_LIT:r>' ) <EOL> except : <EOL> pass <EOL> if not logofile : <EOL> try : <EOL> logofile = open ( logopath , '<STR_LIT:r>' ) <EOL> except : <EOL> pass <EOL> result = "<STR_LIT>" + mimetype + "<STR_LIT>" + base64 . b64encode ( logofile . read ( ) ) <EOL> return Markup ( result ) <EOL> register . object ( core_logo_content ) <EOL> MOMENT = <NUM_LIT> <EOL> @ contextfilter <EOL> def humanize_datetime ( context , value ) : <EOL> """<STR_LIT>""" <EOL> request = context [ '<STR_LIT>' ] <EOL> user = None <EOL> if request . user . username : <EOL> try : <EOL> user = request . user . profile <EOL> except : <EOL> pass <EOL> default_timezone = settings . HARDTREE_SERVER_DEFAULT_TIMEZONE <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except : <EOL> pass <EOL> try : <EOL> conf = ModuleSetting . get ( '<STR_LIT>' , user = user ) [ <NUM_LIT:0> ] <EOL> default_timezone = conf . value <EOL> except Exception : <EOL> default_timezone = getattr ( <EOL> settings , '<STR_LIT>' ) [ default_timezone ] [ <NUM_LIT:0> ] <EOL> all_timezones = getattr ( settings , '<STR_LIT>' , [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) ] ) <EOL> title = all_timezones [ int ( default_timezone ) ] [ <NUM_LIT:1> ] <EOL> GMT = title [ <NUM_LIT:4> : <NUM_LIT:10> ] <EOL> sign = GMT [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> hours = int ( GMT [ <NUM_LIT:1> : <NUM_LIT:3> ] ) <EOL> mins = int ( GMT [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> now = datetime . now ( ) <EOL> if value : <EOL> if sign == "<STR_LIT:->" : <EOL> value = value - timedelta ( hours = hours , minutes = mins ) <EOL> now = now - timedelta ( hours = hours , minutes = mins ) <EOL> else : <EOL> value = value + timedelta ( hours = hours , minutes = mins ) <EOL> now = now + timedelta ( hours = hours , minutes = mins ) <EOL> if isinstance ( value , timedelta ) : <EOL> delta = value <EOL> elif isinstance ( value , datetime ) : <EOL> delta = now - value <EOL> else : <EOL> delta = None <EOL> if delta : <EOL> if delta . days > <NUM_LIT:6> : <EOL> month = None <EOL> if value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> month = _ ( "<STR_LIT>" ) <EOL> return month + value . strftime ( "<STR_LIT>" ) <EOL> if delta . days > <NUM_LIT:1> : <EOL> if value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif value . strftime ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif delta . days == <NUM_LIT:1> : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif delta . seconds >= <NUM_LIT> : <EOL> return str ( delta . seconds / <NUM_LIT> ) + _ ( "<STR_LIT>" ) <EOL> elif delta . seconds >= <NUM_LIT> : <EOL> return _ ( "<STR_LIT>" ) <EOL> elif delta . seconds > MOMENT : <EOL> return str ( delta . seconds / <NUM_LIT> ) + _ ( "<STR_LIT>" ) <EOL> else : <EOL> return _ ( "<STR_LIT>" ) <EOL> return djangodate ( value ) <EOL> else : <EOL> return str ( value ) <EOL> register . filter ( '<STR_LIT>' , humanize_datetime ) <EOL> @ contextfilter <EOL> def currency_format ( context , value , currency = None ) : <EOL> """<STR_LIT>""" <EOL> if not currency : <EOL> currency = Currency . objects . get ( is_default = True ) <EOL> if not currency . symbol : <EOL> return unicode ( value ) + "<STR_LIT:U+0020>" + currency . code <EOL> else : <EOL> return currency . symbol + unicode ( value ) <EOL> register . filter ( '<STR_LIT>' , currency_format ) <EOL> @ contextfunction <EOL> def currency_print ( context , currency = None ) : <EOL> """<STR_LIT>""" <EOL> if not currency : <EOL> currency = Currency . objects . get ( is_default = True ) <EOL> return unicode ( currency . code ) <EOL> register . object ( currency_print ) <EOL> @ contextfilter <EOL> def number_format ( context , value ) : <EOL> """<STR_LIT>""" <EOL> value = str ( value ) <EOL> negative = False <EOL> addzero = None <EOL> if value [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> value = value [ <NUM_LIT:1> : ] <EOL> negative = True <EOL> if '<STR_LIT:.>' in value : <EOL> point = value . rindex ( '<STR_LIT:.>' ) <EOL> if point == len ( value ) - <NUM_LIT:2> : <EOL> addzero = True <EOL> else : <EOL> point = len ( value ) <EOL> while point < len ( value ) - <NUM_LIT:3> : <EOL> if value [ len ( value ) - <NUM_LIT:1> ] == '<STR_LIT:0>' : <EOL> value = value [ : len ( value ) - <NUM_LIT:1> ] <EOL> else : <EOL> break <EOL> while point > <NUM_LIT:3> : <EOL> value = value [ : point - <NUM_LIT:3> ] + "<STR_LIT:U+002C>" + value [ point - <NUM_LIT:3> : ] <EOL> point = value . index ( '<STR_LIT:U+002C>' ) <EOL> if addzero : <EOL> value += "<STR_LIT:0>" <EOL> if negative : <EOL> value = "<STR_LIT:->" + value <EOL> return value <EOL> register . filter ( '<STR_LIT>' , number_format ) <EOL> @ contextfunction <EOL> def show_hint ( context , hint = None , object = None ) : <EOL> "<STR_LIT>" <EOL> request = context [ '<STR_LIT>' ] <EOL> response_format = '<STR_LIT:html>' <EOL> user = None <EOL> if request . user . username : <EOL> try : <EOL> user = request . user . profile <EOL> except Exception : <EOL> pass <EOL> return Markup ( render_to_string ( '<STR_LIT>' + hint , { '<STR_LIT:user>' : user , '<STR_LIT:object>' : object } , <EOL> response_format = response_format ) ) <EOL> register . object ( show_hint ) <EOL> @ contextfilter <EOL> def group_by_letter ( context , object_list ) : <EOL> "<STR_LIT>" <EOL> res = { } <EOL> for x in object_list : <EOL> r = re . search ( '<STR_LIT>' , x . name ) <EOL> if r : <EOL> key = r . group ( ) . lower ( ) <EOL> if key not in res : <EOL> res [ key ] = [ x ] <EOL> else : <EOL> res [ key ] . append ( x ) <EOL> n = re . search ( '<STR_LIT>' , x . name ) <EOL> if n : <EOL> if '<STR_LIT:#>' not in res : <EOL> res [ '<STR_LIT:#>' ] = [ x ] <EOL> else : <EOL> res [ '<STR_LIT:#>' ] . append ( x ) <EOL> if not n and not r : <EOL> if '<STR_LIT:#>' not in res : <EOL> res [ '<STR_LIT:#>' ] = [ x ] <EOL> else : <EOL> res [ '<STR_LIT:#>' ] . append ( x ) <EOL> l = [ ] <EOL> for k , v in res . items ( ) : <EOL> l . append ( ( k , v ) ) <EOL> l . sort ( cmp = lambda x , y : cmp ( x , y ) ) <EOL> return l <EOL> register . filter ( '<STR_LIT>' , group_by_letter ) <EOL> @ contextfunction <EOL> def rss_link ( context , url = None ) : <EOL> "<STR_LIT>" <EOL> request = context [ '<STR_LIT>' ] <EOL> params = request . GET . copy ( ) <EOL> params . update ( { '<STR_LIT>' : get_secret_key ( request ) } ) <EOL> if not url : <EOL> url = request . path <EOL> for ext in getattr ( settings , '<STR_LIT>' , { '<STR_LIT:html>' : '<STR_LIT>' } ) : <EOL> url = url . replace ( '<STR_LIT:.>' + ext , '<STR_LIT>' ) <EOL> url += '<STR_LIT>' <EOL> try : <EOL> url += '<STR_LIT:?>' + urllib . urlencode ( params ) <EOL> except : <EOL> pass <EOL> return Markup ( url ) <EOL> register . object ( rss_link ) <EOL> @ contextfunction <EOL> def logo_block_container ( context ) : <EOL> "<STR_LIT>" <EOL> response_format = '<STR_LIT:html>' <EOL> return Markup ( render_to_string ( '<STR_LIT>' , <EOL> response_format = response_format ) ) <EOL> register . object ( logo_block_container ) </s>
