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