Compare commits
3 Commits
44f49e5974
...
2d8eb32e90
Author | SHA1 | Date |
---|---|---|
Lukáš Kucharczyk | 2d8eb32e90 | |
Lukáš Kucharczyk | 1f1ed79ee5 | |
Lukáš Kucharczyk | 01fd7bad69 |
|
@ -3,7 +3,9 @@
|
|||
## Improved
|
||||
* game overview: improve how editions and purchases are displayed
|
||||
* 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
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{{ title }}
|
||||
{% endblock title %}
|
||||
{% block content %}
|
||||
{% if dataset.count >= 1 %}
|
||||
{% if dataset_count >= 1 %}
|
||||
<div class="mx-auto text-center my-4">
|
||||
<a id="last-session-start"
|
||||
href="{% url 'start_session_same_as_last' last.id %}"
|
||||
|
@ -17,7 +17,7 @@
|
|||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if dataset.count != 0 %}
|
||||
{% if dataset_count != 0 %}
|
||||
<table class="responsive-table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from typing import Any, Callable
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Avg, Count, ExpressionWrapper, F, Prefetch, Q, Sum, fields
|
||||
from django.db.models.functions import Extract, TruncDate
|
||||
from django.db.models import (
|
||||
Avg,
|
||||
Count,
|
||||
ExpressionWrapper,
|
||||
F,
|
||||
Prefetch,
|
||||
Q,
|
||||
Sum,
|
||||
fields,
|
||||
)
|
||||
from django.db.models.functions import TruncDate
|
||||
from django.http import (
|
||||
HttpRequest,
|
||||
HttpResponse,
|
||||
|
@ -277,38 +285,40 @@ def list_sessions(
|
|||
context = {}
|
||||
context["title"] = "Sessions"
|
||||
|
||||
all_sessions = Session.objects.prefetch_related(
|
||||
"purchase", "purchase__edition", "purchase__edition__game"
|
||||
).order_by("-timestamp_start")
|
||||
|
||||
if filter == "purchase":
|
||||
dataset = Session.objects.filter(purchase=purchase_id)
|
||||
dataset = all_sessions.filter(purchase=purchase_id)
|
||||
context["purchase"] = Purchase.objects.get(id=purchase_id)
|
||||
elif filter == "platform":
|
||||
dataset = Session.objects.filter(purchase__platform=platform_id)
|
||||
dataset = all_sessions.filter(purchase__platform=platform_id)
|
||||
context["platform"] = Platform.objects.get(id=platform_id)
|
||||
elif filter == "edition":
|
||||
dataset = Session.objects.filter(purchase__edition=edition_id)
|
||||
dataset = all_sessions.filter(purchase__edition=edition_id)
|
||||
context["edition"] = Edition.objects.get(id=edition_id)
|
||||
elif filter == "game":
|
||||
dataset = Session.objects.filter(purchase__edition__game=game_id)
|
||||
dataset = all_sessions.filter(purchase__edition__game=game_id)
|
||||
context["game"] = Game.objects.get(id=game_id)
|
||||
elif filter == "ownership_type":
|
||||
dataset = Session.objects.filter(purchase__ownership_type=ownership_type)
|
||||
dataset = all_sessions.filter(purchase__ownership_type=ownership_type)
|
||||
context["ownership_type"] = dict(Purchase.OWNERSHIP_TYPES)[ownership_type]
|
||||
elif filter == "recent":
|
||||
current_year = timezone.now().year
|
||||
first_day_of_year = timezone.make_aware(datetime(current_year, 1, 1))
|
||||
dataset = Session.objects.filter(
|
||||
timestamp_start__gte=first_day_of_year
|
||||
).order_by("-timestamp_start")
|
||||
dataset = all_sessions.filter(timestamp_start__gte=first_day_of_year).order_by(
|
||||
"-timestamp_start"
|
||||
)
|
||||
context["title"] = "This year"
|
||||
else:
|
||||
# by default, sort from newest to oldest
|
||||
dataset = Session.objects.order_by("-timestamp_start")
|
||||
dataset = all_sessions
|
||||
|
||||
context["total_duration"] = dataset.total_duration_formatted()
|
||||
context["dataset"] = dataset
|
||||
try:
|
||||
context["last"] = Session.objects.latest()
|
||||
except ObjectDoesNotExist:
|
||||
context["last"] = None
|
||||
context = {
|
||||
"dataset": dataset,
|
||||
"dataset_count": dataset.count(),
|
||||
"last": Session.objects.prefetch_related("purchase__platform").latest(),
|
||||
}
|
||||
|
||||
return render(request, "list_sessions.html", context)
|
||||
|
||||
|
|
Loading…
Reference in New Issue