<s> from django import template <EOL> from django . core . urlresolvers import reverse <EOL> register = template . Library ( ) <EOL> class NewsletterstyleNode ( template . Node ) : <EOL> def __init__ ( self , key , style , request ) : <EOL> self . key = key <EOL> self . style = style <EOL> self . request_var = template . Variable ( request ) <EOL> def render ( self , context ) : <EOL> request = self . request_var . resolve ( context ) <EOL> if not hasattr ( request , '<STR_LIT>' ) : <EOL> setattr ( request , '<STR_LIT>' , dict ( ) ) <EOL> request . _pennyblack_newsletterstyle [ str ( self . key ) ] = self . style . render ( context ) <EOL> return '<STR_LIT>' <EOL> def newsletterstyle ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = list ( token . split_contents ( ) ) <EOL> if len ( bits ) != <NUM_LIT:3> : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % <EOL> bits [ <NUM_LIT:0> ] ) <EOL> request = bits [ <NUM_LIT:1> ] <EOL> key = parser . compile_filter ( bits [ <NUM_LIT:2> ] ) <EOL> style = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return NewsletterstyleNode ( key , style , request ) <EOL> newsletterstyle = register . tag ( newsletterstyle ) <EOL> class NewsletterGetStyleNode ( template . Node ) : <EOL> def __init__ ( self , key , request ) : <EOL> self . key = key <EOL> self . request_var = template . Variable ( request ) <EOL> def render ( self , context ) : <EOL> request = self . request_var . resolve ( context ) <EOL> if not hasattr ( request , '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> if str ( self . key ) not in request . _pennyblack_newsletterstyle . keys ( ) : <EOL> return '<STR_LIT>' <EOL> return request . _pennyblack_newsletterstyle [ str ( self . key ) ] <EOL> def get_newsletterstyle ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = list ( token . split_contents ( ) ) <EOL> if len ( bits ) != <NUM_LIT:3> : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % <EOL> bits [ <NUM_LIT:0> ] ) <EOL> request = bits [ <NUM_LIT:1> ] <EOL> key = parser . compile_filter ( bits [ <NUM_LIT:2> ] ) <EOL> return NewsletterGetStyleNode ( key , request ) <EOL> get_newsletterstyle = register . tag ( get_newsletterstyle ) <EOL> class NewsletterHeaderImageNode ( template . Node ) : <EOL> def __init__ ( self , extra_args = { } ) : <EOL> self . extra_args = extra_args <EOL> def render ( self , context ) : <EOL> newsletter = context [ '<STR_LIT>' ] <EOL> if context [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in context : <EOL> mail = context [ '<STR_LIT>' ] <EOL> header_url = mail . get_header_url ( ) <EOL> else : <EOL> header_url = '<STR_LIT>' <EOL> header_image = newsletter . header_image . get_absolute_url ( ) <EOL> else : <EOL> mail = context [ '<STR_LIT>' ] <EOL> header_url = mail . get_header_url ( ) <EOL> header_image = newsletter . get_base_url ( ) + reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : mail . mail_hash , '<STR_LIT:filename>' : newsletter . header_image } ) <EOL> return """<STR_LIT>""" % ( header_url , header_image , '<STR_LIT:U+0020>' . join ( self . extra_args ) ) <EOL> @ register . tag <EOL> def header_image ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = list ( token . split_contents ( ) ) <EOL> extra_args = [ ] <EOL> for bit in bits : <EOL> splitted = bit . split ( '<STR_LIT:=>' ) <EOL> if len ( splitted ) == <NUM_LIT:2> : <EOL> extra_args . append ( bit ) <EOL> return NewsletterHeaderImageNode ( extra_args = extra_args ) <EOL> class NewsletterLinkUrlNode ( template . Node ) : <EOL> def __init__ ( self , identifier = None ) : <EOL> self . identifier = identifier <EOL> def render ( self , context ) : <EOL> from pennyblack . models import Link , Newsletter <EOL> if '<STR_LIT>' not in context : <EOL> return u'<STR_LIT:#>' <EOL> mail = context [ '<STR_LIT>' ] <EOL> newsletter = mail . job . newsletter <EOL> if newsletter . is_workflow ( ) : <EOL> job = newsletter . get_default_job ( ) <EOL> else : <EOL> job = mail . job <EOL> try : <EOL> link = job . links . get ( identifier = self . identifier ) <EOL> except job . links . model . DoesNotExist : <EOL> link = Newsletter . add_view_link_to_job ( self . identifier , job ) <EOL> return context [ '<STR_LIT>' ] + reverse ( '<STR_LIT>' , args = ( mail . mail_hash , link . link_hash ) ) <EOL> @ register . tag <EOL> def link_url ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = list ( token . split_contents ( ) ) <EOL> if len ( bits ) != <NUM_LIT:2> : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" % <EOL> bits [ <NUM_LIT:0> ] ) <EOL> return NewsletterLinkUrlNode ( identifier = bits [ <NUM_LIT:1> ] ) <EOL> class ContentImageUrlNode ( template . Node ) : <EOL> def render ( self , context ) : <EOL> if '<STR_LIT>' in context : <EOL> return context [ '<STR_LIT:content>' ] . get_image_url ( context = context ) <EOL> return context [ '<STR_LIT:content>' ] . get_image_url ( ) <EOL> @ register . tag <EOL> def content_image_url ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> return ContentImageUrlNode ( ) </s>
