Preserve date range query parameters
This commit is contained in:
parent
03f88af03c
commit
023e0fde15
@ -5,14 +5,16 @@ from django.utils import timezone
|
|||||||
|
|
||||||
|
|
||||||
class DateRangeMixin:
|
class DateRangeMixin:
|
||||||
def get_start_date(self):
|
def get_start_date(self, use_default=True):
|
||||||
if self.request.GET.get("startDate") != None:
|
if self.request.GET.get("startDate") != None:
|
||||||
found_time = timezone.datetime.strptime(
|
found_time = timezone.datetime.strptime(
|
||||||
self.request.GET.get("startDate"), "%Y-%m-%d"
|
self.request.GET.get("startDate"), "%Y-%m-%d"
|
||||||
)
|
)
|
||||||
return timezone.make_aware(datetime.combine(found_time, time.min))
|
return timezone.make_aware(datetime.combine(found_time, time.min))
|
||||||
else:
|
elif use_default == True:
|
||||||
return timezone.now() - timezone.timedelta(days=30)
|
return timezone.now() - timezone.timedelta(days=30)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_end_date(self):
|
def get_end_date(self):
|
||||||
if self.request.GET.get("endDate") != None:
|
if self.request.GET.get("endDate") != None:
|
||||||
@ -23,8 +25,11 @@ class DateRangeMixin:
|
|||||||
else:
|
else:
|
||||||
return timezone.now()
|
return timezone.now()
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
data = super().get_context_data(**kwargs)
|
data = super().get_context_data(**kwargs)
|
||||||
data["start_date"] = self.get_start_date()
|
data["start_date"] = self.get_start_date()
|
||||||
data["end_date"] = self.get_end_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
|
return data
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{% load humanize helpers %}
|
{% 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 %}
|
{% with stats=object.stats %}
|
||||||
<div class="p-4 md:flex justify-between">
|
<div class="p-4 md:flex justify-between">
|
||||||
<div class="flex items-center mb-4 md:mb-0">
|
<div class="flex items-center mb-4 md:mb-0">
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
{% for session in object_list %}
|
{% for session in object_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<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">
|
class="font-medium text-urge-700">
|
||||||
{{session.start_time|date:"M j Y, g:i a"|capfirst}}
|
{{session.start_time|date:"M j Y, g:i a"|capfirst}}
|
||||||
{% if session.is_currently_active %}
|
{% if session.is_currently_active %}
|
||||||
|
@ -235,7 +235,7 @@
|
|||||||
<div class="card ~neutral !low limited-height py-2">
|
<div class="card ~neutral !low limited-height py-2">
|
||||||
{% include 'dashboard/includes/session_list.html' %}
|
{% include 'dashboard/includes/session_list.html' %}
|
||||||
<hr class="sep h-8">
|
<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
|
sessions
|
||||||
→</a>
|
→</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
{% block service_actions %}
|
{% block service_actions %}
|
||||||
<div class="mr-2">{% include 'dashboard/includes/date_range.html' %}</div>
|
<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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block service_content %}
|
{% block service_content %}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="md:flex justify-between items-center" id="heading">
|
<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">
|
<h3 class="heading leading-none mr-4">
|
||||||
{{object.link|iconify}}
|
{{object.link|iconify}}
|
||||||
{{object.name}}
|
{{object.name}}
|
||||||
|
@ -184,3 +184,7 @@ def urldisplay(url):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def add_string(arg1, arg2):
|
||||||
|
return f"{str(arg1)}{str(arg2)}"
|
||||||
|
Loading…
Reference in New Issue
Block a user