mirror of
https://github.com/ae-utbm/sith.git
synced 2025-04-15 18:40:23 +00:00
Default France value and cleaner handling of BillingInfo creation
This commit is contained in:
parent
5c2f324e13
commit
4ce885ac6b
@ -43,7 +43,6 @@ class BillingInfoForm(forms.ModelForm):
|
||||
]
|
||||
widgets = {
|
||||
"phone_number": RegionalPhoneNumberWidget,
|
||||
"country": AutoCompleteSelect,
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,7 +51,9 @@ class BillingInfoState(Enum):
|
||||
MISSING_PHONE_NUMBER = 3
|
||||
|
||||
@classmethod
|
||||
def from_model(cls, info: BillingInfo) -> BillingInfoState:
|
||||
def from_model(cls, info: BillingInfo | None) -> BillingInfoState:
|
||||
if info is None:
|
||||
return cls.EMPTY
|
||||
for attr in [
|
||||
"first_name",
|
||||
"last_name",
|
||||
|
@ -16,7 +16,7 @@
|
||||
class="collapse-body"
|
||||
hx-trigger="submit"
|
||||
hx-post="{{ action }}"
|
||||
hx-swap="outerHTML settle:100"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="closest span"
|
||||
x-show="collapsed"
|
||||
>
|
||||
|
@ -66,7 +66,6 @@
|
||||
{% trans %}Clear{% endtrans %}
|
||||
</button>
|
||||
<form method="get" action="{{ url('eboutic:command') }}">
|
||||
{% csrf_token %}
|
||||
<button class="btn btn-blue">
|
||||
<i class="fa fa-check"></i>
|
||||
<input type="submit" value="{% trans %}Validate{% endtrans %}"/>
|
||||
|
@ -72,6 +72,7 @@
|
||||
type="submit"
|
||||
id="bank-submit-button"
|
||||
:disabled="!isCbAvailable"
|
||||
class="btn btn-blue"
|
||||
value="{% trans %}Pay with credit card{% endtrans %}"
|
||||
/>
|
||||
</form>
|
||||
@ -84,7 +85,7 @@
|
||||
<form method="post" action="{{ url('eboutic:pay_with_sith') }}" name="sith-pay-form">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="pay_with_sith_account">
|
||||
<input type="submit" value="{% trans %}Pay with Sith account{% endtrans %}"/>
|
||||
<input class="btn btn-blue" type="submit" value="{% trans %}Pay with Sith account{% endtrans %}"/>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -38,6 +38,7 @@ from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.http import require_GET, require_POST
|
||||
from django.views.generic import TemplateView, UpdateView, View
|
||||
from django_countries.fields import Country
|
||||
|
||||
from core.views.mixins import FragmentMixin, UseFragmentsMixin
|
||||
from counter.forms import BillingInfoForm
|
||||
@ -55,6 +56,7 @@ from eboutic.schemas import PurchaseItemList, PurchaseItemSchema
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
|
||||
from django.utils.html import SafeString
|
||||
|
||||
|
||||
@login_required
|
||||
@ -99,15 +101,28 @@ class BillingInfoFormFragment(LoginRequiredMixin, FragmentMixin, UpdateView):
|
||||
form_class = BillingInfoForm
|
||||
template_name = "eboutic/eboutic_billing_info.jinja"
|
||||
|
||||
def get_initial(self):
|
||||
if self.object is None:
|
||||
return {
|
||||
"country": Country(code="FR"),
|
||||
}
|
||||
return {}
|
||||
|
||||
def render_fragment(self, request, **kwargs) -> SafeString:
|
||||
self.object = self.get_object()
|
||||
return super().render_fragment(request, **kwargs)
|
||||
|
||||
def get_customer(self) -> Customer:
|
||||
return Customer.get_or_create(self.request.user)[0]
|
||||
|
||||
def form_valid(self, form: BillingInfoForm):
|
||||
form.instance.customer = self.get_customer()
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_object(self, *args, **kwargs):
|
||||
customer, _ = Customer.get_or_create(self.request.user)
|
||||
if not hasattr(customer, "billing_infos"):
|
||||
customer.billing_infos = BillingInfo()
|
||||
return customer.billing_infos
|
||||
return getattr(self.get_customer(), "billing_infos", None)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
if not hasattr(self, "object"):
|
||||
self.object = self.get_object()
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
kwargs["action"] = reverse("eboutic:billing_infos")
|
||||
kwargs["BillingInfoState"] = BillingInfoState
|
||||
|
Loading…
x
Reference in New Issue
Block a user