Compare commits

..

4 Commits

Author SHA1 Message Date
Lukáš Kucharczyk 44c70a5ee7
Formatting
Django CI/CD / test (push) Successful in 1m21s Details
Django CI/CD / build-and-push (push) Successful in 1m57s Details
2024-06-03 18:19:11 +02:00
Lukáš Kucharczyk cd804f2c77
Sort url paths 2024-06-03 18:18:58 +02:00
Lukáš Kucharczyk 15997bd5af
Re-enable delete session delete view 2024-06-03 18:07:10 +02:00
Lukáš Kucharczyk 880ea93424
Unify url path names 2024-06-03 18:05:34 +02:00
5 changed files with 60 additions and 56 deletions

View File

@ -8,6 +8,7 @@ def safe_division(numerator: int | float, denominator: int | float) -> int | flo
except ZeroDivisionError:
return 0
def safe_getattr(obj, attr_chain, default=None):
"""
Safely get the nested attribute from an object.
@ -20,7 +21,7 @@ def safe_getattr(obj, attr_chain, default=None):
Returns:
The value of the nested attribute if it exists, otherwise the default value.
"""
attrs = attr_chain.split('.')
attrs = attr_chain.split(".")
for attr in attrs:
try:
obj = getattr(obj, attr)

View File

@ -46,7 +46,7 @@ class EditionChoiceField(forms.ModelChoiceField):
class IncludePlatformSelect(forms.Select):
def create_option(self, name, value, *args, **kwargs):
option = super().create_option(name, value, *args, **kwargs)
if platform_id := safe_getattr(value, 'instance.platform.id'):
if platform_id := safe_getattr(value, "instance.platform.id"):
option["attrs"]["data-platform"] = platform_id
return option

View File

