<s> from rwbench import ROOT <EOL> from os . path import join <EOL> from django . conf import settings <EOL> settings . configure ( <EOL> TEMPLATE_DIRS = ( join ( ROOT , '<STR_LIT>' ) , ) , <EOL> TEMPLATE_LOADERS = ( <EOL> ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , <EOL> ) ) , <EOL> ) <EOL> ) <EOL> from django . template import loader as django_loader , Context as DjangoContext , Node , NodeList , Variable , TokenParser <EOL> from django import template as django_template_module <EOL> from django . template import Library <EOL> django_extensions = django_template_module . Library ( ) <EOL> django_template_module . builtins . append ( django_extensions ) <EOL> from rwbench import dateformat <EOL> django_extensions . filter ( dateformat ) <EOL> def var_or_none ( x ) : <EOL> if x is not None : <EOL> return Variable ( x ) <EOL> @ django_extensions . tag <EOL> def input_field ( parser , token ) : <EOL> p = TokenParser ( token . contents ) <EOL> args = [ p . value ( ) ] <EOL> while p . more ( ) : <EOL> args . append ( p . value ( ) ) <EOL> return InputFieldNode ( * args ) <EOL> @ django_extensions . tag <EOL> def textarea ( parser , token ) : <EOL> p = TokenParser ( token . contents ) <EOL> args = [ p . value ( ) ] <EOL> while p . more ( ) : <EOL> args . append ( p . value ( ) ) <EOL> return TextareaNode ( * args ) <EOL> @ django_extensions . tag <EOL> def form ( parser , token ) : <EOL> p = TokenParser ( token . contents ) <EOL> args = [ ] <EOL> while p . more ( ) : <EOL> args . append ( p . value ( ) ) <EOL> body = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> parser . delete_first_token ( ) <EOL> return FormNode ( body , * args ) <EOL> class InputFieldNode ( Node ) : <EOL> def __init__ ( self , name , type = None , value = None ) : <EOL> self . name = var_or_none ( name ) <EOL> self . type = var_or_none ( type ) <EOL> self . value = var_or_none ( value ) <EOL> def render ( self , context ) : <EOL> name = self . name . resolve ( context ) <EOL> type = '<STR_LIT:text>' <EOL> value = '<STR_LIT>' <EOL> if self . type is not None : <EOL> type = self . type . resolve ( context ) <EOL> if self . value is not None : <EOL> value = self . value . resolve ( context ) <EOL> tmpl = django_loader . get_template ( '<STR_LIT>' ) <EOL> return tmpl . render ( DjangoContext ( { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:type>' : type , <EOL> '<STR_LIT:value>' : value <EOL> } ) ) <EOL> class TextareaNode ( Node ) : <EOL> def __init__ ( self , name , rows = None , cols = None , value = None ) : <EOL> self . name = var_or_none ( name ) <EOL> self . rows = var_or_none ( rows ) <EOL> self . cols = var_or_none ( cols ) <EOL> self . value = var_or_none ( value ) <EOL> def render ( self , context ) : <EOL> name = self . name . resolve ( context ) <EOL> rows = <NUM_LIT:10> <EOL> cols = <NUM_LIT> <EOL> value = '<STR_LIT>' <EOL> if self . rows is not None : <EOL> rows = int ( self . rows . resolve ( context ) ) <EOL> if self . cols is not None : <EOL> cols = int ( self . cols . resolve ( context ) ) <EOL> if self . value is not None : <EOL> value = self . value . resolve ( context ) <EOL> tmpl = django_loader . get_template ( '<STR_LIT>' ) <EOL> return tmpl . render ( DjangoContext ( { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : rows , <EOL> '<STR_LIT>' : cols , <EOL> '<STR_LIT:value>' : value <EOL> } ) ) <EOL> class FormNode ( Node ) : <EOL> def __init__ ( self , body , action = None , method = None ) : <EOL> self . body = body <EOL> self . action = action <EOL> self . method = method <EOL> def render ( self , context ) : <EOL> body = self . body . render ( context ) <EOL> action = '<STR_LIT>' <EOL> method = '<STR_LIT>' <EOL> if self . action is not None : <EOL> action = self . action . resolve ( context ) <EOL> if self . method is not None : <EOL> method = self . method . resolve ( context ) <EOL> tmpl = django_loader . get_template ( '<STR_LIT>' ) <EOL> return tmpl . render ( DjangoContext ( { <EOL> '<STR_LIT:body>' : body , <EOL> '<STR_LIT:action>' : action , <EOL> '<STR_LIT>' : method <EOL> } ) ) </s>
