diff options
| -rw-r--r-- | archaeological_finds/templates/ishtar/sheet_find.html | 2 | ||||
| -rw-r--r-- | archaeological_warehouse/migrations/0033_auto_20190212_1524.py | 40 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 17 | ||||
| -rw-r--r-- | archaeological_warehouse/templates/ishtar/sheet_container.html | 52 | ||||
| -rw-r--r-- | ishtar_common/forms_common.py | 8 | ||||
| -rw-r--r-- | ishtar_common/models.py | 13 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/sheet_document.html | 1 | 
7 files changed, 98 insertions, 35 deletions
diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index 1af09b030..03295a8e2 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -89,8 +89,6 @@        <div class="clearfix">            <div class="card float-left col-12 col-md-6 col-lg-4">                {% include "ishtar/blocks/window_image.html" %} -              <div class="card-body"> -              </div>            </div>            {% endif %} 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 %} -<div class="row"> -    <div class="offset-lg-4 col-lg-4 offset-md-3 col-md-6 offset-sm-1 col-sm-10 col-12"> -        <div class="card"> -            {% include "ishtar/blocks/window_image.html" %} -            <div class="card-body"> -                <p class="card-text"> -                    <p class="window-refs">{{ item.reference|default:"" }}</p> -                    <p class="window-refs">{{ item.container_type|default:"" }}</p> -                    <p class="window-refs">{{ item.responsible.name }} - {{ item.index }}</p> -                    <p class="window-refs">{{ item.old_reference|default:"" }}</p> -                    {% include "ishtar/blocks/sheet_external_id.html" %} -                </p> -            </div> -        </div> +<div class="clearfix"> +    {% if item.main_image %} +    <div class="card float-left col-12 col-md-4"> +        {% include "ishtar/blocks/window_image.html" %} +    </div> +    {% endif %} +    {% if item.main_image %} +    <div class="float-left col-12 col-md-6 col-lg-8 text-center">{# </div>> #} +    {% else %} +    <div class="float-left col-6 col-md-3 text-center"> +    {% endif %} +        <p class="window-refs">{{ item.reference|default:"" }}</p> +        <p class="window-refs">{{ item.container_type|default:"" }}</p> +        <p class="window-refs">{{ item.responsible.name }} - {{ item.index }}</p> +        <p class="window-refs">{{ item.old_reference|default:"" }}</p> +        {% include "ishtar/blocks/sheet_external_id.html" %} +    </div> +    {% if item.main_image %} +    <div class="row float-left col-12 col-md-6 col-lg-8 text-center">{# </div>> #} +    {% else %} +    <div class="float-left row col-6 col-md-8"> +    {% 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 "<pre>" "</pre>" %} +        {% include "ishtar/blocks/sheet_json.html" %}      </div>  </div> -<div class="row"> -    {% 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 "<pre>" "</pre>" %} -</div> - -{% include "ishtar/blocks/sheet_json.html" %} -  {% if item.finds.count %}  <h4>{% trans "Content" %}</h4>  {% dynamic_table_document finds 'finds' 'container' item.pk 'TABLE_COLS' output 'large' %} diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 16c6d269e..fadda7593 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -51,6 +51,7 @@ from ishtar_common.utils import is_downloadable, clean_session_cache, \  from archaeological_operations.models import Operation  from archaeological_context_records.models import ContextRecord  from archaeological_finds.models import Find +from archaeological_warehouse.models import Container  def get_town_field(label=_(u"Town"), required=True): @@ -1270,6 +1271,12 @@ class DocumentSelect(TableSelect):          validators=[models.valid_id(Find)])      find__denomination = forms.CharField(label=_(u"Find - denomination"),                                           required=False) +    container = forms.IntegerField( +        label=_(u"Container"), required=False, +        widget=widgets.JQueryAutoComplete( +            reverse_lazy('autocomplete-container'), +            associated_model=Container), +        validators=[models.valid_id(Container)])      TYPES = [          FieldType('source_type', models.SourceType), @@ -1278,6 +1285,7 @@ class DocumentSelect(TableSelect):      PROFILE_FILTER = {          'context_record': ['context_record'],          'find': ['find'], +        'warehouse': ['container']      } diff --git a/ishtar_common/models.py b/ishtar_common/models.py index a37c1f6bc..b03604e26 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3831,12 +3831,12 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel):      # other will be symbolic links      RELATED_MODELS = [          'treatment_files', 'treatments', 'finds', 'context_records', -        'operations', 'sites', 'warehouses', 'files' +        'operations', 'sites', 'warehouses', 'containers', 'files'      ]      # same fields but in order for forms      RELATED_MODELS_ALT = [          'finds', 'context_records', 'operations', 'sites', 'files', -        'warehouses', 'treatments', 'treatment_files', +        'warehouses', 'containers', 'treatments', 'treatment_files',      ]      SLUG = 'document'      LINK_SPLIT = u"<||>" @@ -3926,6 +3926,10 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel):              pgettext_lazy("key for text search", u"file"),              'files__cached_label__iexact'          ), +        'container': SearchAltName( +            pgettext_lazy("key for text search", u"container"), +            'containers__cached_label__iexact' +        ),          'site': SearchAltName(              pgettext_lazy("key for text search", u"site"),              'sites__cached_label__iexact' @@ -3937,11 +3941,6 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel):      }      objects = ExternalIdManager() - -    RELATED_MODELS_ALT = [ -        'finds', 'context_records', 'operations', 'sites', 'files', -        'warehouses', 'treatments', 'treatment_files', -    ]      RELATIVE_SESSION_NAMES = [          ('find', 'finds__pk'),          ('contextrecord', 'context_records__pk'), diff --git a/ishtar_common/templates/ishtar/sheet_document.html b/ishtar_common/templates/ishtar/sheet_document.html index af94f8fbe..48d21ff00 100644 --- a/ishtar_common/templates/ishtar/sheet_document.html +++ b/ishtar_common/templates/ishtar/sheet_document.html @@ -57,6 +57,7 @@  {% field_flex_full "Treatments" item.treatments|add_links %}  {% field_flex_full "Treatment files" item.treatment_files|add_links %}  {% field_flex_full "Warehouses" item.warehouses|add_links %} +{% field_flex_full "Containers" item.containers|add_links %}  {% endif %}  {% endblock %}  | 
