annotate contact/forms.py @ 1160:b84ce2d7e93d

New template for displaying django messages. New common template for rendering django messages in the new V3 Foundation style.
author Brian Neal <bgneal@gmail.com>
date Tue, 24 Jan 2017 19:22:29 -0600
parents 6ac56115e0a8
children b957e4829a03
rev   line source
gremmie@1 1 """forms for the contact application"""
gremmie@1 2
gremmie@1 3 from django import forms
gremmie@1 4 from django.conf import settings
gremmie@1 5 from django.template.loader import render_to_string
gremmie@1 6 from django.contrib.sites.models import Site
gremmie@1 7 from core.functions import send_mail
gremmie@1 8
gremmie@1 9
gremmie@1 10 class ContactForm(forms.Form):
bgneal@819 11 """Form used to contact the website admins"""
bgneal@1070 12 name=forms.CharField(label="Your Name")
bgneal@1070 13 email=forms.EmailField(label="Your Email")
bgneal@1070 14 subject=forms.CharField()
bgneal@819 15 honeypot=forms.CharField(max_length=64, required=False,
bgneal@819 16 label='If you enter anything in this field your message will be treated as spam')
bgneal@819 17 message=forms.CharField(label="Your Message",
bgneal@1070 18 widget=forms.Textarea(),
bgneal@819 19 max_length=3000)
gremmie@1 20
bgneal@819 21 recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS]
gremmie@1 22
bgneal@819 23 def clean_honeypot(self):
bgneal@819 24 value = self.cleaned_data['honeypot']
bgneal@819 25 if value:
bgneal@819 26 raise forms.ValidationError(self.fields['honeypot'].label)
bgneal@819 27 return value
gremmie@1 28
bgneal@819 29 def save(self):
bgneal@819 30 # Send the feedback message email
gremmie@1 31
bgneal@819 32 site = Site.objects.get_current()
gremmie@1 33
bgneal@819 34 msg = render_to_string('contact/contact_email.txt', {
bgneal@819 35 'site_name': site.name,
bgneal@819 36 'user_name': self.cleaned_data['name'],
bgneal@819 37 'user_email': self.cleaned_data['email'],
bgneal@892 38 'subject': self.cleaned_data['subject'],
bgneal@819 39 'message': self.cleaned_data['message'],
bgneal@819 40 })
gremmie@1 41
bgneal@819 42 subject = site.name + ' Feedback: ' + self.cleaned_data['subject']
bgneal@892 43 from_email = settings.GPP_NO_REPLY_EMAIL + '@' + site.domain
bgneal@892 44 send_mail(subject, msg, from_email, self.recipient_list,
bgneal@892 45 reply_to=self.cleaned_data['email'])