Changeset 12444 for trunk


Ignore:
Timestamp:
01/28/11 13:51:50 (13 years ago)
Author:
ramonb
Message:

sara_cmt/cluster/templatetags/ramonb_extras.py:

  • cleanup
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sara_cmt/sara_cmt/cluster/templatetags/ramonb_extras.py

    r12442 r12444  
    5353
    5454    """
    55         Leipe shit ouwe
    56     """
    57     mijn_poep = token.split_contents()
    58     tag = mijn_poep[0]
    59     new_var = mijn_poep[1]
    60     is_teken = mijn_poep[2]
    61     assignees = mijn_poep[3:]
     55        Variable assignment within template
     56
     57        Usage: {% assign newvar = <space seprated list of strings/vars %}
     58         i.e.: {% assign file_name = '/var/tmp/rack-' rack.label '.txt' %}
     59    """
     60    definition = token.split_contents()
     61
     62    if len(definition) < 4:
     63        raise template.TemplateSyntaxError, '%r tag requires at least 4 arguments' % tag
     64
     65    tag = definition[0]
     66    new_var = definition[1]
     67    is_teken = definition[2]
     68    assignees = definition[3:]
    6269
    6370    return resolveVariables( new_var, assignees )
     
    6976        self.varname = varname
    7077        self.varlist = varlist
    71         self.resvars = [ ]
    72 
    73     def render(self, context):
    74 
    75         aarsvars = [ ]
     78
     79    def render(self, context):
     80
     81        resvars = [ ]
    7682
    7783        for a in self.varlist:
    7884
    7985            var_str = ''
     86
    8087            if not (a[0] == a[-1] and a[0] in ('"', "'")):
    8188                try:
     89                    # RB: assume strings are quoted
     90                    #
    8291                    a_var = template.Variable( a )
    8392                    var_str = a_var.resolve(context)
     93
    8494                except template.VariableDoesNotExist:
     95
     96                    #RB: still think not allowed to raise exceptions from render function
     97                    #
    8598                    #raise template.TemplateSyntaxError, 'cannot resolve variable %r' %(  str( self.path ) )
    8699                    pass
    87100
    88                 aarsvars.append( str(var_str) )
     101                resvars.append( str(var_str) )
    89102
    90103            else:
     104                #RB: strip quotes from string
    91105                a = str( a.strip("'").strip('"') )
    92                 aarsvars.append( str(a) )
    93 
    94         #print aarsvars
    95 
    96         context[ self.varname ] = string.join( aarsvars, '' )
     106                resvars.append( str(a) )
     107
     108        #RB: finally assign the concatenated string to new varname
     109        context[ self.varname ] = string.join( resvars, '' )
    97110
    98111        #RB: Django render functions not supposed/allowed to raise Exception, I think
Note: See TracChangeset for help on using the changeset viewer.