Changeset 14138


Ignore:
Timestamp:
03/16/12 11:51:05 (12 years ago)
Author:
ramonb
Message:

templatetags/cmts_extras.py:

  • parse entire file if oldstyle %store
  • parse until %endstore for newstyle %store
  • generateStoreOutput(): set 'output' variable in context for oldstyle %store
  • see #4
File:
1 edited

Legend:

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

    r14137 r14138  
    178178    if len(definition) == 4:
    179179
     180        #RB: OLDSTYLE
    180181        #RB: 4 arguments means: {% store /path/filename as output %}
    181182        #RB: old style: DONT try to resolve variable
     
    184185        path_str = "'%s'" %path_arg
    185186
     187        # RB: parse the entire template for old-style
     188        nodelist = parser.parse()
     189
     190        # RB: set backwards compatibility for StoreOutput
     191        bw_compat = True
     192
    186193    else:
    187 
     194        #RB: NEWSTYLE
    188195        #RB: 2 arguments can mean: {% store 'string' %}
    189196        #RB: 2 arguments can mean: {% store variable %}
     
    191198        path_str = path_arg
    192199
    193     # RB: parse the template thing until %endstore found
    194     nodelist = parser.parse(('endstore',))
    195     parser.delete_first_token()
     200        # RB: parse the template thing until %endstore found
     201        nodelist = parser.parse(('endstore',))
     202        # RB: throw away %endstore tag
     203        parser.delete_first_token()
     204
     205        # RB: no backwards compatibility for StoreOutput
     206        bw_compat = False
    196207
    197208    # RB: Now lets start writing output files
    198     return generateStoreOutput(tag, path_str, nodelist)
     209    return generateStoreOutput(tag, path_str, nodelist, bw_compat)
    199210
    200211class generateStoreOutput(template.Node):
    201212
    202     def __init__(self, tag, path_str, nodelist):
     213    def __init__(self, tag, path_str, nodelist, bw_compat=False):
    203214        self.tag = tag
    204215        self.nodelist = nodelist
    205216        self.path_str = path_str
     217        self.bw_compat = bw_compat
    206218
    207219    def render(self, context):
     
    219231                #raise template.TemplateSyntaxError, '%r tag argument 1: not a variable %r' %( tag, path_str )
    220232                pass
     233
     234        if self.bw_compat:
     235            # RB: store 'output' variable filename for BW compat
     236
     237            context[ 'output' ] = mypath_str
    221238
    222239        # RB: render template between store tags
Note: See TracChangeset for help on using the changeset viewer.