Mercurial > public > sg101
view gpp/contact/forms.py @ 265:1ba2c6bf6eb7
Closing #98. Animated GIFs were losing their transparency and animated properties when saved as avatars. Reworked the avatar save process to only run the avatar through PIL if it is too big. This preserves the original uploaded file if it is within the desired size settings. This may still mangle big animated gifs. If this becomes a problem, then maybe look into calling the PIL Image.resize() method directly. Moved the PIL image specific functions from bio.forms to a new module: core.image for better reusability in the future.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 24 Sep 2010 02:12:09 +0000 |
parents | dbd703f7d63a |
children |
line wrap: on
line source
"""forms for the contact application""" from django import forms from django.conf import settings from django.template.loader import render_to_string from django.contrib.sites.models import Site from core.functions import send_mail class ContactForm(forms.Form): """Form used to contact the website admins""" name = forms.CharField(label = "Your Name", max_length = 61, widget = forms.TextInput(attrs = {'size' : 50 })) email = forms.EmailField(label = "Your Email", widget = forms.TextInput(attrs = {'size' : 50 })) subject = forms.CharField(max_length = 64, widget = forms.TextInput(attrs = {'size' : 50 })) honeypot = forms.CharField(max_length = 64, required = False, label = 'If you enter anything in this field your message will be treated as spam') message = forms.CharField(label = "Your Message", widget = forms.Textarea(attrs = {'rows' : 16, 'cols' : 50}), max_length = 3000) recipient_list = [mail_tuple[1] for mail_tuple in settings.MANAGERS] def clean_honeypot(self): value = self.cleaned_data['honeypot'] if value: raise forms.ValidationError(self.fields['honeypot'].label) return value def save(self): # Send the feedback message email site = Site.objects.get_current() msg = render_to_string('contact/contact_email.txt', { 'site_name' : site.name, 'user_name' : self.cleaned_data['name'], 'user_email' : self.cleaned_data['email'], 'message' : self.cleaned_data['message'], }) subject = site.name + ' Feedback: ' + self.cleaned_data['subject'] send_mail(subject, msg, self.cleaned_data['email'], self.recipient_list)