1 # -*- coding: utf-8 -*-
3 from django.core.files.storage import FileSystemStorage
4 from django.db import models
5 from django.utils.translation import ugettext_lazy as _
6 from jsonfield import JSONField
7 from . import app_settings
10 class Contact(models.Model):
11 created_at = models.DateTimeField(_('submission date'), auto_now_add=True)
12 ip = models.IPAddressField(_('IP address'))
13 contact = models.CharField(_('contact'), max_length=128)
14 form_tag = models.CharField(_('form'), max_length=32, db_index=True)
15 body = JSONField(_('body'))
18 def pretty_print(value, for_html=False):
19 if type(value) in (tuple, list, dict):
20 value = yaml.safe_dump(value,
22 default_flow_style=False)
24 value = value.replace(" ", unichr(160))
28 ordering = ('-created_at',)
29 verbose_name = _('submitted form')
30 verbose_name_plural = _('submitted forms')
32 def __unicode__(self):
33 return unicode(self.created_at)
36 class Attachment(models.Model):
37 contact = models.ForeignKey(Contact)
38 tag = models.CharField(max_length=64)
39 file = models.FileField(upload_to='contact/attachment')
42 def get_absolute_url(self):
43 return ('contact_attachment', [self.contact_id, self.tag])
46 __import__(app_settings.FORMS_MODULE)