Files
santeh-ray/orders/forms.py
Azimkin 81e30f853d
All checks were successful
Build and Push Docker Image / build (push) Successful in 50s
feat: implement order management and checkout functionality
- Added `Order` and `OrderItem` models with migrations for managing orders and their details
- Created `CheckoutForm` for validating order data and customer information
- Built templates for order confirmation, checkout success, and emails (HTML and plain text)
- Added logic for email notifications upon successful order placement
- Enhanced shopping cart template with checkout panel integration
- Updated styles and JavaScript for streamlined checkout UX
- Refactored cart view to support item summaries and final totals during checkout
2026-05-25 16:45:42 +02:00

57 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django import forms
from orders.models import Order
class CheckoutForm(forms.Form):
delivery_method = forms.ChoiceField(
choices=Order.DeliveryMethod.choices,
initial=Order.DeliveryMethod.COURIER,
widget=forms.RadioSelect,
label="Способ доставки",
)
region = forms.CharField(max_length=255, required=False, label="Регион")
address = forms.CharField(max_length=512, required=False, label="Адрес")
payment_method = forms.ChoiceField(
choices=Order.PaymentMethod.choices,
initial=Order.PaymentMethod.CARD,
widget=forms.RadioSelect,
label="Способ оплаты",
)
customer_name = forms.CharField(max_length=255, label="ФИО")
phone = forms.CharField(max_length=32, label="Телефон")
email = forms.EmailField(label="E-mail")
recipient_matches_customer = forms.BooleanField(required=False, initial=True)
promo_code = forms.CharField(max_length=64, required=False, label="Промокод")
terms_accepted = forms.BooleanField(required=True, label="Согласие с условиями")
def clean_email(self):
return self.cleaned_data["email"].strip().lower()
def clean_promo_code(self):
return self.cleaned_data["promo_code"].strip()
def clean_customer_name(self):
return self.cleaned_data["customer_name"].strip()
def clean_phone(self):
return self.cleaned_data["phone"].strip()
def clean_region(self):
return self.cleaned_data["region"].strip()
def clean_address(self):
return self.cleaned_data["address"].strip()
def clean(self):
cleaned_data = super().clean()
delivery_method = cleaned_data.get("delivery_method")
if delivery_method == Order.DeliveryMethod.COURIER:
if not cleaned_data.get("region"):
self.add_error("region", "Укажите регион доставки.")
if not cleaned_data.get("address"):
self.add_error("address", "Укажите адрес доставки.")
return cleaned_data