1 # -*- coding: utf-8 -*-
3 from django.db import models
4 from django.utils.encoding import smart_unicode
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, allow_unicode=True, default_flow_style=False)
22 value = smart_unicode(value).replace(u" ", unichr(160))
26 ordering = ('-created_at',)
27 verbose_name = _('submitted form')
28 verbose_name_plural = _('submitted forms')
30 def __unicode__(self):
31 return unicode(self.created_at)
34 class Attachment(models.Model):
35 contact = models.ForeignKey(Contact)
36 tag = models.CharField(max_length=64)
37 file = models.FileField(upload_to='contact/attachment')
40 def get_absolute_url(self):
41 return 'contact_attachment', [self.contact_id, self.tag]
44 __import__(app_settings.FORMS_MODULE)