annotate gpp/contact/forms.py @ 6:b6263ac72052

Use DRY principle to manage third party javascript libraries. Created script_tags template tags to generate the correct link and script tags for 3rd party libraries. The settings.py file is the only place where the full path name is specified.
author Brian Neal <bgneal@gmail.com>
date Sat, 11 Apr 2009 22:50:56 +0000
parents dbd703f7d63a
children
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):
gremmie@1 11 """Form used to contact the website admins"""
gremmie@1 12 name = forms.CharField(label = "Your Name", max_length = 61,
gremmie@1 13 widget = forms.TextInput(attrs = {'size' : 50 }))
gremmie@1 14 email = forms.EmailField(label = "Your Email",
gremmie@1 15 widget = forms.TextInput(attrs = {'size' : 50 }))
gremmie@1 16 subject = forms.CharField(max_length = 64,
gremmie@1 17 widget = forms.TextInput(attrs = {'size' : 50 }))
gremmie@1 18 honeypot = forms.CharField(max_length = 64, required = False,
gremmie@1 19 label = 'If you enter anything in this field your message will be treated as spam')
gremmie@1 20 message = forms.CharField(label = "Your Message",
gremmie@1 21 widget = forms.Textarea(attrs = {'rows' : 16, 'cols' : 50}),
gremmie@1 22 max_length = 3000)
gremmie@1 23
gremmie@1 24 recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS]
gremmie@1 25
gremmie@1 26 def clean_honeypot(self):
gremmie@1 27 value = self.cleaned_data['honeypot']
gremmie@1 28 if value:
gremmie@1 29 raise forms.ValidationError(self.fields['honeypot'].label)
gremmie@1 30 return value
gremmie@1 31
gremmie@1 32 def save(self):
gremmie@1 33 # Send the feedback message email
gremmie@1 34
gremmie@1 35 site = Site.objects.get_current()
gremmie@1 36
gremmie@1 37 msg = render_to_string('contact/contact_email.txt',
gremmie@1 38 {
gremmie@1 39 'site_name' : site.name,
gremmie@1 40 'user_name' : self.cleaned_data['name'],
gremmie@1 41 'user_email' : self.cleaned_data['email'],
gremmie@1 42 'message' : self.cleaned_data['message'],
gremmie@1 43 })
gremmie@1 44
gremmie@1 45 subject = site.name + ' Feedback: ' + self.cleaned_data['subject']
gremmie@1 46 send_mail(subject, msg, self.cleaned_data['email'], self.recipient_list)
gremmie@1 47