<s> from django import template <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> register = template . Library ( ) <EOL> def resolve ( what , context ) : <EOL> try : <EOL> return template . Variable ( what ) . resolve ( context ) <EOL> except template . VariableDoesNotExist : <EOL> return what <EOL> def get_bits ( token ) : <EOL> bits = token . split_contents ( ) <EOL> return [ bit . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) for bit in bits [ <NUM_LIT:1> : ] ] <EOL> def button ( template_name ) : <EOL> def tag ( parser , token ) : <EOL> return ButtonTag ( template_name , get_bits ( token ) ) <EOL> return tag <EOL> class ButtonTag ( template . Node ) : <EOL> def __init__ ( self , template_name , params = [ ] ) : <EOL> self . template_name = template_name <EOL> self . params = params <EOL> def render ( self , context ) : <EOL> if not '<STR_LIT>' in context : <EOL> raise AttributeError ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> button = '<STR_LIT>' . join ( [ resolve ( bit , context ) for bit in self . params ] ) <EOL> return template . loader . render_to_string ( self . template_name , { <EOL> '<STR_LIT>' : button } , context ) </s>
