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()
|
register = template.Library()
|
||||||
|
|
||||||
def remove_formatting(string):
|
def remove_formatting(string):
|
||||||
for to_strip in ["'", '"', ' ']:
|
if type(string) is str:
|
||||||
string = string.strip(to_strip)
|
for to_strip in ["'", '"', ' ']:
|
||||||
|
string = string.strip(to_strip)
|
||||||
|
|
||||||
for to_remove in ['\t', '\n',]:
|
for to_remove in ['\t', '\n',]:
|
||||||
string = string.replace(to_remove, '')
|
string = string.replace(to_remove, '')
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
@ -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:
|
||||||
nodeList = parser.parse(('end%s'%split[0],))
|
block_tag = False
|
||||||
parser.delete_first_token()
|
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)
|
return PartialNode(partial_name, nodeList)
|
||||||
else:
|
else:
|
||||||
nodeList = template.NodeList()
|
nodeList = template.NodeList()
|
||||||
|
Loading…
Reference in New Issue
Block a user