Formatting
Django CI/CD / test (push) Successful in 1m21s Details
Django CI/CD / build-and-push (push) Successful in 1m57s Details

This commit is contained in:
Lukáš Kucharczyk 2024-06-03 18:19:11 +02:00
parent cd804f2c77
commit 44c70a5ee7
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
3 changed files with 7 additions and 3 deletions

View File

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

View File

@ -46,7 +46,7 @@ class EditionChoiceField(forms.ModelChoiceField):
class IncludePlatformSelect(forms.Select): class IncludePlatformSelect(forms.Select):
def create_option(self, name, value, *args, **kwargs): def create_option(self, name, value, *args, **kwargs):
option = super().create_option(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 option["attrs"]["data-platform"] = platform_id
return option return option

View File

@ -283,6 +283,7 @@ def end_session(request, session_id: int, template: str = ""):
return render(request, template, context) return render(request, template, context)
return redirect("list_sessions") return redirect("list_sessions")
@login_required @login_required
def delete_session(request, session_id=None): def delete_session(request, session_id=None):
session = get_object_or_404(Session, id=session_id) 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 request.session["return_path"] = request.path
return render(request, "stats.html", context) return render(request, "stats.html", context)
@login_required @login_required
def delete_purchase(request, purchase_id=None): def delete_purchase(request, purchase_id=None):
purchase = get_object_or_404(Purchase, id=purchase_id) purchase = get_object_or_404(Purchase, id=purchase_id)
purchase.delete() purchase.delete()
return redirect("list_sessions") return redirect("list_sessions")
@login_required @login_required
def add_purchase(request, edition_id=None): def add_purchase(request, edition_id=None):
context = {} context = {}