njpma/app/contact/views.py
2021-11-24 12:50:26 +01:00

23 lines
865 B
Python

from django.conf import settings
from django.core.mail import EmailMessage
from django.shortcuts import render
from app.video.utils import render_to_json_response
from . import forms
from . import models
def index(request):
success = True
if request.method == 'POST':
form = forms.ContactForm(request.POST)
if form.is_valid():
message = 'From: %s\n\n%s' % (form.cleaned_data['email'], form.cleaned_data['message'])
subject = 'njp.ma contact message'
from_ = settings.CONTACT_FROM_EMAIL
to = [settings.CONTACT_TO_EMAIL]
msg = EmailMessage(subject, message, from_, to, reply_to=[form.cleaned_data['email']])
msg.send(fail_silently=True)
else:
success = False
else:
success = False
return render_to_json_response({'success': success})