From 44c70a5ee7c53e51ec0d1c6e4de5b674337aeb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 3 Jun 2024 18:19:11 +0200 Subject: [PATCH] Formatting --- common/utils.py | 5 +++-- games/forms.py | 2 +- games/views.py | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/utils.py b/common/utils.py index f837ec0..ed82eb6 100644 --- a/common/utils.py +++ b/common/utils.py @@ -7,7 +7,8 @@ def safe_division(numerator: int | float, denominator: int | float) -> int | flo return numerator / denominator 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) diff --git a/games/forms.py b/games/forms.py index 6ad8b19..1104d54 100644 --- a/games/forms.py +++ b/games/forms.py @@ -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 diff --git a/games/views.py b/games/views.py index 192beab..8a3250c 100644 --- a/games/views.py +++ b/games/views.py @@ -283,6 +283,7 @@ def end_session(request, session_id: int, template: str = ""): return render(request, template, context) return redirect("list_sessions") + @login_required def delete_session(request, session_id=None): session = get_object_or_404(Session, id=session_id) @@ -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 = {}