From 652ceb27c297c4ea0cf707d157e7e680d356b509 Mon Sep 17 00:00:00 2001 From: Sli Date: Fri, 20 Dec 2024 19:06:01 +0100 Subject: [PATCH] Fix counter main * Fix crash when submitting nothing * Fix code field not being autofocus --- counter/forms.py | 19 +++++++++--------- counter/templates/counter/counter_main.jinja | 21 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/counter/forms.py b/counter/forms.py index 80a0e0ad..cfd1b46d 100644 --- a/counter/forms.py +++ b/counter/forms.py @@ -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 diff --git a/counter/templates/counter/counter_main.jinja b/counter/templates/counter/counter_main.jinja index fcf1bb43..b418f263 100644 --- a/counter/templates/counter/counter_main.jinja +++ b/counter/templates/counter/counter_main.jinja @@ -59,5 +59,26 @@ {% endif %} {% endblock %} +{% block script %} + {{ super() }} + +{% endblock %} +