diff options
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 07a052470..ee767a4ef 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -59,6 +59,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch from django.db.models import Q, Max, Count, F from django.db.models.signals import post_save, post_delete, m2m_changed from django.db.utils import DatabaseError +from django.template import Context, Template from django.template.defaultfilters import slugify from django.utils.functional import lazy from ishtar_common.utils import ugettext_lazy as _, ugettext, \ @@ -2588,6 +2589,12 @@ post_delete.connect(post_save_cache, sender=SupportType) class Format(GeneralType): + iframe_template = models.TextField( + _("Iframe template"), blank=True, default="", + help_text=_("Template to insert an iframe for this format. Use django " + "template with a {{document}} variable matching the " + "current document.")) + class Meta: verbose_name = _("Format type") verbose_name_plural = _("Format types") @@ -2955,10 +2962,10 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel, source_free_input = models.CharField( verbose_name=_("Source - free input"), blank=True, null=True, max_length=500) - support_type = models.ForeignKey(SupportType, verbose_name=_("Support"), + support_type = models.ForeignKey(SupportType, verbose_name=_("Medium"), on_delete=models.SET_NULL, blank=True, null=True, ) - format_type = models.ForeignKey(Format, verbose_name=_("Medium"), + format_type = models.ForeignKey(Format, verbose_name=_("Format"), on_delete=models.SET_NULL, blank=True, null=True) scale = models.CharField(_("Scale"), max_length=30, null=True, @@ -3023,6 +3030,16 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel, return (self.external_id,) @property + def has_iframe(self): + return self.format_type and self.format_type.iframe_template + + def get_iframe(self): + if not self.has_iframe: + return "" + return Template(self.format_type.iframe_template).render( + Context({"document": self})) + + @property def container(self): if not self.container_id: return |