55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from django.conf import settings
|
|
from django.shortcuts import render
|
|
from .models import AnonMessage
|
|
|
|
import json
|
|
import requests
|
|
from django.conf import settings
|
|
from django.http import JsonResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from django.core.mail import EmailMultiAlternatives
|
|
from django.template.loader import render_to_string
|
|
from django.utils.html import strip_tags
|
|
|
|
|
|
from .forms import ContactMe
|
|
|
|
# Create your views here.
|
|
def home(request):
|
|
if request.method == "POST":
|
|
form = ContactMe(request.POST)
|
|
if form.is_valid():
|
|
|
|
send_email_contactme(request, form.cleaned_data["customer_email"], form.cleaned_data["message"], form.cleaned_data["customer_name"])
|
|
|
|
return JsonResponse({"success": True})
|
|
else:
|
|
return JsonResponse({"success": False, "errors": form.errors})
|
|
|
|
|
|
#zprávy z chatu (posledníhc deset)
|
|
last_messages = AnonMessage.get_last_messages(10, True)
|
|
|
|
for message in last_messages:
|
|
message.time = message.time.strftime("%b. %d, %Y, %H:%M")
|
|
|
|
return render(request, 'home/index.html',{'last_messages':last_messages,'contactme_form': ContactMe()})
|
|
|
|
import logging
|
|
from django.core.mail import send_mail
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def send_email_contactme(request, customer_email, message, name):
|
|
subject = "vontor.cz - nový zákazník"
|
|
recipient_email = customer_email
|
|
context = f"Zákazník: {name}\nEmail: {customer_email}\n\nZpráva: {message}"
|
|
|
|
send_mail(
|
|
subject,
|
|
context,
|
|
'"vontor.cz" <web@vontor.cz>',
|
|
['brunovontor@gmail.com'],
|
|
fail_silently=False,
|
|
) |