Compare commits
No commits in common. "2d8eb32e90e8807804418dd4532edf8072a60695" and "44f49e597483a34b9a8792841254505987260949" have entirely different histories.
2d8eb32e90
...
44f49e5974
|
@ -3,9 +3,7 @@
|
|||
## 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
|
||||
* listing sessions is much faster
|
||||
* session list: starting and ending sessions is much faster/doest not reload the page
|
||||
|
||||
## 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,17 +1,9 @@
|
|||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Callable
|
||||
|
||||
from django.db.models import (
|
||||
Avg,
|
||||
Count,
|
||||
ExpressionWrapper,
|
||||
F,
|
||||
Prefetch,
|
||||
Q,
|
||||
Sum,
|
||||
fields,
|
||||
)
|
||||
from django.db.models.functions import TruncDate
|
||||
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.http import (
|
||||
HttpRequest,
|
||||
HttpResponse,
|
||||
|
@ -285,40 +277,38 @@ 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 = all_sessions.filter(purchase=purchase_id)
|
||||
dataset = Session.objects.filter(purchase=purchase_id)
|
||||
context["purchase"] = Purchase.objects.get(id=purchase_id)
|
||||
elif filter == "platform":
|
||||
dataset = all_sessions.filter(purchase__platform=platform_id)
|
||||
dataset = Session.objects.filter(purchase__platform=platform_id)
|
||||
context["platform"] = Platform.objects.get(id=platform_id)
|
||||
elif filter == "edition":
|
||||
dataset = all_sessions.filter(purchase__edition=edition_id)
|
||||
dataset = Session.objects.filter(purchase__edition=edition_id)
|
||||
context["edition"] = Edition.objects.get(id=edition_id)
|
||||
elif filter == "game":
|
||||
dataset = all_sessions.filter(purchase__edition__game=game_id)
|
||||
dataset = Session.objects.filter(purchase__edition__game=game_id)
|
||||
context["game"] = Game.objects.get(id=game_id)
|
||||
elif filter == "ownership_type":
|
||||
dataset = all_sessions.filter(purchase__ownership_type=ownership_type)
|
||||
dataset = Session.objects.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 = all_sessions.filter(timestamp_start__gte=first_day_of_year).order_by(
|
||||
"-timestamp_start"
|
||||
)
|
||||
dataset = Session.objects.filter(
|
||||
timestamp_start__gte=first_day_of_year
|
||||
).order_by("-timestamp_start")
|
||||
context["title"] = "This year"
|
||||
else:
|
||||
dataset = all_sessions
|
||||
# by default, sort from newest to oldest
|
||||
dataset = Session.objects.order_by("-timestamp_start")
|
||||
|
||||
context = {
|
||||
"dataset": dataset,
|
||||
"dataset_count": dataset.count(),
|
||||
"last": Session.objects.prefetch_related("purchase__platform").latest(),
|
||||
}
|
||||
context["total_duration"] = dataset.total_duration_formatted()
|
||||
context["dataset"] = dataset
|
||||
try:
|
||||
context["last"] = Session.objects.latest()
|
||||
except ObjectDoesNotExist:
|
||||
context["last"] = None
|
||||
|
||||
return render(request, "list_sessions.html", context)
|
||||
|
||||
|
|
Loading…
Reference in New Issue