Compare commits

...

2 Commits

Author SHA1 Message Date
Lukáš Kucharczyk 4552cf7616 Version 1.3.0
continuous-integration/drone/push Build is passing Details
2023-11-05 15:10:56 +01:00
Lukáš Kucharczyk a614b51d29 Make some pages redirect back instead to session list 2023-11-05 15:09:51 +01:00
4 changed files with 35 additions and 6 deletions

View File

@ -1,9 +1,12 @@
## Unreleased
## 1.3.0 / 2023-11-05 15:09+01:00
### New
* Add Stats to the main navigation
* Allow selecting year on the Stats page
### Improved
* Make some pages redirect back instead to session list
### Improved
* Make navigation more compact

View File

@ -6,7 +6,7 @@ RUN npm install && \
FROM python:3.10.9-slim-bullseye
ENV VERSION_NUMBER 1.2.0
ENV VERSION_NUMBER 1.3.0
ENV PROD 1
ENV PYTHONUNBUFFERED=1

View File

@ -1,11 +1,11 @@
from common.time import format_duration
from common.time import now as now_with_tz
from common.time import format_duration, now as now_with_tz
from datetime import datetime, timedelta
from django.conf import settings
from django.db.models import Sum, F
from django.http import HttpResponseRedirect
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect, render
from django.urls import reverse
from typing import Callable, Any
from zoneinfo import ZoneInfo
from .forms import (
@ -61,6 +61,25 @@ def update_session(request, session_id=None):
return redirect("list_sessions")
def use_custom_redirect(
func: Callable[..., HttpResponse]
) -> Callable[..., HttpResponse]:
"""
Will redirect to "return_path" session variable if set.
"""
def wrapper(request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
response = func(request, *args, **kwargs)
if isinstance(response, HttpResponseRedirect) and (
next_url := request.session.get("return_path")
):
return HttpResponseRedirect(next_url)
return response
return wrapper
@use_custom_redirect
def edit_session(request, session_id=None):
context = {}
session = Session.objects.get(id=session_id)
@ -73,6 +92,7 @@ def edit_session(request, session_id=None):
return render(request, "add_session.html", context)
@use_custom_redirect
def edit_purchase(request, purchase_id=None):
context = {}
purchase = Purchase.objects.get(id=purchase_id)
@ -85,6 +105,7 @@ def edit_purchase(request, purchase_id=None):
return render(request, "add.html", context)
@use_custom_redirect
def edit_game(request, game_id=None):
context = {}
purchase = Game.objects.get(id=game_id)
@ -119,9 +140,11 @@ def view_game(request, game_id=None):
context["last_session"] = context["sessions"].first()
context["first_session"] = context["sessions"].last()
context["sessions_with_notes"] = context["sessions"].exclude(note="")
request.session["return_path"] = request.path
return render(request, "view_game.html", context)
@use_custom_redirect
def edit_platform(request, platform_id=None):
context = {}
purchase = Platform.objects.get(id=platform_id)
@ -134,6 +157,7 @@ def edit_platform(request, platform_id=None):
return render(request, "add.html", context)
@use_custom_redirect
def edit_edition(request, edition_id=None):
context = {}
edition = Edition.objects.get(id=edition_id)
@ -146,6 +170,7 @@ def edit_edition(request, edition_id=None):
return render(request, "add.html", context)
@use_custom_redirect
def start_game_session(request, game_id: int):
last_session = (
Session.objects.filter(purchase__edition__game_id=game_id)
@ -300,6 +325,7 @@ def stats(request, year: int = 0):
"spent_per_game": int(total_spent / all_purchased_this_year.count()),
}
request.session["return_path"] = request.path
return render(request, "stats.html", context)

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "timetracker"
version = "1.2.0"
version = "1.3.0"
description = "A simple time tracker."
authors = ["Lukáš Kucharczyk <lukas@kucharczyk.xyz>"]
license = "GPL"