Changeset 14139


Ignore:
Timestamp:
03/16/12 11:58:38 (12 years ago)
Author:
ramonb
Message:

templatetags/cmts_extras.py:

  • this is better
  • now 'output' can be a different name and will be also respected
  • i.e.: %store /path/file as blaataap
  • see #4
File:
1 edited

Legend:

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

    r14138 r14139  
    173173    tag = definition[0]
    174174    path_arg = definition[1]
    175     #kw_as = definition[2]
    176     #kw_output = definition[3]
    177175
    178176    if len(definition) == 4:
    179177
    180         #RB: OLDSTYLE
     178            #RB: OLDSTYLE
    181179        #RB: 4 arguments means: {% store /path/filename as output %}
    182180        #RB: old style: DONT try to resolve variable
    183181        #RB: instead convert filename to quoted string
    184182
     183        kw_as = definition[2]
     184        kw_output_name = definition[3]
     185
    185186        path_str = "'%s'" %path_arg
    186187
     
    188189        nodelist = parser.parse()
    189190
    190         # RB: set backwards compatibility for StoreOutput
    191         bw_compat = True
    192 
    193191    else:
    194         #RB: NEWSTYLE
     192        #RB: NEWSTYLE
    195193        #RB: 2 arguments can mean: {% store 'string' %}
    196194        #RB: 2 arguments can mean: {% store variable %}
     195
     196        kw_output_name = None
    197197
    198198        path_str = path_arg
     
    203203        parser.delete_first_token()
    204204
    205         # RB: no backwards compatibility for StoreOutput
    206         bw_compat = False
    207 
    208205    # RB: Now lets start writing output files
    209     return generateStoreOutput(tag, path_str, nodelist, bw_compat)
     206    return generateStoreOutput(tag, path_str, nodelist, kw_output_name)
    210207
    211208class generateStoreOutput(template.Node):
    212209
    213     def __init__(self, tag, path_str, nodelist, bw_compat=False):
     210    def __init__(self, tag, path_str, nodelist, kw_output_name=None):
    214211        self.tag = tag
    215212        self.nodelist = nodelist
    216213        self.path_str = path_str
    217         self.bw_compat = bw_compat
     214        self.kw_output_name = kw_output_name
    218215
    219216    def render(self, context):
     
    232229                pass
    233230
    234         if self.bw_compat:
     231        if self.kw_output_name:
    235232            # RB: store 'output' variable filename for BW compat
    236233
    237             context[ 'output' ] = mypath_str
     234            context[ self.kw_output_name ] = mypath_str
    238235
    239236        # RB: render template between store tags
Note: See TracChangeset for help on using the changeset viewer.