Mercurial > public > sg101
comparison gpp/contact/forms.py @ 1:dbd703f7d63a
Initial import of sg101 stuff from private repository.
author | gremmie |
---|---|
date | Mon, 06 Apr 2009 02:43:12 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:900ba3c7b765 | 1:dbd703f7d63a |
---|---|
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 |