summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/migrations/0053_auto_20181220_1539.py47
-rw-r--r--archaeological_finds/migrations/0054_migrate_main_image.py23
-rw-r--r--archaeological_finds/models_finds.py8
-rw-r--r--archaeological_finds/models_treatments.py18
-rw-r--r--archaeological_finds/templates/ishtar/sheet_find.html8
5 files changed, 97 insertions, 7 deletions
diff --git a/archaeological_finds/migrations/0053_auto_20181220_1539.py b/archaeological_finds/migrations/0053_auto_20181220_1539.py
new file mode 100644
index 000000000..a17fb75eb
--- /dev/null
+++ b/archaeological_finds/migrations/0053_auto_20181220_1539.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-12-20 15:39
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0079_migrate-importers'),
+ ('archaeological_finds', '0052_auto_20181211_1558'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='find',
+ name='main_image',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='main_image_finds', to='ishtar_common.Document', verbose_name='Main image'),
+ ),
+ migrations.AddField(
+ model_name='historicalfind',
+ name='main_image',
+ field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.Document'),
+ ),
+ migrations.AddField(
+ model_name='historicaltreatment',
+ name='main_image',
+ field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.Document'),
+ ),
+ migrations.AddField(
+ model_name='historicaltreatmentfile',
+ name='main_image',
+ field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ishtar_common.Document'),
+ ),
+ migrations.AddField(
+ model_name='treatment',
+ name='main_image',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='main_image_treatments', to='ishtar_common.Document', verbose_name='Main image'),
+ ),
+ migrations.AddField(
+ model_name='treatmentfile',
+ name='main_image',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='main_image_treatment_files', to='ishtar_common.Document', verbose_name='Main image'),
+ ),
+ ]
diff --git a/archaeological_finds/migrations/0054_migrate_main_image.py b/archaeological_finds/migrations/0054_migrate_main_image.py
new file mode 100644
index 000000000..1a7f942c4
--- /dev/null
+++ b/archaeological_finds/migrations/0054_migrate_main_image.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-12-20 19:12
+from __future__ import unicode_literals
+
+from django.db import migrations
+from ishtar_common.utils_migrations import migrate_main_image
+
+
+def migrate_main_image_script(apps, schema):
+ migrate_main_image(apps, 'archaeological_finds', 'Find')
+ migrate_main_image(apps, 'archaeological_finds', 'Treatment')
+ migrate_main_image(apps, 'archaeological_finds', 'TreatmentFile')
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_finds', '0053_auto_20181220_1539'),
+ ]
+
+ operations = [
+ migrations.RunPython(migrate_main_image_script)
+ ]
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 393583749..33ec2df0b 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -40,7 +40,7 @@ from ishtar_common.models import Document, GeneralType, \
HistoricalRecords, OwnPerms, Person, Basket, post_save_cache, \
ValueGetter, get_current_profile, IshtarSiteProfile, PRIVATE_FIELDS, \
SpatialReferenceSystem, BulkUpdatedItem, ExternalIdManager, QuickAction, \
- MainItem
+ MainItem, document_attached_changed
from archaeological_operations.models import AdministrativeAct, Operation
from archaeological_context_records.models import ContextRecord, Dating
@@ -1179,6 +1179,9 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,
documents = models.ManyToManyField(
Document, related_name='finds', verbose_name=_(u"Documents"),
blank=True)
+ main_image = models.ForeignKey(
+ Document, related_name='main_image_finds',
+ verbose_name=_(u"Main image"), blank=True, null=True)
treatments = models.ManyToManyField(
"Treatment", verbose_name=_(u"Treatments"),
related_name='finds', blank=True,
@@ -1954,6 +1957,9 @@ def base_find_find_changed(sender, **kwargs):
m2m_changed.connect(base_find_find_changed, sender=Find.base_finds.through)
+m2m_changed.connect(document_attached_changed,
+ sender=Find.documents.through)
+
class Property(LightHistorizedItem):
find = models.ForeignKey(Find, verbose_name=_(u"Find"))
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index 06f61068b..64bad203d 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -23,7 +23,8 @@ from django.conf import settings
from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
from django.db.models import Max, Q
-from django.db.models.signals import post_save, post_delete, pre_delete
+from django.db.models.signals import post_save, post_delete, pre_delete, \
+ m2m_changed
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _, pgettext_lazy, \
activate, deactivate
@@ -35,7 +36,7 @@ from archaeological_warehouse.models import Warehouse, Container
from ishtar_common.models import Document, GeneralType, \
ImageModel, BaseHistorizedItem, OwnPerms, HistoricalRecords, Person, \
Organization, ValueGetter, post_save_cache, ShortMenuItem, \
- DashboardFormItem, ExternalIdManager
+ DashboardFormItem, ExternalIdManager, document_attached_changed
from ishtar_common.utils import cached_label_changed, get_current_year, \
update_data
@@ -179,6 +180,9 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem,
documents = models.ManyToManyField(
Document, related_name='treatments', verbose_name=_(u"Documents"),
blank=True)
+ main_image = models.ForeignKey(
+ Document, related_name='main_image_treatments',
+ verbose_name=_(u"Main image"), blank=True, null=True)
cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,
db_index=True)
history = HistoricalRecords()
@@ -579,6 +583,9 @@ def pre_delete_treatment(sender, **kwargs):
pre_delete.connect(pre_delete_treatment, sender=Treatment)
+m2m_changed.connect(document_attached_changed,
+ sender=Treatment.documents.through)
+
class AbsFindTreatments(models.Model):
find = models.ForeignKey(Find, verbose_name=_(u"Find"),
@@ -847,6 +854,9 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem,
documents = models.ManyToManyField(
Document, related_name='treatment_files', verbose_name=_(u"Documents"),
blank=True)
+ main_image = models.ForeignKey(
+ Document, related_name='main_image_treatment_files',
+ verbose_name=_(u"Main image"), blank=True, null=True)
associated_basket = models.ForeignKey(
FindBasket, null=True, blank=True, on_delete=models.SET_NULL,
related_name='treatment_files'
@@ -956,4 +966,8 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem,
super(TreatmentFile, self).save(*args, **kwargs)
+
+m2m_changed.connect(document_attached_changed,
+ sender=TreatmentFile.documents.through)
+
post_save.connect(cached_label_changed, sender=TreatmentFile)
diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html
index 7171c3deb..cfbefa306 100644
--- a/archaeological_finds/templates/ishtar/sheet_find.html
+++ b/archaeological_finds/templates/ishtar/sheet_find.html
@@ -81,8 +81,8 @@
<div class="tab-pane fade show active" id="{{window_id}}-basefind"
role="tabpanel" aria-labelledby="{{window_id}}-basefind-tab">
- {% with nb_image=item.images.count %}
- {% if nb_image %}
+ {% with has_image=item.main_image %}
+ {% if has_image %}
<div class="clearfix">
<div class="card float-left col-12 col-md-6 col-lg-4">
{% include "ishtar/blocks/window_image.html" %}
@@ -105,12 +105,12 @@
<div class="tab-content">
{% for base_find in item.base_finds.all %}
- {% with first=forloop.first|add:nb_image %}
+ {% with first=forloop.first|add:has_image %}
{% include "ishtar/sheet_basefind.html" %}
{% endwith %}
{% endfor %}
</div>
- {% if nb_image %}
+ {% if has_image %}
</div>
{% endif %}
{% endwith %}