@ -4,32 +4,60 @@ from games import views
urlpatterns = [
path("", views.index, name="index"),
path("device/add", views.add_device, name="add_device"),
path("edition/add", views.add_edition, name="add_edition"),
path(
"list-sessions/recent",
views.list_sessions,
{"filter": "recent"},
name="list_sessions_recent",
"edition/add/for-game/<int:game_id>",
views.add_edition,
name="add_edition_for_game",
),
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"),
path("edition/<int:edition_id>/edit", views.edit_edition, name="edit_edition"),
path("game/add", views.add_game, name="add_game"),
path("game/<int:game_id>/edit", views.edit_game, name="edit_game"),
path("game/<int:game_id>/view", views.view_game, name="view_game"),
path("platform/add", views.add_platform, name="add_platform"),
path("platform/<int:platform_id>/edit", views.edit_platform, name="edit_platform"),
path("purchase/add", views.add_purchase, name="add_purchase"),
path("purchase/<int:purchase_id>/edit", views.edit_purchase, name="edit_purchase"),
path(
"add-session-for-purchase/<int:purchase_id>",
"purchase/<int:purchase_id>/delete",
views.delete_purchase,
name="delete_purchase",
),
path(
"purchase/related-purchase-by-edition",
views.related_purchase_by_edition,
name="related_purchase_by_edition",
),
path(
"purchase/add/for-edition/<int:edition_id>",
views.add_purchase,
name="add_purchase_for_edition",
),
path("session/add", views.add_session, name="add_session"),
path(
"session/add/for-purchase/<int:purchase_id>",
views.add_session,
name="add_session_for_purchase",
),
path(
"session/clone/from-game/<int:session_id>",
"session/add/from-game/<int:session_id>",
views.new_session_from_existing_session,
{"template": "view_game.html#session-info"},
name="view_game_start_session_from_session",
),
path(
"session/clone/from-list/<int:session_id>",
"session/add/from-list/<int:session_id>",
views.new_session_from_existing_session,
{"template": "list_sessions.html#session-row"},
name="list_sessions_start_session_from_session",
),
path("session/<int:session_id>/edit", views.edit_session, name="edit_session"),
path(
"session/<int:session_id>/delete",
views.delete_session,
name="delete_session",
),
path(
"session/end/from-game/<int:session_id>",
views.end_session,
@ -42,67 +70,39 @@ urlpatterns = [
{"template": "list_sessions.html#session-row"},
name="list_sessions_end_session",
),
# path(
# "delete_session/by-id/<int:session_id>",
# views.delete_session,
# name="delete_session",
# ),
path("session/list", views.list_sessions, name="list_sessions"),
path(
"purchase/<int:purchase_id>/delete",
views.delete_purchase,
name="delete_purchase",
),
path("add-purchase/", views.add_purchase, name="add_purchase"),
path(
"add-purchase-for-edition/<int:edition_id>",
views.add_purchase,
name="add_purchase_for_edition",
"session/list/recent",
views.list_sessions,
{"filter": "recent"},
name="list_sessions_recent",
),
path(
"related-purchase-by-edition",
views.related_purchase_by_edition,
name="related_purchase_by_edition",
),
path("add-edition/", views.add_edition, name="add_edition"),
path(
"add-edition-for-game/<int:game_id>",
views.add_edition,
name="add_edition_for_game",
),
path("edit-edition/<int:edition_id>", views.edit_edition, name="edit_edition"),
path("game/<int:game_id>/view", views.view_game, name="view_game"),
path("game/<int:game_id>/edit", views.edit_game, name="edit_game"),
path("edit-platform/<int:platform_id>", views.edit_platform, name="edit_platform"),
path("add-device/", views.add_device, name="add_device"),
path("edit-session/<int:session_id>", views.edit_session, name="edit_session"),
path("edit-purchase/<int:purchase_id>", views.edit_purchase, name="edit_purchase"),
path("list-sessions/", views.list_sessions, name="list_sessions"),
path(
"list-sessions/by-purchase/<int:purchase_id>",
"session/list/by-purchase/<int:purchase_id>",
views.list_sessions,
{"filter": "purchase"},
name="list_sessions_by_purchase",
),
path(
"list-sessions/by-platform/<int:platform_id>",
"session/list/by-platform/<int:platform_id>",
views.list_sessions,
{"filter": "platform"},
name="list_sessions_by_platform",
),
path(
"list-sessions/by-game/<int:game_id>",
"session/list/by-game/<int:game_id>",
views.list_sessions,
{"filter": "game"},
name="list_sessions_by_game",
),
path(
"list-sessions/by-edition/<int:edition_id>",
"session/list/by-edition/<int:edition_id>",
views.list_sessions,
{"filter": "edition"},
name="list_sessions_by_edition",
),
path(
"list-sessions/by-ownership/<str:ownership_type>",
"session/list/by-ownership/<str:ownership_type>",
views.list_sessions,
{"filter": "ownership_type"},
name="list_sessions_by_ownership_type",

View File

@ -284,10 +284,11 @@ def end_session(request, session_id: int, template: str = ""):
return redirect("list_sessions")
# def delete_session(request, session_id=None):
# session = Session.objects.get(id=session_id)
# session.delete()
# return redirect("list_sessions")
@login_required
def delete_session(request, session_id=None):
session = get_object_or_404(Session, id=session_id)
session.delete()
return redirect("list_sessions")
@login_required
@ -591,12 +592,14 @@ def stats(request, year: int = 0):
request.session["return_path"] = request.path
return render(request, "stats.html", context)
@login_required
def delete_purchase(request, purchase_id=None):
purchase = get_object_or_404(Purchase, id=purchase_id)
purchase.delete()
return redirect("list_sessions")
@login_required
def add_purchase(request, edition_id=None):
context = {}

View File

@ -23,10 +23,10 @@ from graphene_django.views import GraphQLView
urlpatterns = [
path("", RedirectView.as_view(url="/tracker")),
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),
path("login/", auth_views.LoginView.as_view(), name="login"),
path("logout/", auth_views.LogoutView.as_view(), name="logout"),
path("tracker/", include("games.urls")),
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),
]
if settings.DEBUG: