Added the retrieve_status() utility and applied it in the retrieve_status template tag in the Mia core application.

This commit is contained in:
依瑪貓 2020-07-28 22:22:06 +08:00
parent 983f38d6f0
commit 80b871d488
2 changed files with 16 additions and 4 deletions

View File

@ -61,6 +61,20 @@ def error_redirect(request, url, form, errors_by_field):
return HttpResponseRedirect(str(UrlBuilder(url).add_param("s", id))) return HttpResponseRedirect(str(UrlBuilder(url).add_param("s", id)))
def retrieve_status(request):
"""Retrieves the previously-stored status.
Args:
request (HttpRequest): The request.
Returns:
dict: The previously-stored status.
"""
if "s" not in request.GET:
return None
return _retrieve(request, request.GET["s"])
def _store(request, status): def _store(request, status):
"""Stores the status into the session, and returns the status ID that can """Stores the status into the session, and returns the status ID that can
be used to retrieve the status later with retrieve(). be used to retrieve the status later with retrieve().

View File

@ -26,7 +26,7 @@ from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext from django.utils.translation import gettext
from mia_core.status import _retrieve from mia_core.status import _retrieve, retrieve_status
from mia_core.utils import UrlBuilder from mia_core.utils import UrlBuilder
register = template.Library() register = template.Library()
@ -126,9 +126,7 @@ def retrieve_status_tag(context):
Returns: Returns:
str: An empty string. str: An empty string.
""" """
if "s" not in context.request.GET: status = retrieve_status(context.request)
return ""
status = _retrieve(context.request, context.request.GET["s"])
if status is None: if status is None:
return "" return ""
if "success" in status: if "success" in status: