From 596c193c38c5eef0ad0798d690e65215744346bf Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 12 Feb 2019 15:46:33 +0100 Subject: Add documents to containers --- .../migrations/0033_auto_20190212_1524.py | 40 +++++++++++++++++ archaeological_warehouse/models.py | 17 ++++++- .../templates/ishtar/sheet_container.html | 52 ++++++++++++---------- 3 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 archaeological_warehouse/migrations/0033_auto_20190212_1524.py (limited to 'archaeological_warehouse') diff --git a/archaeological_warehouse/migrations/0033_auto_20190212_1524.py b/archaeological_warehouse/migrations/0033_auto_20190212_1524.py new file mode 100644 index 000000000..0af79c8bd --- /dev/null +++ b/archaeological_warehouse/migrations/0033_auto_20190212_1524.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2019-02-12 15:24 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0084_auto_20190206_1522'), + ('archaeological_warehouse', '0032_auto_20190206_1442'), + ] + + operations = [ + migrations.RemoveField( + model_name='container', + name='image', + ), + migrations.RemoveField( + model_name='container', + name='thumbnail', + ), + migrations.AddField( + model_name='container', + name='documents', + field=models.ManyToManyField(blank=True, related_name='containers', to='ishtar_common.Document', verbose_name='Documents'), + ), + migrations.AddField( + model_name='container', + name='main_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='main_image_containers', to='ishtar_common.Document', verbose_name='Image principale'), + ), + migrations.AlterField( + model_name='warehouse', + name='main_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='main_image_warehouses', to='ishtar_common.Document', verbose_name='Image principale'), + ), + ] diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index a0da12601..42a9bb310 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -30,7 +30,7 @@ from django.utils.translation import ugettext_lazy as _, pgettext_lazy from ishtar_common.data_importer import post_importer_action from ishtar_common.models import Document, GeneralType, get_external_id, \ LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \ - ImageModel, DashboardFormItem, ExternalIdManager, ShortMenuItem, \ + DashboardFormItem, ExternalIdManager, ShortMenuItem, \ document_attached_changed, SearchAltName from ishtar_common.utils import cached_label_changed @@ -316,7 +316,7 @@ post_save.connect(post_save_cache, sender=ContainerType) post_delete.connect(post_save_cache, sender=ContainerType) -class Container(LightHistorizedItem, ImageModel, OwnPerms): +class Container(LightHistorizedItem, OwnPerms): SLUG = 'container' SHOW_URL = 'show-container' TABLE_COLS = ['reference', 'container_type__label', 'cached_location', @@ -393,6 +393,13 @@ class Container(LightHistorizedItem, ImageModel, OwnPerms): external_id = models.TextField(_(u"External ID"), blank=True, null=True) auto_external_id = models.BooleanField( _(u"External ID is set automatically"), default=False) + documents = models.ManyToManyField( + Document, related_name='containers', verbose_name=_(u"Documents"), + blank=True) + main_image = models.ForeignKey( + Document, related_name='main_image_containers', + on_delete=models.SET_NULL, + verbose_name=_(u"Main image"), blank=True, null=True) class Meta: verbose_name = _(u"Container") @@ -431,6 +438,9 @@ class Container(LightHistorizedItem, ImageModel, OwnPerms): ] return u" | ".join(locas) + def _get_base_image_path(self): + return self.responsible._get_base_image_path() + u"/" + self.external_id + @classmethod def get_query_owns(cls, ishtaruser): return Q(history_creator=ishtaruser.user_ptr) | \ @@ -631,6 +641,9 @@ class Container(LightHistorizedItem, ImageModel, OwnPerms): post_save.connect(cached_label_changed, sender=Container) +m2m_changed.connect(document_attached_changed, + sender=Container.documents.through) + class ContainerLocalisation(models.Model): container = models.ForeignKey(Container, verbose_name=_(u"Container"), diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index 262d7145b..27cbf9bee 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -8,34 +8,38 @@ {% endblock %} {% block content %} -
-
-
- {% include "ishtar/blocks/window_image.html" %} -
-

-

{{ item.reference|default:"" }}

-

{{ item.container_type|default:"" }}

-

{{ item.responsible.name }} - {{ item.index }}

-

{{ item.old_reference|default:"" }}

- {% include "ishtar/blocks/sheet_external_id.html" %} -

-
-
+
+ {% if item.main_image %} +
+ {% include "ishtar/blocks/window_image.html" %} +
+ {% endif %} + {% if item.main_image %} +
{#
> #} + {% else %} +
+ {% endif %} +

{{ item.reference|default:"" }}

+

{{ item.container_type|default:"" }}

+

{{ item.responsible.name }} - {{ item.index }}

+

{{ item.old_reference|default:"" }}

+ {% include "ishtar/blocks/sheet_external_id.html" %} +
+ {% if item.main_image %} +
{#
> #} + {% else %} +
+ {% endif %} + {% field_flex_detail "Responsible warehouse" item.responsible %} + {% field_flex_detail "Location (warehouse)" item.location %} + {% include "ishtar/blocks/sheet_creation_section.html" %} + {% field_flex "Location" item.precise_location %} + {% field_flex_full "Comment" item.comment "
" "
" %} + {% include "ishtar/blocks/sheet_json.html" %}
-
- {% field_flex_detail "Responsible warehouse" item.responsible %} - {% field_flex_detail "Location (warehouse)" item.location %} - {% include "ishtar/blocks/sheet_creation_section.html" %} - {% field_flex "Location" item.precise_location %} - {% field_flex_full "Comment" item.comment "
" "
" %} -
- -{% include "ishtar/blocks/sheet_json.html" %} - {% if item.finds.count %}

{% trans "Content" %}

{% dynamic_table_document finds 'finds' 'container' item.pk 'TABLE_COLS' output 'large' %} -- cgit v1.2.3