Preserve date range query parameters
This commit is contained in:
parent
159015de1c
commit
f4127cf9b1
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% load humanize helpers %}
|
||||
|
||||
<a class="card ~neutral !low service mb-6 p-0" href="{% url 'dashboard:service' object.uuid %}">
|
||||
<a class="card ~neutral !low service mb-6 p-0" href="{% url 'dashboard:service' object.uuid %}{{date_query_params}}">
|
||||
{% with stats=object.stats %}
|
||||
<div class="p-4 md:flex justify-between">
|
||||
<div class="flex items-center mb-4 md:mb-0">
|
||||
|
@ -12,7 +12,7 @@
|
||||
{% for session in object_list %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'dashboard:service_session' object.pk session.pk %}"
|
||||
<a href="{% url 'dashboard:service_session' object.pk session.pk %}{{date_query_params}}"
|
||||
class="font-medium text-urge-700">
|
||||
{{session.start_time|date:"M j Y, g:i a"|capfirst}}
|
||||
{% if session.is_currently_active %}
|
||||
|
@ -235,7 +235,7 @@
|
||||
<div class="card ~neutral !low limited-height py-2">
|
||||
{% include 'dashboard/includes/session_list.html' %}
|
||||
<hr class="sep h-8">
|
||||
<a href="{% url 'dashboard:service_session_list' service.uuid %}" class="button ~neutral w-auto mb-2">View more
|
||||
<a href="{% url 'dashboard:service_session_list' service.uuid %}{{date_query_params}}" class="button ~neutral w-auto mb-2">View more
|
||||
sessions
|
||||
→</a>
|
||||
</div>
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
{% block service_actions %}
|
||||
<div class="mr-2">{% include 'dashboard/includes/date_range.html' %}</div>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button field ~neutral bg-neutral-000 w-auto">Analytics →</a>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}{{date_query_params}}" class="button field ~neutral bg-neutral-000 w-auto">Analytics →</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block service_content %}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="md:flex justify-between items-center" id="heading">
|
||||
<a class="flex items-center mb-4 md:mb-0" href="{% url 'dashboard:service' object.uuid %}">
|
||||
<a class="flex items-center mb-4 md:mb-0" href="{% url 'dashboard:service' object.uuid %}{{date_query_params}}">
|
||||
<h3 class="heading leading-none mr-4">
|
||||
{{object.link|iconify}}
|
||||
{{object.name}}
|
||||
|
@ -184,3 +184,7 @@ def urldisplay(url):
|
||||
)
|
||||
else:
|
||||
return url
|
||||
|
||||
@register.filter
|
||||
def add_string(arg1, arg2):
|
||||
return f"{str(arg1)}{str(arg2)}"
|
||||
|
Loading…
Reference in New Issue
Block a user