Formatting
This commit is contained in:
parent
cd804f2c77
commit
44c70a5ee7
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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 = {}
|
||||||
|
|
Loading…
Reference in New Issue