X-Git-Url: https://git.mdrn.pl/fnpdjango.git/blobdiff_plain/c4ec253cd69546987dc20dec4c9be9e3867986f2..02524a5492bf3a45585346ef7d989e7b823059c0:/fnpdjango/templatetags/macros.py diff --git a/fnpdjango/templatetags/macros.py b/fnpdjango/templatetags/macros.py old mode 100755 new mode 100644 index 181a497..647843d --- a/fnpdjango/templatetags/macros.py +++ b/fnpdjango/templatetags/macros.py @@ -52,9 +52,8 @@ through {% extends ... %} tags. """ from django import template -from django.template import resolve_variable, FilterExpression -from django.template.loader import get_template, get_template_from_string, find_template_source -from django.conf import settings +from django.template.base import FilterExpression +from django.template.loader import get_template import re register = template.Library() @@ -85,12 +84,12 @@ def do_macro(parser, token): args = token.split_contents() tag_name, macro_name, args = args[0], args[1], args[2:] except IndexError: - raise template.TemplateSyntaxError, "'%s' tag requires at least one argument (macro name)" % token.contents.split()[0] + raise template.TemplateSyntaxError("'%s' tag requires at least one argument (macro name)" % token.contents.split()[0]) # TODO: check that 'args' are all simple strings ([a-zA-Z0-9_]+) r_valid_arg_name = re.compile(r'^[a-zA-Z0-9_]+$') for arg in args: if not r_valid_arg_name.match(arg): - raise template.TemplateSyntaxError, "Argument '%s' to macro '%s' contains illegal characters. Only alphanumeric characters and '_' are allowed." % (arg, macro_name) + raise template.TemplateSyntaxError("Argument '%s' to macro '%s' contains illegal characters. Only alphanumeric characters and '_' are allowed." % (arg, macro_name)) nodelist = parser.parse(('endmacro', )) parser.delete_first_token() @@ -112,7 +111,7 @@ def do_loadmacros(parser, token): try: tag_name, filename = token.split_contents() except IndexError: - raise template.TemplateSyntaxError, "'%s' tag requires at least one argument (macro name)" % token.contents.split()[0] + raise template.TemplateSyntaxError("'%s' tag requires at least one argument (macro name)" % token.contents.split()[0]) if filename[0] in ('"', "'") and filename[-1] == filename[0]: filename = filename[1:-1] t = get_template(filename) @@ -141,20 +140,20 @@ def do_usemacro(parser, token): args = token.split_contents() tag_name, macro_name, values = args[0], args[1], args[2:] except IndexError: - raise template.TemplateSyntaxError, "'%s' tag requires at least one argument (macro name)" % token.contents.split()[0] + raise template.TemplateSyntaxError("'%s' tag requires at least one argument (macro name)" % token.contents.split()[0]) try: macro = parser._macros[macro_name] except (AttributeError, KeyError): - raise template.TemplateSyntaxError, "Macro '%s' is not defined" % macro_name + raise template.TemplateSyntaxError("Macro '%s' is not defined" % macro_name) if (len(values) != len(macro.args)): - raise template.TemplateSyntaxError, "Macro '%s' was declared with %d parameters and used with %d parameter" % ( + raise template.TemplateSyntaxError("Macro '%s' was declared with %d parameters and used with %d parameter" % ( macro_name, len(macro.args), - len(values)) + len(values))) filter_expressions = [] for val in values: if (val[0] == "'" or val[0] == '"') and (val[0] != val[-1]): - raise template.TemplateSyntaxError, "Non-terminated string argument: %s" % val[1:] + raise template.TemplateSyntaxError("Non-terminated string argument: %s" % val[1:]) filter_expressions.append(FilterExpression(val, parser)) return UseMacroNode(macro, filter_expressions) \ No newline at end of file