<s> from django . template import TemplateSyntaxError <EOL> from django import template <EOL> register = template . Library ( ) <EOL> from zorna . site . models import SiteOptions <EOL> class check_if_has_access_to_option_node ( template . Node ) : <EOL> def __init__ ( self , key , var_name ) : <EOL> self . var_name = var_name <EOL> if not ( key [ <NUM_LIT:0> ] == key [ - <NUM_LIT:1> ] and key [ <NUM_LIT:0> ] in ( '<STR_LIT:">' , "<STR_LIT:'>" ) ) : <EOL> self . key = key <EOL> else : <EOL> self . key = key [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> def render ( self , context ) : <EOL> request = context [ '<STR_LIT>' ] <EOL> try : <EOL> context [ self . var_name ] = SiteOptions . objects . is_access_valid ( <EOL> request . user , self . key ) <EOL> except : <EOL> pass <EOL> return '<STR_LIT>' <EOL> @ register . tag ( name = "<STR_LIT>" ) <EOL> def check_if_has_access_to_option ( parser , token ) : <EOL> bits = token . split_contents ( ) <EOL> if <NUM_LIT:4> != len ( bits ) : <EOL> raise TemplateSyntaxError ( '<STR_LIT>' % bits [ <NUM_LIT:0> ] ) <EOL> if bits [ - <NUM_LIT:2> ] != '<STR_LIT>' : <EOL> raise TemplateSyntaxError ( <EOL> '<STR_LIT>' % bits [ <NUM_LIT:0> ] ) <EOL> key = bits [ <NUM_LIT:1> ] <EOL> varname = bits [ - <NUM_LIT:1> ] <EOL> return check_if_has_access_to_option_node ( key , varname ) </s>
