from django import newforms as forms from django.newforms import widgets from live.utils.custom_widgets import TinyMCE from live.about.models import Feedback class ContactForm(forms.Form): from_email = forms.EmailField(label='email',initial='my_email@address.com') subject = forms.CharField(max_length=100) message = forms.CharField(widget=TinyMCE()) subject_prefix = forms.CharField(widget=widgets.HiddenInput,initial='feedback') def save(self,commit = True,user=None): feedback = Feedback(**self.clean_data) feedback.user = user if commit: feedback.save() return feedback def contact(request,template="about/contact.html",redirect_to="/"): form = None if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): feedback = form.save(user=request.user) return HttpResponseRedirect("/") else: form = ContactForm() r = render_to_response(template, {'contact_form':form}) return r