diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-11-10 11:07:20 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:21 +0100 |
commit | 715be2448ba981981216e0b3bc194e17699efd57 (patch) | |
tree | c68d3be460d2d9e5d5119564ada092084a7aa8c2 /ishtar_common | |
parent | ddccc8af774abd592a38aa5ed70975a1168720c5 (diff) | |
download | Ishtar-715be2448ba981981216e0b3bc194e17699efd57.tar.bz2 Ishtar-715be2448ba981981216e0b3bc194e17699efd57.zip |
Document: add iframe template for documents
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms_common.py | 2 | ||||
-rw-r--r-- | ishtar_common/migrations/0206_auto_20201110_1030.py | 36 | ||||
-rw-r--r-- | ishtar_common/models.py | 21 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_document.html | 5 |
4 files changed, 59 insertions, 5 deletions
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, @@ -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 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 %} <div class="clearfix"> <div class="card float-left col-12 col-md-4"> {% include "ishtar/blocks/window_image.html" %} + {{ item.get_iframe }} </div> <div class="row float-left col-12 col-md-6 col-lg-8 text-center"> {% else %} @@ -53,7 +54,7 @@ {% field_flex_full "" item.authors|add_links:'person' %} {% endif %} </div> -{% if item.main_image %} +{% if item.main_image or has_iframe %} </div> {% endif %} <div class="row"> |