Reordered the code in the template tags in the Mia core application.

This commit is contained in:
依瑪貓 2020-07-27 21:23:40 +08:00
parent c8eb31ce82
commit cc18dbd5f1

View File

@ -80,6 +80,39 @@ def url_period(context, period_spec):
return reverse(view_name, kwargs=kwargs) return reverse(view_name, kwargs=kwargs)
@register.simple_tag(takes_context=True)
def url_with_return(context, view_name, *args):
"""Returns the transaction URL.
Args:
context (RequestContext): The request context.
view_name (str): The view name.
*args (tuple[any]): The URL arguments.
Returns:
str: The URL.
"""
url = reverse(view_name, args=args)
return_to = context.request.get_full_path()
return str(UrlBuilder(url).set_param("r", return_to))
@register.simple_tag(takes_context=True)
def url_keep_return(context, view_name, *args):
"""Returns the transaction URL.
Args:
context (RequestContext): The request context.
view_name (str): The view name.
*args (tuple[any]): The URL arguments.
Returns:
str: The URL.
"""
url = reverse(view_name, args=args)
return str(UrlBuilder(url).set_param("r", context.request.GET.get("r")))
@register.filter @register.filter
def smart_date(value): def smart_date(value):
"""Formats the date for human friendliness. """Formats the date for human friendliness.
@ -120,36 +153,3 @@ def smart_month(value):
if value.year == year and value.month == month: if value.year == year and value.month == month:
return gettext("Last Month") return gettext("Last Month")
return defaultfilters.date(value, "Y/n") return defaultfilters.date(value, "Y/n")
@register.simple_tag(takes_context=True)
def url_with_return(context, view_name, *args):
"""Returns the transaction URL.
Args:
context (RequestContext): The request context.
view_name (str): The view name.
*args (tuple[any]): The URL arguments.
Returns:
str: The URL.
"""
url = reverse(view_name, args=args)
return_to = context.request.get_full_path()
return str(UrlBuilder(url).set_param("r", return_to))
@register.simple_tag(takes_context=True)
def url_keep_return(context, view_name, *args):
"""Returns the transaction URL.
Args:
context (RequestContext): The request context.
view_name (str): The view name.
*args (tuple[any]): The URL arguments.
Returns:
str: The URL.
"""
url = reverse(view_name, args=args)
return str(UrlBuilder(url).set_param("r", context.request.GET.get("r")))