Fixin Partial and Set Tag
This commit is contained in:
parent
f2eb048f0b
commit
a139594863
@ -7,11 +7,12 @@ from django.http import request
|
||||
register = template.Library()
|
||||
|
||||
def remove_formatting(string):
|
||||
for to_strip in ["'", '"', ' ']:
|
||||
string = string.strip(to_strip)
|
||||
|
||||
for to_remove in ['\t', '\n',]:
|
||||
string = string.replace(to_remove, '')
|
||||
if type(string) is str:
|
||||
for to_strip in ["'", '"', ' ']:
|
||||
string = string.strip(to_strip)
|
||||
|
||||
for to_remove in ['\t', '\n',]:
|
||||
string = string.replace(to_remove, '')
|
||||
|
||||
return string
|
||||
|
||||
@ -50,11 +51,12 @@ class VariableNode(template.Node):
|
||||
def render(self, context):
|
||||
if type(self.content) is not str:
|
||||
self.content = self.content.render(context)
|
||||
try:
|
||||
self.content = template.Variable(self.content).resolve(context)
|
||||
except template.VariableDoesNotExist:
|
||||
pass
|
||||
|
||||
self.content = remove_formatting(self.content)
|
||||
|
||||
self.content = template.Variable(self.content).resolve(context)
|
||||
|
||||
context[self.name] = self.content
|
||||
return ''
|
||||
|
||||
@ -100,8 +102,20 @@ def partial(parser, token):
|
||||
raise template.TemplateSyntaxError('%r expects a partial name' % split[0])
|
||||
|
||||
if len(split) == 2:
|
||||
nodeList = parser.parse(('end%s'%split[0],))
|
||||
parser.delete_first_token()
|
||||
block_tag = False
|
||||
for token in reversed(parser.tokens):
|
||||
if 'end%s'%split[0] in token.contents:
|
||||
block_tag = True
|
||||
break
|
||||
|
||||
if split[0] in token.contents:
|
||||
break
|
||||
|
||||
if block_tag:
|
||||
nodeList = parser.parse(('end%s'%split[0],))
|
||||
parser.delete_first_token()
|
||||
else:
|
||||
nodeList = template.NodeList()
|
||||
return PartialNode(partial_name, nodeList)
|
||||
else:
|
||||
nodeList = template.NodeList()
|
||||
|
Loading…
Reference in New Issue
Block a user