Compare commits
No commits in common. "44c70a5ee7c53e51ec0d1c6e4de5b674337aeb39" and "dc1a9d5c4f5af189a442edb1808ebf772131167c" have entirely different histories.
44c70a5ee7
...
dc1a9d5c4f
|
@ -8,7 +8,6 @@ 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.
|
||||
|
@ -21,7 +20,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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -4,60 +4,32 @@ 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(
|
||||
"edition/add/for-game/<int:game_id>",
|
||||
views.add_edition,
|
||||
name="add_edition_for_game",
|
||||
"list-sessions/recent",
|
||||
views.list_sessions,
|
||||
{"filter": "recent"},
|
||||
name="list_sessions_recent",
|
||||
),
|
||||
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-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(
|
||||
"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>",
|
||||
"add-session-for-purchase/<int:purchase_id>",
|
||||
views.add_session,
|
||||
name="add_session_for_purchase",
|
||||
),
|
||||
path(
|
||||
"session/add/from-game/<int:session_id>",
|
||||
"session/clone/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/add/from-list/<int:session_id>",
|
||||
"session/clone/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,
|
||||
|
@ -70,39 +42,67 @@ urlpatterns = [
|
|||
{"template": "list_sessions.html#session-row"},
|
||||
name="list_sessions_end_session",
|
||||
),
|
||||
path("session/list", views.list_sessions, name="list_sessions"),
|
||||
# path(
|
||||
# "delete_session/by-id/<int:session_id>",
|
||||
# views.delete_session,
|
||||
# name="delete_session",
|
||||
# ),
|
||||
path(
|
||||
"session/list/recent",
|
||||
views.list_sessions,
|
||||
{"filter": "recent"},
|
||||
name="list_sessions_recent",
|
||||
"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",
|
||||
),
|
||||
path(
|
||||
"session/list/by-purchase/<int:purchase_id>",
|
||||
"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>",
|
||||
views.list_sessions,
|
||||
{"filter": "purchase"},
|
||||
name="list_sessions_by_purchase",
|
||||
),
|
||||
path(
|
||||
"session/list/by-platform/<int:platform_id>",
|
||||
"list-sessions/by-platform/<int:platform_id>",
|
||||
views.list_sessions,
|
||||
{"filter": "platform"},
|
||||
name="list_sessions_by_platform",
|
||||
),
|
||||
path(
|
||||
"session/list/by-game/<int:game_id>",
|
||||
"list-sessions/by-game/<int:game_id>",
|
||||
views.list_sessions,
|
||||
{"filter": "game"},
|
||||
name="list_sessions_by_game",
|
||||
),
|
||||
path(
|
||||
"session/list/by-edition/<int:edition_id>",
|
||||
"list-sessions/by-edition/<int:edition_id>",
|
||||
views.list_sessions,
|
||||
{"filter": "edition"},
|
||||
name="list_sessions_by_edition",
|
||||
),
|
||||
path(
|
||||
"session/list/by-ownership/<str:ownership_type>",
|
||||
"list-sessions/by-ownership/<str:ownership_type>",
|
||||
views.list_sessions,
|
||||
{"filter": "ownership_type"},
|
||||
name="list_sessions_by_ownership_type",
|
||||
|
|
|
@ -284,11 +284,10 @@ def end_session(request, session_id: int, template: str = ""):
|
|||
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")
|
||||
# def delete_session(request, session_id=None):
|
||||
# session = Session.objects.get(id=session_id)
|
||||
# session.delete()
|
||||
# return redirect("list_sessions")
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -592,14 +591,12 @@ 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 = {}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue