From babec7cc2dad51de855e29ad234c4715dc96c60b Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 3 Jul 2024 14:15:54 +0100 Subject: [PATCH] Simplify content special-casing --- yamdl_playground/core/simple_tags.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/yamdl_playground/core/simple_tags.py b/yamdl_playground/core/simple_tags.py index db5f944..b493551 100644 --- a/yamdl_playground/core/simple_tags.py +++ b/yamdl_playground/core/simple_tags.py @@ -3,8 +3,8 @@ from django.template.library import parse_bits, SimpleNode from functools import wraps class SimpleBlockNode(SimpleNode): - def __init__(self, nodelist, func, takes_context, args, kwargs, target_var): - super().__init__(func, takes_context, args, kwargs, target_var) + def __init__(self, nodelist, *args, **kwargs): + super().__init__(*args, **kwargs) self.nodelist = nodelist 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": target_var = bits[-1] 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( parser=parser, bits=bits, - params=argspec.args, + params=params, varargs=argspec.varargs, varkw=argspec.varkw, defaults=argspec.defaults, @@ -38,7 +41,7 @@ def simple_block_tag(register, takes_context=None, name=None): takes_context=takes_context, name=function_name ) - args = args[1:] # remove content placeholder + nodelist = parser.parse((f'end{function_name}',)) parser.delete_first_token() return SimpleBlockNode(nodelist, func, takes_context, args, kwargs, target_var)