add icon field to platform, use everywhere
This commit is contained in:
@ -7,9 +7,14 @@ from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
|
||||
from common.components import A, Button, Icon
|
||||
from common.components import (
|
||||
A,
|
||||
Button,
|
||||
Icon,
|
||||
LinkedNameWithPlatformIcon,
|
||||
PopoverTruncated,
|
||||
)
|
||||
from common.time import dateformat, local_strftime
|
||||
from common.utils import truncate_with_popover
|
||||
from games.forms import EditionForm
|
||||
from games.models import Edition, Game
|
||||
|
||||
@ -42,7 +47,6 @@ def list_editions(request: HttpRequest) -> HttpResponse:
|
||||
"Game",
|
||||
"Name",
|
||||
"Sort Name",
|
||||
"Platform",
|
||||
"Year",
|
||||
"Wikidata",
|
||||
"Created",
|
||||
@ -50,30 +54,22 @@ def list_editions(request: HttpRequest) -> HttpResponse:
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
A(
|
||||
[
|
||||
(
|
||||
"href",
|
||||
reverse(
|
||||
"view_game",
|
||||
args=[edition.game.pk],
|
||||
),
|
||||
)
|
||||
],
|
||||
truncate_with_popover(edition.game.name),
|
||||
LinkedNameWithPlatformIcon(
|
||||
name=edition.name,
|
||||
game_id=edition.game.id,
|
||||
platform=edition.platform,
|
||||
),
|
||||
truncate_with_popover(
|
||||
PopoverTruncated(
|
||||
edition.name
|
||||
if edition.game.name != edition.name
|
||||
else "(identical)"
|
||||
),
|
||||
truncate_with_popover(
|
||||
PopoverTruncated(
|
||||
edition.sort_name
|
||||
if edition.sort_name is not None
|
||||
and edition.game.name != edition.sort_name
|
||||
else "(identical)"
|
||||
),
|
||||
truncate_with_popover(str(edition.platform)),
|
||||
edition.year_released,
|
||||
edition.wikidata,
|
||||
local_strftime(edition.created_at, dateformat),
|
||||
|
@ -8,7 +8,15 @@ from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
|
||||
from common.components import A, Button, Div, Icon, Popover
|
||||
from common.components import (
|
||||
A,
|
||||
Button,
|
||||
Div,
|
||||
Icon,
|
||||
NameWithPlatformIcon,
|
||||
Popover,
|
||||
PopoverTruncated,
|
||||
)
|
||||
from common.time import (
|
||||
dateformat,
|
||||
durationformat,
|
||||
@ -17,7 +25,7 @@ from common.time import (
|
||||
local_strftime,
|
||||
timeformat,
|
||||
)
|
||||
from common.utils import safe_division, truncate, truncate_with_popover
|
||||
from common.utils import safe_division, truncate
|
||||
from games.forms import GameForm
|
||||
from games.models import Edition, Game, Purchase, Session
|
||||
from games.views.general import use_custom_redirect
|
||||
@ -67,9 +75,9 @@ def list_games(request: HttpRequest) -> HttpResponse:
|
||||
),
|
||||
)
|
||||
],
|
||||
truncate_with_popover(game.name),
|
||||
PopoverTruncated(game.name),
|
||||
),
|
||||
truncate_with_popover(
|
||||
PopoverTruncated(
|
||||
game.sort_name
|
||||
if game.sort_name is not None and game.name != game.sort_name
|
||||
else "(identical)"
|
||||
@ -197,14 +205,15 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
edition_data: dict[str, Any] = {
|
||||
"columns": [
|
||||
"Name",
|
||||
"Platform",
|
||||
"Year Released",
|
||||
"Actions",
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
edition.name,
|
||||
Icon(str(edition.platform).lower().replace(".", "")),
|
||||
NameWithPlatformIcon(
|
||||
name=edition.name,
|
||||
platform=edition.platform,
|
||||
),
|
||||
edition.year_released,
|
||||
render_to_string(
|
||||
"cotton/button_group.html",
|
||||
@ -232,7 +241,10 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
"columns": ["Name", "Type", "Date", "Price", "Actions"],
|
||||
"rows": [
|
||||
[
|
||||
purchase.name if purchase.name else purchase.edition.name,
|
||||
NameWithPlatformIcon(
|
||||
name=purchase.name if purchase.name else purchase.edition.name,
|
||||
platform=purchase.platform,
|
||||
),
|
||||
purchase.get_type_display(),
|
||||
purchase.date_purchased.strftime(dateformat),
|
||||
f"{purchase.price} {purchase.price_currency}",
|
||||
@ -301,9 +313,15 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
|
||||
),
|
||||
],
|
||||
),
|
||||
"columns": ["Date", "Duration", "Actions"],
|
||||
"columns": ["Edition", "Date", "Duration", "Actions"],
|
||||
"rows": [
|
||||
[
|
||||
NameWithPlatformIcon(
|
||||
name=session.purchase.name
|
||||
if session.purchase.name
|
||||
else session.purchase.edition.name,
|
||||
platform=session.purchase.platform,
|
||||
),
|
||||
f"{local_strftime(session.timestamp_start)}{f" — {session.timestamp_end.strftime(timeformat)}" if session.timestamp_end else ""}",
|
||||
(
|
||||
format_duration(session.duration_calculated, durationformat)
|
||||
|
@ -40,6 +40,7 @@ def list_platforms(request: HttpRequest) -> HttpResponse:
|
||||
"header_action": A([], Button([], "Add platform"), url="add_platform"),
|
||||
"columns": [
|
||||
"Name",
|
||||
"Icon",
|
||||
"Group",
|
||||
"Created",
|
||||
"Actions",
|
||||
@ -47,6 +48,7 @@ def list_platforms(request: HttpRequest) -> HttpResponse:
|
||||
"rows": [
|
||||
[
|
||||
platform.name,
|
||||
Icon(platform.icon),
|
||||
platform.group,
|
||||
local_strftime(platform.created_at, dateformat),
|
||||
render_to_string(
|
||||
|
@ -13,9 +13,8 @@ from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from common.components import A, Button, Div, Icon
|
||||
from common.components import A, Button, Icon, LinkedNameWithPlatformIcon
|
||||
from common.time import dateformat
|
||||
from common.utils import truncate_with_popover
|
||||
from games.forms import PurchaseForm
|
||||
from games.models import Edition, Purchase
|
||||
from games.views.general import use_custom_redirect
|
||||
@ -60,35 +59,10 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
A(
|
||||
[
|
||||
(
|
||||
"href",
|
||||
reverse(
|
||||
"view_game",
|
||||
args=[purchase.edition.game.pk],
|
||||
),
|
||||
),
|
||||
],
|
||||
Div(
|
||||
attributes=[("class", "inline-flex gap-2 items-center")],
|
||||
children=[
|
||||
Icon(
|
||||
str(purchase.platform)
|
||||
.lower()
|
||||
.translate(
|
||||
str(purchase.platform)
|
||||
.lower()
|
||||
.maketrans("", "", ". /()")
|
||||
)
|
||||
),
|
||||
truncate_with_popover(
|
||||
purchase.edition.game.name
|
||||
if purchase.type == "game"
|
||||
else f"{purchase.edition.game.name} ({purchase.name})"
|
||||
),
|
||||
],
|
||||
),
|
||||
LinkedNameWithPlatformIcon(
|
||||
name=purchase.edition.name,
|
||||
game_id=purchase.edition.game.pk,
|
||||
platform=purchase.platform,
|
||||
),
|
||||
purchase.get_type_display(),
|
||||
purchase.price,
|
||||
|
@ -8,7 +8,7 @@ from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from common.components import A, Button, Div, Icon, Popover
|
||||
from common.components import A, Button, Div, Icon, LinkedNameWithPlatformIcon, Popover
|
||||
from common.time import (
|
||||
dateformat,
|
||||
durationformat,
|
||||
@ -17,7 +17,7 @@ from common.time import (
|
||||
local_strftime,
|
||||
timeformat,
|
||||
)
|
||||
from common.utils import truncate, truncate_with_popover
|
||||
from common.utils import truncate
|
||||
from games.forms import SessionForm
|
||||
from games.models import Purchase, Session
|
||||
from games.views.general import use_custom_redirect
|
||||
@ -91,12 +91,10 @@ def list_sessions(request: HttpRequest) -> HttpResponse:
|
||||
],
|
||||
"rows": [
|
||||
[
|
||||
A(
|
||||
children=truncate_with_popover(session.purchase.edition.name),
|
||||
url=reverse(
|
||||
"view_game",
|
||||
args=[session.purchase.edition.game.pk],
|
||||
),
|
||||
LinkedNameWithPlatformIcon(
|
||||
name=session.purchase.edition.name,
|
||||
game_id=session.purchase.edition.game.pk,
|
||||
platform=session.purchase.platform,
|
||||
),
|
||||
f"{local_strftime(session.timestamp_start)}{f" — {local_strftime(session.timestamp_end, timeformat)}" if session.timestamp_end else ""}",
|
||||
(
|
||||
@ -238,6 +236,14 @@ def end_session(
|
||||
return redirect("list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_session(request: HttpRequest, session_id: int = 0) -> HttpResponse:
|
||||
session = get_object_or_404(Session, id=session_id)
|
||||
session.delete()
|
||||
return redirect("list_sessions")
|
||||
return redirect("list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_session(request: HttpRequest, session_id: int = 0) -> HttpResponse:
|
||||
session = get_object_or_404(Session, id=session_id)
|
||||
|
Reference in New Issue
Block a user