From 74ee42a68486a4cfbc12325e0bca338d7d356479 Mon Sep 17 00:00:00 2001 From: James Robinson <70377025+JamesPRobinson@users.noreply.github.com> Date: Tue, 21 Jan 2025 15:14:07 +0000 Subject: [PATCH] feat/add cookie selector function and condition in template --- .../dataworkspace/apps/datasets/views.py | 24 ++++++++++++++++++- .../templates/datasets/index.html | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dataworkspace/dataworkspace/apps/datasets/views.py b/dataworkspace/dataworkspace/apps/datasets/views.py index 944fa1b4e1..0f008fff3b 100644 --- a/dataworkspace/dataworkspace/apps/datasets/views.py +++ b/dataworkspace/dataworkspace/apps/datasets/views.py @@ -174,9 +174,31 @@ def _get_tags_as_dict(): return tags_dict +def show_survey_banner(request): + accepted = request.COOKIES.get("survey_accepted") + dismissed = request.COOKIES.get("suvery_dismissed") + # neither accepted nor dismissed + if all(s is None for s in [accepted, dismissed]): + return True + # dismissed and accepted could both be true so check accepted first + elif accepted is not None: + return False + elif dismissed is not None: + # config_notification = NotificationConfig.Objects.filter(campaign_id="survey") or simply NofiticationConfig.Objects.first() + date_expiry = datetime.strptime("2025/03/03", "%H/%m/%d") # config_notifaction.expiry_date + cookie_expiration = datetime.strptime( + request.COOKIES.get("survey_dismissed_expiration"), "%Y-%m-%dT%%H:%M:%S" + ) + # is is the last week? + days_left = (cookie_expiration - datetime.now()).days + if days_left <= 7: + return True + return False + + @csp_update(SCRIPT_SRC=settings.WEBPACK_SCRIPT_SRC) def home_view(request): - return render(request, "datasets/index.html") + return render(request, "datasets/index.html", {"show_survey": show_survey_banner(request)}) @csp_update(SCRIPT_SRC=settings.WEBPACK_SCRIPT_SRC) diff --git a/dataworkspace/dataworkspace/templates/datasets/index.html b/dataworkspace/dataworkspace/templates/datasets/index.html index e846f95826..1e161d73a7 100644 --- a/dataworkspace/dataworkspace/templates/datasets/index.html +++ b/dataworkspace/dataworkspace/templates/datasets/index.html @@ -38,7 +38,9 @@ ) {% endblock %} - +{% if show_survey %} + +{% endif %} {% block page_title %}Search - {{ block.super }}{% endblock %} {% block search_bar %}