Revised the url_period() tag in the Mia core application.

This commit is contained in:
依瑪貓 2020-07-23 22:19:27 +08:00
parent 25383a3ae6
commit 334292e6e8

View File

@ -63,11 +63,19 @@ def str_format(format_str, *args):
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def url_period(context, period_spec): 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" % ( view_name = "%s:%s" % (
request.resolver_match.app_name, context.request.resolver_match.app_name,
request.resolver_match.url_name) context.request.resolver_match.url_name)
kwargs = request.resolver_match.kwargs kwargs = context.request.resolver_match.kwargs
kwargs["period"] = period_spec kwargs["period"] = period_spec
return reverse(view_name, kwargs=kwargs) return reverse(view_name, kwargs=kwargs)