Simplify content special-casing
This commit is contained in:
parent
2ba54c9a90
commit
babec7cc2d
1 changed files with 8 additions and 5 deletions
|
@ -3,8 +3,8 @@ from django.template.library import parse_bits, SimpleNode
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
class SimpleBlockNode(SimpleNode):
|
class SimpleBlockNode(SimpleNode):
|
||||||
def __init__(self, nodelist, func, takes_context, args, kwargs, target_var):
|
def __init__(self, nodelist, *args, **kwargs):
|
||||||
super().__init__(func, takes_context, args, kwargs, target_var)
|
super().__init__(*args, **kwargs)
|
||||||
self.nodelist = nodelist
|
self.nodelist = nodelist
|
||||||
|
|
||||||
def get_resolved_arguments(self, context):
|
def get_resolved_arguments(self, context):
|
||||||
|
@ -25,11 +25,14 @@ def simple_block_tag(register, takes_context=None, name=None):
|
||||||
if len(bits) >= 2 and bits[-2] == "as":
|
if len(bits) >= 2 and bits[-2] == "as":
|
||||||
target_var = bits[-1]
|
target_var = bits[-1]
|
||||||
bits = bits[:-2]
|
bits = bits[:-2]
|
||||||
bits = [''] + bits # add placeholder for content arg
|
|
||||||
|
params = argspec.args
|
||||||
|
del params[1 if takes_context else 0]
|
||||||
|
|
||||||
args, kwargs = parse_bits(
|
args, kwargs = parse_bits(
|
||||||
parser=parser,
|
parser=parser,
|
||||||
bits=bits,
|
bits=bits,
|
||||||
params=argspec.args,
|
params=params,
|
||||||
varargs=argspec.varargs,
|
varargs=argspec.varargs,
|
||||||
varkw=argspec.varkw,
|
varkw=argspec.varkw,
|
||||||
defaults=argspec.defaults,
|
defaults=argspec.defaults,
|
||||||
|
@ -38,7 +41,7 @@ def simple_block_tag(register, takes_context=None, name=None):
|
||||||
takes_context=takes_context,
|
takes_context=takes_context,
|
||||||
name=function_name
|
name=function_name
|
||||||
)
|
)
|
||||||
args = args[1:] # remove content placeholder
|
|
||||||
nodelist = parser.parse((f'end{function_name}',))
|
nodelist = parser.parse((f'end{function_name}',))
|
||||||
parser.delete_first_token()
|
parser.delete_first_token()
|
||||||
return SimpleBlockNode(nodelist, func, takes_context, args, kwargs, target_var)
|
return SimpleBlockNode(nodelist, func, takes_context, args, kwargs, target_var)
|
||||||
|
|
Loading…
Reference in a new issue