From 334292e6e880fd4e2644ea870d15850ebaff6a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 23 Jul 2020 22:19:27 +0800 Subject: [PATCH] Revised the url_period() tag in the Mia core application. --- mia_core/templatetags/mia_core.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mia_core/templatetags/mia_core.py b/mia_core/templatetags/mia_core.py index 511a807..d47269f 100644 --- a/mia_core/templatetags/mia_core.py +++ b/mia_core/templatetags/mia_core.py @@ -63,11 +63,19 @@ def str_format(format_str, *args): @register.simple_tag(takes_context=True) def url_period(context, period_spec): - request = context["request"] + """Returns the current URL with a new period. + + Args: + context (RequestContext): The request context. + period_spec (str): The period specification. + + Returns: + str: The current URL with the new period. + """ view_name = "%s:%s" % ( - request.resolver_match.app_name, - request.resolver_match.url_name) - kwargs = request.resolver_match.kwargs + context.request.resolver_match.app_name, + context.request.resolver_match.url_name) + kwargs = context.request.resolver_match.kwargs kwargs["period"] = period_spec return reverse(view_name, kwargs=kwargs)