<s> from django import template <EOL> from django . template . defaultfilters import linebreaks , urlize <EOL> from symposion . conference . models import current_conference <EOL> from symposion . sponsorship . models import Sponsor , SponsorLevel <EOL> register = template . Library ( ) <EOL> class SponsorsNode ( template . Node ) : <EOL> @ classmethod <EOL> def handle_token ( cls , parser , token ) : <EOL> bits = token . split_contents ( ) <EOL> if len ( bits ) == <NUM_LIT:3> and bits [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> return cls ( bits [ <NUM_LIT:2> ] ) <EOL> elif len ( bits ) == <NUM_LIT:4> and bits [ <NUM_LIT:2> ] == "<STR_LIT>" : <EOL> return cls ( bits [ <NUM_LIT:3> ] , bits [ <NUM_LIT:1> ] ) <EOL> else : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> def __init__ ( self , context_var , level = None ) : <EOL> if level : <EOL> self . level = template . Variable ( level ) <EOL> else : <EOL> self . level = None <EOL> self . context_var = context_var <EOL> def render ( self , context ) : <EOL> conference = current_conference ( ) <EOL> if self . level : <EOL> level = self . level . resolve ( context ) <EOL> queryset = Sponsor . objects . filter ( <EOL> level__conference = conference , level__name__iexact = level , active = True ) . order_by ( "<STR_LIT>" ) <EOL> else : <EOL> queryset = Sponsor . objects . filter ( level__conference = conference , active = True ) . order_by ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> context [ self . context_var ] = queryset <EOL> return u"<STR_LIT>" <EOL> class SponsorLevelNode ( template . Node ) : <EOL> @ classmethod <EOL> def handle_token ( cls , parser , token ) : <EOL> bits = token . split_contents ( ) <EOL> if len ( bits ) == <NUM_LIT:3> and bits [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> return cls ( bits [ <NUM_LIT:2> ] ) <EOL> else : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> def __init__ ( self , context_var ) : <EOL> self . context_var = context_var <EOL> def render ( self , context ) : <EOL> conference = current_conference ( ) <EOL> context [ self . context_var ] = SponsorLevel . objects . filter ( conference = conference ) <EOL> return u"<STR_LIT>" <EOL> @ register . tag <EOL> def sponsors ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> return SponsorsNode . handle_token ( parser , token ) <EOL> @ register . tag <EOL> def sponsor_levels ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> return SponsorLevelNode . handle_token ( parser , token ) <EOL> class LocalizedTextNode ( template . Node ) : <EOL> @ classmethod <EOL> def handle_token ( cls , parser , token ) : <EOL> bits = token . split_contents ( ) <EOL> if len ( bits ) == <NUM_LIT:3> : <EOL> return cls ( bits [ <NUM_LIT:2> ] , bits [ <NUM_LIT:1> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> elif len ( bits ) == <NUM_LIT:5> and bits [ - <NUM_LIT:2> ] == "<STR_LIT>" : <EOL> return cls ( bits [ <NUM_LIT:2> ] , bits [ <NUM_LIT:1> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] , bits [ <NUM_LIT:4> ] ) <EOL> else : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % bits [ <NUM_LIT:0> ] ) <EOL> def __init__ ( self , sponsor , content_type , context_var = None ) : <EOL> self . sponsor_var = template . Variable ( sponsor ) <EOL> self . content_type = content_type <EOL> self . content_var = context_var <EOL> def render ( self , context ) : <EOL> s = '<STR_LIT>' <EOL> try : <EOL> sponsor = self . sponsor_var . resolve ( context ) <EOL> content_type = '<STR_LIT>' % ( self . content_type , context [ '<STR_LIT>' ] . LANGUAGE_CODE ) <EOL> texts = sponsor . sponsor_benefits . filter ( benefit__content_type = content_type ) <EOL> if texts . count ( ) > <NUM_LIT:0> : <EOL> s = linebreaks ( urlize ( texts [ <NUM_LIT:0> ] . text , autoescape = True ) ) <EOL> if self . content_var : <EOL> context [ self . content_var ] = s <EOL> s = '<STR_LIT>' <EOL> except : <EOL> pass <EOL> return s <EOL> @ register . tag <EOL> def localized_text ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> return LocalizedTextNode . handle_token ( parser , token ) </s>
