def contact_form(request, template="contact/contact.html"): """ Prints the contact form. If posted, validates. If validates, sends an email to the contacts in settings. """ if request.method == 'POST': form = ContactForm(request.POST) try: valid = form.is_valid() except SuspiciousOperation: # Bot fake out! return redirect(reverse('contact_success')) if valid: success = form.send_email(settings.CONTACT_RECIPIENTS, settings.DEFAULT_FROM_EMAIL) if success: return redirect(reverse('contact_success')) else: return redirect(reverse('contact_failure')) else: form = ContactForm() return render_to_response(template, { 'form': form, }, context_instance=RequestContext(request))
def home(request): if request.method == 'POST': contact_form = ContactForm(request.POST) if contact_form.is_valid(): contact_form.save() messages.success( request, 'Mensaje enviado con exito, nos pondremos en contacto pronto') else: messages.error( request, 'Ocurrió un error al enviar el mensaje, intenta nuevamente') return render(request, 'index.html', {'form': ContactForm})
def contact(request): if request.method == 'POST': # If the form has been submitted... form = ContactForm(request.POST) # A form bound to the POST data if form.is_valid(): name = form.cleaned_data['name'] email = form.cleaned_data['email'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] send_mail(subject, message, email, ['*****@*****.**', '*****@*****.**']) return HttpResponseRedirect('/') else: form = ContactForm() # An unbound form return render(request, 'contact/contact_form.html', { 'form': form, })
def contact_submit(request): log = logging.getLogger(__name__) if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): name = form.cleaned_data["contact_name"] content = form.cleaned_data["content"] from_email = form.cleaned_data["contact_email"] to_email = [form.cleaned_data["contact_receiver"]] client_ip = get_client_ip(request) if not name: name = "Noen" if request.user.is_authenticated: username = request.user.username log.info( "{username} has tried to contact {to_email}".format( username=username, to_email=to_email ) ) else: log.info( "A user at {client_ip} has tried to contact {to_email}".format( client_ip=client_ip, to_email=to_email ) ) subject = "[Kontakt] {name} har kontaktet dere gjennom online.ntnu.no".format( name=name ) EmailMessage(subject, content, from_email, to_email).send() messages.success(request, "Meldingen ble sendt") else: messages.error( request, "Meldingen ble ikke sendt. Prøv igjen eller send mail direkte til dotkom", ) return redirect("contact_index")
def contact_submit(request): log = logging.getLogger(__name__) if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): name = form.cleaned_data['contact_name'] content = form.cleaned_data['content'] from_email = form.cleaned_data['contact_email'] to_email = [form.cleaned_data['contact_receiver']] client_ip = get_client_ip(request) if not name: name = 'Noen' if request.user.is_authenticated: username = request.user.username log.info('{username} has tried to contact {to_email}'.format( username=username, to_email=to_email)) else: log.info( 'A user at {client_ip} has tried to contact {to_email}'. format(client_ip=client_ip, to_email=to_email)) subject = '[Kontakt] {name} har kontaktet dere gjennom online.ntnu.no'.format( name=name) EmailMessage(subject, content, from_email, to_email).send() messages.success(request, 'Meldingen ble sendt') else: messages.error( request, 'Meldingen ble ikke sendt. Prøv igjen eller send mail direkte til dotkom' ) return redirect('contact_index')
def edit_person(request): contact = get_object_or_404(Person) if request.method == 'POST': form = ContactForm(request.POST, request.FILES, instance=contact) if form.is_valid(): form.save() if request.is_ajax(): return HttpResponse("redirect") else: return redirect(reverse('contact')) else: form = ContactForm(instance=contact) return render(request, 'contact/contact_form.html', {'form': form})
def contact_form(request): success = None if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): # Getting clean fields name = form.cleaned_data['name'] email = form.cleaned_data['email'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] feedback_email = getattr(settings, 'FEEDBACK_EMAIL') user_ip = request.META['REMOTE_ADDR'] recipients = [feedback_email] # Get current url of site site = request.scheme + '://' +\ request.META['HTTP_HOST'] + request.path date = datetime.now().strftime("%d.%m.%Y в %H:%M") from_email = getattr(settings, 'FROM_EMAIL') # Forming message for send message = "{1} написал Вам через форму обратной связи с сайта {0}:\ \n\n{2}\n\nДата: {3}\ \nEmail отправителя: {4}\ \nIP отправителя: {5}".format(site, name, message, date, email, user_ip) try: send_mail(subject, message, from_email, recipients) except BadHeaderError: raise form.ValidationError('Invalid header found!') else: success = True form = ContactForm() else: form = ContactForm() context_dict = {'form': form, 'success': success} return render(request, 'contact.html', context_dict)
def contact(request): form = ContactForm(request.POST or None) if form.is_valid(): form.save() return render(request, 'contact.html', {'form': form})