django-emailform / emailform /

Full commit
from __future__ import absolute_import

import datetime
from operator import itemgetter

from django.contrib.sites.models import Site
from django.db import models
from django.utils.translation import ugettext_lazy as _

from .util import ChoiceEnum
from . import settings as local_settings

    from positions.fields import PositionField
except ImportError:
    logging.warn('positions not installed. '
                 'Will just use integers for position fields.')
    PositionField = None

class LiveContactFormManager(models.Manager):

    def get_query_set(self):
        now =
        return super(LiveContactFormManager, self).get_query_set().filter(

class ContactForm(models.Model):

    class Meta:
        ordering = ('-starts_at',)

    title = models.CharField(max_length=80)
    slug = models.SlugField(unique=True)
    description = models.TextField(blank=True)
    starts_at = models.DateTimeField(
    is_published = models.BooleanField(default=False)
    thanks_message = models.TextField(default="Thanks for entering!")
    email = models.CharField(
        help_text=("Send a notification to this email whenever someone "
                   "submits an entry to this contact form",),
    site = models.ForeignKey(Site)

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return ('contact_form_detail', (), {'slug': self.slug})

    objects = models.Manager()
    live = LiveContactFormManager()

OPTION_TYPE_CHOICES = ChoiceEnum(sorted([('char', 'Text Field'),
                                         ('email', 'Email Field'),
                                         ('photo', 'Photo Upload'),
                                         ('video', 'Video Link'),
                                         ('location', 'Location Field'),
                                         ('integer', 'Integer'),
                                         ('float', 'Float'),
                                         ('bool', 'Boolean'),
                                         ('text', 'Text Area'),
                                         ('select', 'Select One Choice'),
                                         ('radio', 'Radio List'),
                                         ('checkbox', 'Checkbox List'),
                                         ('zipcode', 'Zipcode'),
                                         ('state', 'State'),
                                         ('phonenumber', 'Phone Number')],

class Question(models.Model):

    class Meta:
        ordering = ('order',)

    contact_form = models.ForeignKey(ContactForm, related_name="questions")
    question = models.TextField(help_text=_(
        "Appears on the contact form entry page."))
    label = models.CharField(max_length=32, help_text=_(
        "Appears on the results page."))
    help_text = models.TextField(blank=True)
    required = models.BooleanField(default=False)
    if PositionField:
        order = PositionField(collection=('contact_form',))
        order = models.IntegerField()
    option_type = models.CharField(max_length=12, choices=OPTION_TYPE_CHOICES)
    options = models.TextField(blank=True, default='')

    def __unicode(self):
        return self.question

    def parsed_options(self):
        if OPTION_TYPE_CHOICES.BOOLEAN == self.option_type:
            return [True, False]
        return filter(None, (s.strip() for s in self.options.splitlines()))

class Entry(models.Model):

    class Meta:
        verbose_name = "Entry"
        verbose_name_plural = "Entries"
        ordering = ('-submitted_at',)

    contact_form = models.ForeignKey(ContactForm)
    ip_address = models.IPAddressField()
    submitted_at = models.DateTimeField(
    content = models.TextField(blank=True)