123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- from django.shortcuts import render
- from django.http import HttpResponseRedirect
- from .models import *
- from landing.forms import *
- # Create your views here.
- from django.core.mail import EmailMessage, get_connection
- import core.settings as settings
- def send_email_mess(body, sub):
- with get_connection(
- host=settings.EMAIL_HOST,
- port=settings.EMAIL_PORT,
- username=settings.EMAIL_HOST_USER,
- password=settings.EMAIL_HOST_PASSWORD,
- use_tls=settings.EMAIL_USE_TLS,
- use_ssl=settings.EMAIL_USE_SSL
- ) as connection:
- #print(form.cleaned_data)
- subject = sub
- email_from = settings.EMAIL_HOST_USER
- recipient_list = [settings.EMAIL_TO]
- message = body
- EmailMessage(subject, message, email_from, recipient_list, connection=connection).send()
- def index_html(request):
- if request.POST:
- form = MyForm(request.POST)
- if form.is_valid():
- body = f"""
- Имя: {form.cleaned_data['name']}\n
- Email: {form.cleaned_data['email']}\n
- Комментарий: {form.cleaned_data['message']}
- """
- send_email_mess(body, "Пользователь оставил отзыв")
- else:
- form = MyForm()
- menu = LandingPage.objects.filter(slug__startswith='clean')
- context = {
- # "mainpage":LandingPage.objects.get(slug="main"),
- "menu":menu,
- "form":form
- }
- return render(request, 'landing/pages/main.html', context=context)
- def page_html(request):
- if request.POST:
- form = MyForm(request.POST)
- if form.is_valid():
- print(form.cleaned_data)
- else:
- form = MyForm()
- slug = (request.path[1:-1])
- if not LandingPage.objects.filter(slug=slug):
- menu = LandingPage.objects.filter(slug__startswith='clean')
- print(menu)
- if not LandingPage.objects.filter(slug__startswith='clean'):
- menu = LandingPage.objects.filter(slug__startswith='clean')
- context = {
- "form":form
- }
- else:
- context = {
- "form":form,
- "menu":menu
- }
- return render(request, 'landing/pages/in_work.html', context=context)
- else:
- menu = LandingPage.objects.filter(slug__startswith='clean')
- print(menu)
- context = {
- "mainpage":LandingPage.objects.get(slug=slug),
- "form":form,
- "menu":menu
- }
- return render(request, 'landing/pages/simple.html', context=context)
- def send_email(request):
- if request.method == 'POST':
- print(request.POST['email'])
-
- return HttpResponseRedirect('/')
- #simple page
- def contact_html(request):
- return render(request, 'landing/pages/contact.html')
- def price_html(request):
- return render(request, 'landing/pages/price.html')
- def order_html(request):
- if request.POST:
- form = OrderForm(request.POST)
- if form.is_valid():
- services = ""
- for item in form.cleaned_data['service']:
- services += f"{SERVICE_CHOICES[int(item)][1]}, "
- body = f"""
- Имя: {form.cleaned_data['name']}\n
- Фамилия: {form.cleaned_data['surname']}\n
- Номер телефона: {form.cleaned_data['phone']}\n
- Выбранные услуги: {services}\n
- Желаемое время оказания услуги: {form.cleaned_data['datetime']}\n
- Комментарий: {form.cleaned_data['comment'] or "Комментарий отсутствует"}
- """
- send_email_mess(body, "ЗАКАЗ")
- else:
- form = OrderForm()
- context = {
- "form":form
- }
- return render(request, 'landing/pages/order.html', context)
- def faq_html(request):
- if request.POST:
- form = MyForm(request.POST)
- if form.is_valid():
- body = f"""
- Имя: {form.cleaned_data['name']}\n
- Email: {form.cleaned_data['email']}\n
- Вопрос: {form.cleaned_data['message']}
- """
- send_email_mess(body, "Пользователь задал вопрос")
- else:
- form = MyForm()
- context = {
- "form":form,
- "faq":FAQmodel.objects.all()
- }
- return render(request, 'landing/pages/faq.html', context)
|