comparison contact/forms.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/contact/forms.py@dbd703f7d63a
children 38db6ec61af3
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """forms for the contact application"""
2
3 from django import forms
4 from django.conf import settings
5 from django.template.loader import render_to_string
6 from django.contrib.sites.models import Site
7 from core.functions import send_mail
8
9
10 class ContactForm(forms.Form):
11 """Form used to contact the website admins"""
12 name = forms.CharField(label = "Your Name", max_length = 61,
13 widget = forms.TextInput(attrs = {'size' : 50 }))
14 email = forms.EmailField(label = "Your Email",
15 widget = forms.TextInput(attrs = {'size' : 50 }))
16 subject = forms.CharField(max_length = 64,
17 widget = forms.TextInput(attrs = {'size' : 50 }))
18 honeypot = forms.CharField(max_length = 64, required = False,
19 label = 'If you enter anything in this field your message will be treated as spam')
20 message = forms.CharField(label = "Your Message",
21 widget = forms.Textarea(attrs = {'rows' : 16, 'cols' : 50}),
22 max_length = 3000)
23
24 recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS]
25
26 def clean_honeypot(self):
27 value = self.cleaned_data['honeypot']
28 if value:
29 raise forms.ValidationError(self.fields['honeypot'].label)
30 return value
31
32 def save(self):
33 # Send the feedback message email
34
35 site = Site.objects.get_current()
36
37 msg = render_to_string('contact/contact_email.txt',
38 {
39 'site_name' : site.name,
40 'user_name' : self.cleaned_data['name'],
41 'user_email' : self.cleaned_data['email'],
42 'message' : self.cleaned_data['message'],
43 })
44
45 subject = site.name + ' Feedback: ' + self.cleaned_data['subject']
46 send_mail(subject, msg, self.cleaned_data['email'], self.recipient_list)
47