From f4127cf9b1cf74ac4cd17a3ae9905d9d567e558f Mon Sep 17 00:00:00 2001 From: CasperVerswijvelt Date: Thu, 6 May 2021 21:23:05 +0200 Subject: [PATCH] Preserve date range query parameters --- shynet/dashboard/mixins.py | 9 +++++++-- .../templates/dashboard/includes/service_overview.html | 2 +- .../templates/dashboard/includes/session_list.html | 2 +- shynet/dashboard/templates/dashboard/pages/service.html | 2 +- .../templates/dashboard/pages/service_session_list.html | 2 +- shynet/dashboard/templates/dashboard/service_base.html | 2 +- shynet/dashboard/templatetags/helpers.py | 4 ++++ 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/shynet/dashboard/mixins.py b/shynet/dashboard/mixins.py index ed374a1..6ec65ce 100644 --- a/shynet/dashboard/mixins.py +++ b/shynet/dashboard/mixins.py @@ -5,14 +5,16 @@ from django.utils import timezone class DateRangeMixin: - def get_start_date(self): + def get_start_date(self, use_default=True): if self.request.GET.get("startDate") != None: found_time = timezone.datetime.strptime( self.request.GET.get("startDate"), "%Y-%m-%d" ) return timezone.make_aware(datetime.combine(found_time, time.min)) - else: + elif use_default == True: return timezone.now() - timezone.timedelta(days=30) + else: + return None def get_end_date(self): if self.request.GET.get("endDate") != None: @@ -23,8 +25,11 @@ class DateRangeMixin: else: return timezone.now() + def get_context_data(self, **kwargs): data = super().get_context_data(**kwargs) data["start_date"] = self.get_start_date() data["end_date"] = self.get_end_date() + start_date = self.get_start_date(False) + data["date_query_params"] = f"?startDate={start_date.strftime('%Y-%m-%d')}&endDate={self.get_end_date().strftime('%Y-%m-%d')}" if start_date is not None else "" return data diff --git a/shynet/dashboard/templates/dashboard/includes/service_overview.html b/shynet/dashboard/templates/dashboard/includes/service_overview.html index 1996ddb..6024170 100644 --- a/shynet/dashboard/templates/dashboard/includes/service_overview.html +++ b/shynet/dashboard/templates/dashboard/includes/service_overview.html @@ -1,6 +1,6 @@ {% load humanize helpers %} - + {% with stats=object.stats %}
diff --git a/shynet/dashboard/templates/dashboard/includes/session_list.html b/shynet/dashboard/templates/dashboard/includes/session_list.html index a59d484..07aa33e 100644 --- a/shynet/dashboard/templates/dashboard/includes/session_list.html +++ b/shynet/dashboard/templates/dashboard/includes/session_list.html @@ -12,7 +12,7 @@ {% for session in object_list %} - {{session.start_time|date:"M j Y, g:i a"|capfirst}} {% if session.is_currently_active %} diff --git a/shynet/dashboard/templates/dashboard/pages/service.html b/shynet/dashboard/templates/dashboard/pages/service.html index 0005d64..8fa55c4 100644 --- a/shynet/dashboard/templates/dashboard/pages/service.html +++ b/shynet/dashboard/templates/dashboard/pages/service.html @@ -235,7 +235,7 @@ diff --git a/shynet/dashboard/templates/dashboard/pages/service_session_list.html b/shynet/dashboard/templates/dashboard/pages/service_session_list.html index 1218682..eee85e2 100644 --- a/shynet/dashboard/templates/dashboard/pages/service_session_list.html +++ b/shynet/dashboard/templates/dashboard/pages/service_session_list.html @@ -6,7 +6,7 @@ {% block service_actions %}
{% include 'dashboard/includes/date_range.html' %}
-Analytics → +Analytics → {% endblock %} {% block service_content %} diff --git a/shynet/dashboard/templates/dashboard/service_base.html b/shynet/dashboard/templates/dashboard/service_base.html index 3ce009d..54e0c99 100644 --- a/shynet/dashboard/templates/dashboard/service_base.html +++ b/shynet/dashboard/templates/dashboard/service_base.html @@ -6,7 +6,7 @@ {% block content %}