Call parse_bits in django < 2.0 compatible way.

This commit is contained in:
Emil Stenström 2020-06-06 11:27:07 +02:00
parent 24369fce80
commit b5eb6f4db1

View file

@ -1,3 +1,4 @@
import django
from django import template
from django.template.base import Node, NodeList, TemplateSyntaxError, token_kwargs
from django.template.library import parse_bits
@ -16,6 +17,22 @@ except ImportError:
VAR = TOKEN_VAR
BLOCK = TOKEN_BLOCK
# Django < 2.0 compatibility
if django.VERSION > (2, 0):
PARSE_BITS_DEFAULTS = {
"varargs": None,
"varkw": [],
"defaults": None,
"kwonly": [],
"kwonly_defaults": None,
}
else:
PARSE_BITS_DEFAULTS = {
"varargs": None,
"varkw": [],
"defaults": None,
}
register = template.Library()
COMPONENT_CONTEXT_KEY = "component_context"
@ -106,15 +123,14 @@ def do_component(parser, token):
"""
bits = token.split_contents()
tag_args, tag_kwargs = parse_bits(
parser=parser,
bits=bits,
params=["tag_name", "component_name"],
varargs=None,
varkw=[],
defaults=None,
takes_context=False,
name="component_block"
name="component_block",
**PARSE_BITS_DEFAULTS
)
print(tag_args)
tag_name = tag_args.pop(0)