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 | |
parent | ddccc8af774abd592a38aa5ed70975a1168720c5 (diff) | |
download | Ishtar-715be2448ba981981216e0b3bc194e17699efd57.tar.bz2 Ishtar-715be2448ba981981216e0b3bc194e17699efd57.zip |
Document: add iframe template for documents
-rw-r--r-- | archaeological_warehouse/migrations/0102_auto_20200324_1142.py | 100 | ||||
-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 |
5 files changed, 59 insertions, 105 deletions
diff --git a/archaeological_warehouse/migrations/0102_auto_20200324_1142.py b/archaeological_warehouse/migrations/0102_auto_20200324_1142.py deleted file mode 100644 index 4006a9701..000000000 --- a/archaeological_warehouse/migrations/0102_auto_20200324_1142.py +++ /dev/null @@ -1,100 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.27 on 2020-03-24 11:42 -from __future__ import unicode_literals - -from django.conf import settings -import django.contrib.gis.db.models.fields -import django.contrib.postgres.fields.jsonb -import django.contrib.postgres.search -from django.db import migrations, models -import django.db.models.deletion -import simple_history.models -import uuid - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('ishtar_common', '0202_auto_20200129_1941'), - ('archaeological_warehouse', '0101_squashed'), - ] - - operations = [ - migrations.CreateModel( - name='HistoricalWarehouse', - fields=[ - ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), - ('data', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default={})), - ('search_vector', django.contrib.postgres.search.SearchVectorField(blank=True, help_text='Auto filled at save', null=True, verbose_name='Search vector')), - ('qrcode', models.TextField(blank=True, max_length=255, null=True)), - ('x', models.FloatField(blank=True, null=True, verbose_name='X')), - ('y', models.FloatField(blank=True, null=True, verbose_name='Y')), - ('z', models.FloatField(blank=True, null=True, verbose_name='Z')), - ('estimated_error_x', models.FloatField(blank=True, null=True, verbose_name='Estimated error for X')), - ('estimated_error_y', models.FloatField(blank=True, null=True, verbose_name='Estimated error for Y')), - ('estimated_error_z', models.FloatField(blank=True, null=True, verbose_name='Estimated error for Z')), - ('point', django.contrib.gis.db.models.fields.PointField(blank=True, dim=3, null=True, srid=4326, verbose_name='Point')), - ('point_2d', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326, verbose_name='Point (2D)')), - ('point_source', models.CharField(blank=True, choices=[('T', 'Town'), ('P', 'Precise'), ('M', 'Polygon')], max_length=1, null=True, verbose_name='Point source')), - ('point_source_item', models.CharField(blank=True, max_length=100, null=True, verbose_name='Point source item')), - ('multi_polygon', django.contrib.gis.db.models.fields.MultiPolygonField(blank=True, null=True, srid=4326, verbose_name='Multi polygon')), - ('multi_polygon_source', models.CharField(blank=True, choices=[('T', 'Town'), ('P', 'Precise'), ('M', 'Polygon')], max_length=1, null=True, verbose_name='Multi-polygon source')), - ('multi_polygon_source_item', models.CharField(blank=True, max_length=100, null=True, verbose_name='Multi polygon source item')), - ('last_modified', models.DateTimeField(blank=True, editable=False)), - ('history_m2m', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default={})), - ('need_update', models.BooleanField(default=False, verbose_name='Need update')), - ('locked', models.BooleanField(default=False, verbose_name='Item locked for edition')), - ('address', models.TextField(blank=True, null=True, verbose_name='Address')), - ('address_complement', models.TextField(blank=True, null=True, verbose_name='Address complement')), - ('postal_code', models.CharField(blank=True, max_length=10, null=True, verbose_name='Postal code')), - ('town', models.CharField(blank=True, max_length=150, null=True, verbose_name='Town (freeform)')), - ('country', models.CharField(blank=True, max_length=30, null=True, verbose_name='Country')), - ('alt_address', models.TextField(blank=True, null=True, verbose_name='Other address: address')), - ('alt_address_complement', models.TextField(blank=True, null=True, verbose_name='Other address: address complement')), - ('alt_postal_code', models.CharField(blank=True, max_length=10, null=True, verbose_name='Other address: postal code')), - ('alt_town', models.CharField(blank=True, max_length=70, null=True, verbose_name='Other address: town')), - ('alt_country', models.CharField(blank=True, max_length=30, null=True, verbose_name='Other address: country')), - ('phone', models.CharField(blank=True, max_length=18, null=True, verbose_name='Phone')), - ('phone_desc', models.CharField(blank=True, max_length=300, null=True, verbose_name='Phone description')), - ('phone2', models.CharField(blank=True, max_length=18, null=True, verbose_name='Phone description 2')), - ('phone_desc2', models.CharField(blank=True, max_length=300, null=True, verbose_name='Phone description 2')), - ('phone3', models.CharField(blank=True, max_length=18, null=True, verbose_name='Phone 3')), - ('phone_desc3', models.CharField(blank=True, max_length=300, null=True, verbose_name='Phone description 3')), - ('raw_phone', models.TextField(blank=True, null=True, verbose_name='Raw phone')), - ('mobile_phone', models.CharField(blank=True, max_length=18, null=True, verbose_name='Mobile phone')), - ('email', models.EmailField(blank=True, max_length=300, null=True, verbose_name='Email')), - ('alt_address_is_prefered', models.BooleanField(default=False, verbose_name='Alternative address is prefered')), - ('uuid', models.UUIDField(default=uuid.uuid4)), - ('name', models.CharField(max_length=200, verbose_name='Name')), - ('comment', models.TextField(blank=True, null=True, verbose_name='Comment')), - ('external_id', models.TextField(blank=True, null=True, verbose_name='External ID')), - ('auto_external_id', models.BooleanField(default=False, verbose_name='External ID is set automatically')), - ('history_id', models.AutoField(primary_key=True, serialize=False)), - ('history_date', models.DateTimeField()), - ('history_change_reason', models.CharField(max_length=100, null=True)), - ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), - ('history_creator', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Creator')), - ('history_modifier', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Last editor')), - ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), - ('lock_user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Locked by')), - ('main_image', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.Document', verbose_name='Main image')), - ('organization', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.Organization', verbose_name='Organization')), - ('person_in_charge', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.Person', verbose_name='Person in charge')), - ('precise_town', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.Town', verbose_name='Town (precise)')), - ('spatial_reference_system', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.SpatialReferenceSystem', verbose_name='Spatial Reference System')), - ('warehouse_type', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_warehouse.WarehouseType', verbose_name='Warehouse type')), - ], - options={ - 'verbose_name': 'historical Warehouse', - 'ordering': ('-history_date', '-history_id'), - 'get_latest_by': 'history_date', - }, - bases=(simple_history.models.HistoricalChanges, models.Model), - ), - migrations.AddField( - model_name='container', - name='parent', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_warehouse.Container', verbose_name='Parent container'), - ), - ] 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"> |