From 6bdcdd0d780081c0d6ed92714ffebb4d4b2acdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 9 Jul 2020 01:29:51 +0800 Subject: [PATCH] Renamed the format template tag to str_format, and simplify it. --- accounting/templates/accounting/cash.html | 5 ++++- mia_core/templatetags.py | 13 ++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/accounting/templates/accounting/cash.html b/accounting/templates/accounting/cash.html index e479566..c391d70 100644 --- a/accounting/templates/accounting/cash.html +++ b/accounting/templates/accounting/cash.html @@ -25,12 +25,15 @@ First written: 2020/7/1 {% block settings %} {% trans "Cash Account for {} in {}" context "Accounting|" as title_format %} - {% format title_format subject.title_zhtw period.description as title %} + {% str_format title_format subject.title_zhtw period.description as title %} {% setvar "title" title %} {% endblock %} {% block content %} + {% trans "Cash Account for {} in {}" context "Accounting|" as title_format %} + {% str_format title_format subject.title_zhtw period.description as title_format %} +

{{ title_format }}

{{ request.resolver_match.url_name }}

{{ request.resolver_match.app_name }}

diff --git a/mia_core/templatetags.py b/mia_core/templatetags.py index 7f39b5b..75d5f41 100644 --- a/mia_core/templatetags.py +++ b/mia_core/templatetags.py @@ -36,17 +36,12 @@ def setvar(context, key, value): return "" -@register.simple_tag(takes_context=True) -def format(context, format, *args, **kwargs): +@register.simple_tag +def str_format(format_str, *args): """Sets a variable in the template. Args: - context (Context): the context. - format (str): The format. + format_str (str): The format. args (str): The parameters. - kwargs (str): The keyword arguments. """ - if "as" in kwargs: - context.dicts[0][kwargs["as"]] = format.format(*args) - return "" - return format.format(*args) + return format_str.format(*args)