X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/6c9978c5bf8b1ef20871557c22b8b02df647d700..408f2a8ab658eb038a9a98892a253761dfca20d4:/contact/models.py diff --git a/contact/models.py b/contact/models.py index 1c92610..be16c4c 100644 --- a/contact/models.py +++ b/contact/models.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -import yaml from django.db import models -from django.utils.encoding import smart_unicode +from django.db.models import permalink from django.utils.translation import ugettext_lazy as _ from jsonfield import JSONField from . import app_settings @@ -17,8 +16,10 @@ class Contact(models.Model): @staticmethod def pretty_print(value, for_html=False): if type(value) in (tuple, list, dict): + import yaml value = yaml.safe_dump(value, allow_unicode=True, default_flow_style=False) if for_html: + from django.utils.encoding import smart_unicode value = smart_unicode(value).replace(u" ", unichr(160)) return value @@ -30,6 +31,13 @@ class Contact(models.Model): def __unicode__(self): return unicode(self.created_at) + @permalink + def update_url(self): + from contact.forms import update_forms, contact_forms + form_class = update_forms.get(self.form_tag, contact_forms.get(self.form_tag)) + confirmation = form_class.confirmation_class.objects.get(contact=self) + return 'edit_form', [], {'form_tag': self.form_tag, 'contact_id': self.id, 'key': confirmation.key} + class Attachment(models.Model): contact = models.ForeignKey(Contact)