Optimize session listing
This commit is contained in:
parent
01fd7bad69
commit
1f1ed79ee5
|
@ -3,7 +3,9 @@
|
||||||
## Improved
|
## Improved
|
||||||
* game overview: improve how editions and purchases are displayed
|
* game overview: improve how editions and purchases are displayed
|
||||||
* add purchase: only allow choosing purchases of selected edition
|
* add purchase: only allow choosing purchases of selected edition
|
||||||
* session list: starting and ending sessions is much faster/doest not reload the page
|
* session list:
|
||||||
|
* starting and ending sessions is much faster/doest not reload the page
|
||||||
|
* listing sessions is much faster
|
||||||
|
|
||||||
## 1.5.1 / 2023-11-14 21:10+01:00
|
## 1.5.1 / 2023-11-14 21:10+01:00
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
{{ title }}
|
{{ title }}
|
||||||
{% endblock title %}
|
{% endblock title %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if dataset.count >= 1 %}
|
{% if dataset_count >= 1 %}
|
||||||
<div class="mx-auto text-center my-4">
|
<div class="mx-auto text-center my-4">
|
||||||
<a id="last-session-start"
|
<a id="last-session-start"
|
||||||
href="{% url 'start_session_same_as_last' last.id %}"
|
href="{% url 'start_session_same_as_last' last.id %}"
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if dataset.count != 0 %}
|
{% if dataset_count != 0 %}
|
||||||
<table class="responsive-table">
|
<table class="responsive-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -277,35 +277,39 @@ def list_sessions(
|
||||||
context = {}
|
context = {}
|
||||||
context["title"] = "Sessions"
|
context["title"] = "Sessions"
|
||||||
|
|
||||||
|
dataset = Session.objects.prefetch_related(
|
||||||
|
"purchase", "purchase__edition", "purchase__edition__game"
|
||||||
|
).order_by("-timestamp_start")
|
||||||
|
|
||||||
if filter == "purchase":
|
if filter == "purchase":
|
||||||
dataset = Session.objects.filter(purchase=purchase_id)
|
dataset = dataset.filter(purchase=purchase_id)
|
||||||
context["purchase"] = Purchase.objects.get(id=purchase_id)
|
context["purchase"] = Purchase.objects.get(id=purchase_id)
|
||||||
elif filter == "platform":
|
elif filter == "platform":
|
||||||
dataset = Session.objects.filter(purchase__platform=platform_id)
|
dataset = dataset.filter(purchase__platform=platform_id)
|
||||||
context["platform"] = Platform.objects.get(id=platform_id)
|
context["platform"] = Platform.objects.get(id=platform_id)
|
||||||
elif filter == "edition":
|
elif filter == "edition":
|
||||||
dataset = Session.objects.filter(purchase__edition=edition_id)
|
dataset = dataset.filter(purchase__edition=edition_id)
|
||||||
context["edition"] = Edition.objects.get(id=edition_id)
|
context["edition"] = Edition.objects.get(id=edition_id)
|
||||||
elif filter == "game":
|
elif filter == "game":
|
||||||
dataset = Session.objects.filter(purchase__edition__game=game_id)
|
dataset = dataset.filter(purchase__edition__game=game_id)
|
||||||
context["game"] = Game.objects.get(id=game_id)
|
context["game"] = Game.objects.get(id=game_id)
|
||||||
elif filter == "ownership_type":
|
elif filter == "ownership_type":
|
||||||
dataset = Session.objects.filter(purchase__ownership_type=ownership_type)
|
dataset = dataset.filter(purchase__ownership_type=ownership_type)
|
||||||
context["ownership_type"] = dict(Purchase.OWNERSHIP_TYPES)[ownership_type]
|
context["ownership_type"] = dict(Purchase.OWNERSHIP_TYPES)[ownership_type]
|
||||||
elif filter == "recent":
|
elif filter == "recent":
|
||||||
current_year = timezone.now().year
|
current_year = timezone.now().year
|
||||||
first_day_of_year = timezone.make_aware(datetime(current_year, 1, 1))
|
first_day_of_year = timezone.make_aware(datetime(current_year, 1, 1))
|
||||||
dataset = Session.objects.filter(
|
dataset = dataset.filter(timestamp_start__gte=first_day_of_year).order_by(
|
||||||
timestamp_start__gte=first_day_of_year
|
"-timestamp_start"
|
||||||
).order_by("-timestamp_start")
|
)
|
||||||
context["title"] = "This year"
|
context["title"] = "This year"
|
||||||
else:
|
|
||||||
# by default, sort from newest to oldest
|
|
||||||
dataset = Session.objects.order_by("-timestamp_start")
|
|
||||||
|
|
||||||
context["dataset"] = dataset
|
context["dataset"] = dataset
|
||||||
|
context["dataset_count"] = dataset.count()
|
||||||
try:
|
try:
|
||||||
context["last"] = Session.objects.latest()
|
context["last"] = Session.objects.prefetch_related(
|
||||||
|
"purchase__platform"
|
||||||
|
).latest()
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
context["last"] = None
|
context["last"] = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue