- Timestamp:
- 01/28/11 13:51:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sara_cmt/sara_cmt/cluster/templatetags/ramonb_extras.py
r12442 r12444 53 53 54 54 """ 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:] 62 69 63 70 return resolveVariables( new_var, assignees ) … … 69 76 self.varname = varname 70 77 self.varlist = varlist 71 self.resvars = [ ] 72 73 def render(self, context): 74 75 aarsvars = [ ] 78 79 def render(self, context): 80 81 resvars = [ ] 76 82 77 83 for a in self.varlist: 78 84 79 85 var_str = '' 86 80 87 if not (a[0] == a[-1] and a[0] in ('"', "'")): 81 88 try: 89 # RB: assume strings are quoted 90 # 82 91 a_var = template.Variable( a ) 83 92 var_str = a_var.resolve(context) 93 84 94 except template.VariableDoesNotExist: 95 96 #RB: still think not allowed to raise exceptions from render function 97 # 85 98 #raise template.TemplateSyntaxError, 'cannot resolve variable %r' %( str( self.path ) ) 86 99 pass 87 100 88 aarsvars.append( str(var_str) )101 resvars.append( str(var_str) ) 89 102 90 103 else: 104 #RB: strip quotes from string 91 105 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, '' ) 97 110 98 111 #RB: Django render functions not supposed/allowed to raise Exception, I think
Note: See TracChangeset
for help on using the changeset viewer.