From 715be2448ba981981216e0b3bc194e17699efd57 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 10 Nov 2020 11:07:20 +0100 Subject: Document: add iframe template for documents --- ishtar_common/forms_common.py | 2 +- .../migrations/0206_auto_20201110_1030.py | 36 ++++++++++++++++++++++ ishtar_common/models.py | 21 +++++++++++-- ishtar_common/templates/ishtar/sheet_document.html | 5 +-- 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 ishtar_common/migrations/0206_auto_20201110_1030.py (limited to 'ishtar_common') diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 66eabf833..19348ebff 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1281,7 +1281,7 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): model=models.SourceType, label=_("Type"), choices=[], required=False) support_type = widgets.ModelChoiceField( - model=models.SupportType, label=_("Support"), choices=[], + model=models.SupportType, label=_("Medium"), choices=[], required=False) format_type = widgets.ModelChoiceField( model=models.Format, label=_("Format"), choices=[], diff --git a/ishtar_common/migrations/0206_auto_20201110_1030.py b/ishtar_common/migrations/0206_auto_20201110_1030.py new file mode 100644 index 000000000..418066fc9 --- /dev/null +++ b/ishtar_common/migrations/0206_auto_20201110_1030.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.27 on 2020-11-10 10:30 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0205_auto_20201104_0959'), + ] + + operations = [ + migrations.AddField( + model_name='format', + name='iframe_template', + field=models.TextField(blank=True, default='', help_text='Template to insert an iframe for this format. Use django template with a {{document}} variable matching the current document.', verbose_name='Iframe template'), + ), + migrations.AlterField( + model_name='document', + name='format_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ishtar_common.Format', verbose_name='Format'), + ), + migrations.AlterField( + model_name='document', + name='support_type', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ishtar_common.SupportType', verbose_name='Medium'), + ), + migrations.AlterField( + model_name='import', + name='csv_sep', + field=models.CharField(choices=[(',', ','), (';', ';'), ('|', '|')], default=',', help_text='Separator for CSV file. Standard is comma but Microsoft Excel do not follow this standard and use semi-colon.', max_length=1, verbose_name='CSV separator'), + ), + ] 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, @@ -3022,6 +3029,16 @@ class Document(BaseHistorizedItem, CompleteIdentifierItem, OwnPerms, ImageModel, def natural_key(self): 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: diff --git a/ishtar_common/templates/ishtar/sheet_document.html b/ishtar_common/templates/ishtar/sheet_document.html index a9c6f807e..5aff68107 100644 --- a/ishtar_common/templates/ishtar/sheet_document.html +++ b/ishtar_common/templates/ishtar/sheet_document.html @@ -10,10 +10,11 @@ {% block general %} -{% if item.main_image %} +{% if item.main_image or item.has_iframe %}
{% include "ishtar/blocks/window_image.html" %} + {{ item.get_iframe }}
{% else %} @@ -53,7 +54,7 @@ {% field_flex_full "" item.authors|add_links:'person' %} {% endif %}
-{% if item.main_image %} +{% if item.main_image or has_iframe %}
{% endif %}
-- cgit v1.2.3