mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-11 04:19:25 +00:00
Fix counter main
* Fix crash when submitting nothing * Fix code field not being autofocus
This commit is contained in:
@ -87,7 +87,7 @@ class GetUserForm(forms.Form):
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
cus = None
|
||||
customer = None
|
||||
if cleaned_data["code"] != "":
|
||||
if len(cleaned_data["code"]) == StudentCard.UID_SIZE:
|
||||
card = (
|
||||
@ -96,17 +96,18 @@ class GetUserForm(forms.Form):
|
||||
.first()
|
||||
)
|
||||
if card is not None:
|
||||
cus = card.customer
|
||||
if cus is None:
|
||||
cus = Customer.objects.filter(
|
||||
customer = card.customer
|
||||
if customer is None:
|
||||
customer = Customer.objects.filter(
|
||||
account_id__iexact=cleaned_data["code"]
|
||||
).first()
|
||||
elif cleaned_data["id"] is not None:
|
||||
cus = Customer.objects.filter(user=cleaned_data["id"]).first()
|
||||
if cus is None or not cus.can_buy:
|
||||
elif cleaned_data["id"]:
|
||||
customer = Customer.objects.filter(user=cleaned_data["id"]).first()
|
||||
|
||||
if customer is None or not customer.can_buy:
|
||||
raise forms.ValidationError(_("User not found"))
|
||||
cleaned_data["user_id"] = cus.user.id
|
||||
cleaned_data["user"] = cus.user
|
||||
cleaned_data["user_id"] = customer.user.id
|
||||
cleaned_data["user"] = customer.user
|
||||
return cleaned_data
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user