From 498cd69328bf1b7a03727b750b5270fde316cf68 Mon Sep 17 00:00:00 2001 From: Lukas Kucharczyk Date: Sun, 11 Aug 2024 20:29:47 +0200 Subject: [PATCH] improve display of game names, durations --- games/gameviews.py | 9 +++++++-- games/purchaseviews.py | 4 ++-- games/sessionviews.py | 15 +++++++++++---- games/views.py | 4 +++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/games/gameviews.py b/games/gameviews.py index 3755f33..0f0284f 100644 --- a/games/gameviews.py +++ b/games/gameviews.py @@ -7,6 +7,7 @@ from django.shortcuts import render from django.template.loader import render_to_string from django.urls import reverse +from common.utils import truncate_with_popover from games.models import Game from games.views import dateformat @@ -44,8 +45,12 @@ def list_games(request: HttpRequest) -> HttpResponse: ], "rows": [ [ - game.name, - game.sort_name, + truncate_with_popover(game.name), + truncate_with_popover( + game.sort_name + if game.sort_name is not None and game.name != game.sort_name + else "(identical)" + ), game.year_released, game.wikidata, game.created_at.strftime(dateformat), diff --git a/games/purchaseviews.py b/games/purchaseviews.py index f073dd0..f516dee 100644 --- a/games/purchaseviews.py +++ b/games/purchaseviews.py @@ -2,12 +2,12 @@ from typing import Any from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator -from django.db.models.manager import BaseManager from django.http import HttpRequest, HttpResponse from django.shortcuts import render from django.template.loader import render_to_string from django.urls import reverse +from common.utils import truncate_with_popover from games.models import Purchase from games.views import dateformat @@ -50,7 +50,7 @@ def list_purchases(request: HttpRequest) -> HttpResponse: ], "rows": [ [ - purchase.edition.name, + truncate_with_popover(purchase.edition.name), purchase.platform, purchase.price, purchase.price_currency, diff --git a/games/sessionviews.py b/games/sessionviews.py index b86d97d..bce6359 100644 --- a/games/sessionviews.py +++ b/games/sessionviews.py @@ -8,8 +8,15 @@ from django.template.loader import render_to_string from django.urls import reverse from common.time import format_duration +from common.utils import truncate_with_popover from games.models import Session -from games.views import dateformat, datetimeformat, timeformat +from games.views import ( + dateformat, + datetimeformat, + durationformat, + durationformat_manual, + timeformat, +) @login_required @@ -46,15 +53,15 @@ def list_sessions(request: HttpRequest) -> HttpResponse: ], "rows": [ [ - session.purchase.edition.name, + truncate_with_popover(session.purchase.edition.name), f"{session.timestamp_start.strftime(datetimeformat)}{f" — {session.timestamp_end.strftime(timeformat)}" if session.timestamp_end else ""}", ( - format_duration(session.duration_calculated, "%2.1H hours") + format_duration(session.duration_calculated, durationformat) if session.duration_calculated else "-" ), ( - format_duration(session.duration_manual) + format_duration(session.duration_manual, durationformat_manual) if session.duration_manual else "-" ), diff --git a/games/views.py b/games/views.py index 15be907..8e98740 100644 --- a/games/views.py +++ b/games/views.py @@ -29,7 +29,9 @@ from .models import Edition, Game, Platform, Purchase, Session dateformat: str = "%d/%m/%Y" datetimeformat: str = "%d/%m/%Y %H:%M" -timeformat = "%H:%M" +timeformat: str = "%H:%M" +durationformat: str = "%2.1H hours" +durationformat_manual: str = "%H hours" def model_counts(request: HttpRequest) -> dict[str, bool]: