from django.core.files.uploadedfile import UploadedFile
from django.core.mail import send_mail, mail_managers
from django.core.files.uploadedfile import UploadedFile
from django.core.mail import send_mail, mail_managers
model = super(ContactFormMeta, cls).__new__(cls, *args, **kwargs)
assert model.form_tag not in contact_forms, 'Duplicate form_tag.'
model = super(ContactFormMeta, cls).__new__(cls, *args, **kwargs)
assert model.form_tag not in contact_forms, 'Duplicate form_tag.'
class ContactForm(forms.Form):
"""Subclass and define some fields."""
__metaclass__ = ContactFormMeta
class ContactForm(forms.Form):
"""Subclass and define some fields."""
__metaclass__ = ContactFormMeta
def save(self, request):
body = {}
for name, value in self.cleaned_data.items():
if not isinstance(value, UploadedFile) and name != 'contact':
body[name] = value
def save(self, request):
body = {}
for name, value in self.cleaned_data.items():
if not isinstance(value, UploadedFile) and name != 'contact':
body[name] = value
contact = Contact.objects.create(body=body,
ip=request.META['REMOTE_ADDR'],
contact=self.cleaned_data['contact'],
contact = Contact.objects.create(body=body,
ip=request.META['REMOTE_ADDR'],
contact=self.cleaned_data['contact'],
for name, value in self.cleaned_data.items():
if isinstance(value, UploadedFile):
attachment = Attachment(contact=contact, tag=name)
for name, value in self.cleaned_data.items():
if isinstance(value, UploadedFile):
attachment = Attachment(contact=contact, tag=name)
mail_subject = render_to_string([
'contact/%s/mail_subject.txt' % self.form_tag,
'contact/mail_subject.txt',
mail_subject = render_to_string([
'contact/%s/mail_subject.txt' % self.form_tag,
'contact/mail_subject.txt',