update admin panel and visual
This commit is contained in:
+25
-7
@@ -1,21 +1,39 @@
|
||||
from django.contrib import messages
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.shortcuts import redirect, render
|
||||
from django.urls import reverse
|
||||
|
||||
from .forms import ConsultationRequestForm
|
||||
from .models import ConsultationSlot
|
||||
|
||||
|
||||
def home(request):
|
||||
if request.method == "POST":
|
||||
form = ConsultationRequestForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(
|
||||
request,
|
||||
"Заявка отправлена. Игорь Олегович свяжется с вами, чтобы подтвердить время консультации.",
|
||||
)
|
||||
return redirect(f"{reverse('consultations:home')}#booking")
|
||||
try:
|
||||
with transaction.atomic():
|
||||
form.save()
|
||||
except IntegrityError:
|
||||
form.add_error("slot", "Это время только что занял другой ученик. Выберите другой слот.")
|
||||
else:
|
||||
messages.success(
|
||||
request,
|
||||
"Заявка принята. Игорь Олегович свяжется с вами для подтверждения консультации.",
|
||||
)
|
||||
return redirect(f"{reverse('consultations:home')}#booking")
|
||||
else:
|
||||
form = ConsultationRequestForm()
|
||||
|
||||
return render(request, "consultations/home.html", {"form": form})
|
||||
return render(
|
||||
request,
|
||||
"consultations/home.html",
|
||||
{
|
||||
"form": form,
|
||||
"available_slot_count": ConsultationSlot.objects.available().count(),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def privacy_policy(request):
|
||||
return render(request, "consultations/privacy.html")
|
||||
|
||||
Reference in New Issue
Block a user