-
+
⌚
Timetracker
diff --git a/games/templates/list_sessions.html b/games/templates/list_sessions.html
index 0d67637..c552511 100644
--- a/games/templates/list_sessions.html
+++ b/games/templates/list_sessions.html
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
-{% block title %}Sessions{% endblock title %}
+{% block title %}{{ title }}{% endblock title %}
{% block content %}
diff --git a/games/urls.py b/games/urls.py
index 88ddee0..6f1f785 100644
--- a/games/urls.py
+++ b/games/urls.py
@@ -3,7 +3,7 @@ from django.urls import path
from games import views
urlpatterns = [
- path("", views.index, name="index"),
+ path("", views.list_sessions, {"filter": "recent"}, name="list_sessions_recent"),
path("add-game/", views.add_game, name="add_game"),
path("add-platform/", views.add_platform, name="add_platform"),
path("add-session/", views.add_session, name="add_session"),
diff --git a/games/views.py b/games/views.py
index 0c272e0..4ed4a12 100644
--- a/games/views.py
+++ b/games/views.py
@@ -1,4 +1,4 @@
-from datetime import datetime
+from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
from common.plots import playtime_over_time_chart
@@ -73,6 +73,7 @@ def delete_session(request, session_id=None):
def list_sessions(request, filter="", purchase_id="", platform_id="", game_id=""):
context = {}
+ context["title"] = "Sessions"
if filter == "purchase":
dataset = Session.objects.filter(purchase=purchase_id)
@@ -83,6 +84,11 @@ def list_sessions(request, filter="", purchase_id="", platform_id="", game_id=""
elif filter == "game":
dataset = Session.objects.filter(purchase__game=game_id)
context["game"] = Game.objects.get(id=game_id)
+ elif filter == "recent":
+ dataset = Session.objects.filter(
+ timestamp_start__gte=datetime.now() - timedelta(days=30)
+ )
+ context["title"] = "Last 30 days"
else:
# by default, sort from newest to oldest
dataset = Session.objects.all().order_by("-timestamp_start")
@@ -139,10 +145,3 @@ def add_platform(request):
context["form"] = form
context["title"] = "Add New Platform"
return render(request, "add.html", context)
-
-
-def index(request):
- context = {}
- context["total_duration"] = Session().duration_sum
- context["title"] = "Index"
- return render(request, "index.html", context)
diff --git a/timetracker/urls.py b/timetracker/urls.py
index f056a77..834ef5b 100644
--- a/timetracker/urls.py
+++ b/timetracker/urls.py
@@ -73,8 +73,8 @@ router.register(r"sessions", SessionViewSet)
urlpatterns = [
- path("api/", include(router.urls)),
- path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
+ path("", RedirectView.as_view(url="/tracker")),
+ path("tracker/", include("games.urls")),
]
if settings.DEBUG: