Skip to content

Instantly share code, notes, and snippets.

@mjtamlyn
Created June 20, 2012 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mjtamlyn/2959354 to your computer and use it in GitHub Desktop.
Save mjtamlyn/2959354 to your computer and use it in GitHub Desktop.
Multi-contact form (FeinCMS content type)
from django.db import models
from django.utils.text import ugettext_lazy as _
from .contact_form_amended import ContactForm, ContactFormContent
class MultiContactFormContent(ContactFormContent):
FORM_CLASSES = {'simple-contact': ContactForm}
FORM_CHOICES = (('simple-contact', _('Simple contact form')),)
class Meta(ContactFormContent.Meta):
abstract = True
@classmethod
def initialize_type(cls, forms=None):
if forms:
cls.FORM_CLASSES = dict([(f[0], f[2]) for f in forms])
cls.FORM_CHOICES = [(f[0], f[1]) for f in forms]
cls.add_to_class('form', models.CharField(max_length=200, choices=cls.FORM_CHOICES))
def get_email_template_names(self):
return [
'context/contactform/%s-email.txt' % self.form,
'content/contactform/email.txt',
]
def get_form_class(self):
return self.FORM_CLASSES[self.form]
@matthiask
Copy link

Nice! I prefer form designer for those use cases though :-)

https://github.com/feincms/form_designer

@mjtamlyn
Copy link
Author

Yeah I looked at that for about half an hour and couldn't see how to make it do what I needed. Also it didn't have a content type or app content to go with it, whereas this already had the handling. That and I couldn't pip install it :(

@matthiask
Copy link

matthiask commented Jun 20, 2012 via email

@mjtamlyn
Copy link
Author

Ah, that wasn't obvious. It needed a bit of docs to explain how the email/action stuff worked too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment