feat: update order payment methods and refine profile edit functionality
All checks were successful
Build and Push Docker Image / build (push) Successful in 43s
All checks were successful
Build and Push Docker Image / build (push) Successful in 43s
- Replaced `Order.PaymentMethod` options with "cash" and "card" while adjusting related code and templates - Set "cash" as the default payment method for orders and checkout forms - Added profile editing functionality with `ProfileForm`, allowing users to update names - Improved feedback messages across profile and order management templates - Updated catalog to handle empty filter results with a "reset filters" option
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import re
|
||||
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from orders.models import Order
|
||||
|
||||
|
||||
PHONE_RE = re.compile(r"^\+?[\d\s\-()]{7,20}$")
|
||||
|
||||
|
||||
class CheckoutForm(forms.Form):
|
||||
delivery_method = forms.ChoiceField(
|
||||
choices=Order.DeliveryMethod.choices,
|
||||
@@ -14,7 +20,7 @@ class CheckoutForm(forms.Form):
|
||||
address = forms.CharField(max_length=512, required=False, label="Адрес")
|
||||
payment_method = forms.ChoiceField(
|
||||
choices=Order.PaymentMethod.choices,
|
||||
initial=Order.PaymentMethod.CARD,
|
||||
initial=Order.PaymentMethod.CASH,
|
||||
widget=forms.RadioSelect,
|
||||
label="Способ оплаты",
|
||||
)
|
||||
@@ -35,7 +41,10 @@ class CheckoutForm(forms.Form):
|
||||
return self.cleaned_data["customer_name"].strip()
|
||||
|
||||
def clean_phone(self):
|
||||
return self.cleaned_data["phone"].strip()
|
||||
phone = self.cleaned_data["phone"].strip()
|
||||
if not PHONE_RE.match(phone):
|
||||
raise ValidationError("Укажите корректный номер телефона.")
|
||||
return phone
|
||||
|
||||
def clean_region(self):
|
||||
return self.cleaned_data["region"].strip()
|
||||
|
||||
18
orders/migrations/0004_alter_order_payment_method.py
Normal file
18
orders/migrations/0004_alter_order_payment_method.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 6.0.5 on 2026-05-29 16:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('orders', '0003_cartitem_selected_color'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='order',
|
||||
name='payment_method',
|
||||
field=models.CharField(choices=[('cash', 'Наличкой при получении'), ('card', 'Картой при получении')], default='cash', max_length=16, verbose_name='Способ оплаты'),
|
||||
),
|
||||
]
|
||||
@@ -71,9 +71,8 @@ class Order(models.Model):
|
||||
PICKUP = "pickup", "Самовывоз"
|
||||
|
||||
class PaymentMethod(models.TextChoices):
|
||||
CARD = "card", "Банковская карта"
|
||||
CREDIT = "credit", "Кредит"
|
||||
INSTALLMENT = "installment", "Рассрочка"
|
||||
CASH = "cash", "Наличкой при получении"
|
||||
CARD = "card", "Картой при получении"
|
||||
|
||||
class Status(models.TextChoices):
|
||||
PAID = "paid", "Оплачен"
|
||||
@@ -98,7 +97,7 @@ class Order(models.Model):
|
||||
payment_method = models.CharField(
|
||||
max_length=16,
|
||||
choices=PaymentMethod.choices,
|
||||
default=PaymentMethod.CARD,
|
||||
default=PaymentMethod.CASH,
|
||||
verbose_name="Способ оплаты",
|
||||
)
|
||||
promo_code = models.CharField(max_length=64, blank=True, verbose_name="Промокод")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
from decimal import Decimal
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ def checkout(request: HttpRequest) -> HttpResponse:
|
||||
except Exception:
|
||||
messages.error(request, "Заказ создан, но письмо с деталями не удалось отправить. Мы свяжемся с вами.")
|
||||
else:
|
||||
messages.success(request, "Оплата прошла успешно. Детали заказа отправлены на почту.")
|
||||
messages.success(request, "Заказ успешно оформлен. Детали отправлены на почту.")
|
||||
|
||||
return redirect("orders:success", order_id=order.id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user