From 80b871d488278f57e4bfdccfe0feb7d11310810f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 28 Jul 2020 22:22:06 +0800 Subject: [PATCH] Added the retrieve_status() utility and applied it in the retrieve_status template tag in the Mia core application. --- mia_core/status.py | 14 ++++++++++++++ mia_core/templatetags/mia_core.py | 6 ++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mia_core/status.py b/mia_core/status.py index 5d7ff28..8477a93 100644 --- a/mia_core/status.py +++ b/mia_core/status.py @@ -61,6 +61,20 @@ def error_redirect(request, url, form, errors_by_field): 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): """Stores the status into the session, and returns the status ID that can be used to retrieve the status later with retrieve(). diff --git a/mia_core/templatetags/mia_core.py b/mia_core/templatetags/mia_core.py index 1055902..666d265 100644 --- a/mia_core/templatetags/mia_core.py +++ b/mia_core/templatetags/mia_core.py @@ -26,7 +26,7 @@ from django.urls import reverse from django.utils import timezone 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 register = template.Library() @@ -126,9 +126,7 @@ def retrieve_status_tag(context): Returns: str: An empty string. """ - if "s" not in context.request.GET: - return "" - status = _retrieve(context.request, context.request.GET["s"]) + status = retrieve_status(context.request) if status is None: return "" if "success" in status: