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