All checks were successful
Build and Push Docker Image / build (push) Successful in 42s
- Added `Cart` and `CartItem` models with migrations for managing user-specific carts and items - Developed services for cart-related operations: adding, removing, and updating cart items - Built specialized templates (`cart.html`) and styled them with new CSS assets (`cart.css`) - Enabled real-time UI updates via AJAX in shopping cart interactions (`cart.js`) - Modified header to dynamically display cart link with user authentication awareness - Added Leaflet-based interactive map to the contacts page and integrated CSS/JS dependencies - Expanded tests for cart functionality, item detail page cart integration, and contacts page maps
89 lines
3.3 KiB
Python
89 lines
3.3 KiB
Python
import logging
|
||
|
||
from django.conf import settings
|
||
from django.core.mail import send_mail
|
||
from django.shortcuts import redirect, render
|
||
from django.urls import reverse
|
||
from django.contrib import messages
|
||
|
||
from home.forms import FaqQuestionForm
|
||
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
CONTACT_ADDRESS = "Беларусь, г. Минск, ул. Тимирязева, д. 123, к.1, пав. 59"
|
||
CONTACT_EMAIL = "info@santehray.by"
|
||
CONTACT_PHONE_PRIMARY = "+375 (29) 688-18-19"
|
||
CONTACT_PHONE_PRIMARY_URL = "+375296881819"
|
||
CONTACT_PHONE_SECONDARY = "+375 (33) 337-67-81"
|
||
CONTACT_PHONE_SECONDARY_URL = "+375333376781"
|
||
CONTACT_HOURS_WEEKDAYS = "Пн-Пт: 9.00 - 21.00"
|
||
CONTACT_HOURS_WEEKENDS = "Сб-Вс: 10.00 - 18.00"
|
||
CONTACT_MAP_CENTER = {"lat": "53.9334960", "lon": "27.4551021", "zoom": 15}
|
||
CONTACT_MAP_EXTERNAL_URL = (
|
||
"https://www.openstreetmap.org/?mlat=53.9334960&mlon=27.4551021#map=15/53.9334960/27.4551021"
|
||
)
|
||
|
||
|
||
def index(request):
|
||
form = FaqQuestionForm(request.POST or None)
|
||
|
||
if request.method == "POST" and form.is_valid():
|
||
subject = f"Новый вопрос с сайта {settings.SITE_NAME}"
|
||
message = "\n".join(
|
||
[
|
||
f"Имя: {form.cleaned_data['name']}",
|
||
f"Телефон: {form.cleaned_data['phone']}",
|
||
f"Вопрос: {form.cleaned_data['question']}",
|
||
"",
|
||
f"Страница: {request.build_absolute_uri('/')}",
|
||
]
|
||
)
|
||
|
||
try:
|
||
send_mail(
|
||
subject=subject,
|
||
message=message,
|
||
from_email=settings.DEFAULT_FROM_EMAIL,
|
||
recipient_list=[settings.ADMINISTRATOR_EMAIL],
|
||
fail_silently=False,
|
||
)
|
||
except Exception:
|
||
logger.exception("Failed to send FAQ question email")
|
||
form.add_error(None, "Не удалось отправить вопрос. Попробуйте позже.")
|
||
else:
|
||
messages.success(request, "Спасибо. Ваш вопрос отправлен, мы свяжемся с вами в ближайшее время.")
|
||
return redirect(f"{reverse('home')}#faq-section")
|
||
|
||
return render(request=request, template_name='home/index.html', context={"faq_form": form})
|
||
|
||
|
||
def services(request):
|
||
return render(request=request, template_name='home/services.html', context={})
|
||
|
||
|
||
def shipping(request):
|
||
return render(request=request, template_name='home/shipping.html', context={})
|
||
|
||
|
||
def warranty(request):
|
||
return render(request=request, template_name='home/warranty.html', context={})
|
||
|
||
|
||
def contacts(request):
|
||
context = {
|
||
"contact_address": CONTACT_ADDRESS,
|
||
"contact_email": CONTACT_EMAIL,
|
||
"contact_phone_primary": CONTACT_PHONE_PRIMARY,
|
||
"contact_phone_primary_url": CONTACT_PHONE_PRIMARY_URL,
|
||
"contact_phone_secondary": CONTACT_PHONE_SECONDARY,
|
||
"contact_phone_secondary_url": CONTACT_PHONE_SECONDARY_URL,
|
||
"contact_hours_weekdays": CONTACT_HOURS_WEEKDAYS,
|
||
"contact_hours_weekends": CONTACT_HOURS_WEEKENDS,
|
||
"map_lat": CONTACT_MAP_CENTER["lat"],
|
||
"map_lon": CONTACT_MAP_CENTER["lon"],
|
||
"map_zoom": CONTACT_MAP_CENTER["zoom"],
|
||
"map_external_url": CONTACT_MAP_EXTERNAL_URL,
|
||
}
|
||
return render(request=request, template_name='home/contacts.html', context=context)
|