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
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
Loading…
Reference in New Issue