summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/forms_treatments.py10
-rw-r--r--archaeological_finds/migrations/0134_other_reference_rename_find_treatment_imports.py54
-rw-r--r--archaeological_finds/models_finds.py32
-rw-r--r--archaeological_finds/models_treatments.py14
-rw-r--r--archaeological_operations/models.py4
-rw-r--r--ishtar_common/admin.py2
-rw-r--r--ishtar_common/data_importer.py5
-rw-r--r--ishtar_common/models.py2
8 files changed, 104 insertions, 19 deletions
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index c624ebfc6..e8b6599ea 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -55,7 +55,7 @@ class TreatmentSelect(DocumentItemSelect):
))
label = forms.CharField(label=_("Label"))
- other_reference = forms.CharField(label=_("Other ref."))
+ reference = forms.CharField(label=_("Reference"))
year = forms.IntegerField(label=_("Year"))
index = forms.IntegerField(label=_("Index"))
scientific_monitoring_manager = forms.IntegerField(
@@ -174,8 +174,8 @@ class BaseTreatmentForm(CustomForm, ManageOldType):
validators=[valid_id(Organization)], required=False)
label = forms.CharField(label=_("Label"),
max_length=200, required=False)
- other_reference = forms.CharField(
- label=_("Other ref."), max_length=200, required=False)
+ reference = forms.CharField(
+ label=_("Reference"), max_length=200, required=False)
# external_id = forms.CharField(
# label=_("External ref."), max_length=200, required=False)
start_date = DateField(label=_("Start date"), required=False,
@@ -583,8 +583,8 @@ class AdministrativeActTreatmentSelect(TableSelect):
label=_("Treatment name"), max_length=200)
treatment__year = forms.IntegerField(label=_("Treatment year"))
treatment__index = forms.IntegerField(label=_("Treatment index"))
- treatment__other_reference = forms.CharField(
- max_length=200, label=_("Treatment internal reference"))
+ treatment__reference = forms.CharField(
+ max_length=200, label=_("Treatment reference"))
treatment__treatment_types = forms.ChoiceField(label=_("Treatment type"),
choices=[])
history_modifier = forms.IntegerField(
diff --git a/archaeological_finds/migrations/0134_other_reference_rename_find_treatment_imports.py b/archaeological_finds/migrations/0134_other_reference_rename_find_treatment_imports.py
new file mode 100644
index 000000000..1b3354256
--- /dev/null
+++ b/archaeological_finds/migrations/0134_other_reference_rename_find_treatment_imports.py
@@ -0,0 +1,54 @@
+# Generated by Django 2.2.24 on 2025-01-23 11:54
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0259_ishtarsiteprofile_default_location_for_treatment'),
+ ('archaeological_finds', '0133_exhibition'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='historicaltreatment',
+ name='reference',
+ field=models.CharField(blank=True, max_length=200, null=True, verbose_name='Reference'),
+ ),
+ migrations.AddField(
+ model_name='treatment',
+ name='reference',
+ field=models.CharField(blank=True, max_length=200, null=True, verbose_name='Reference'),
+ ),
+ migrations.RunSQL("UPDATE archaeological_finds_treatment set reference=other_reference;"),
+ migrations.RunSQL("UPDATE archaeological_finds_historicaltreatment set reference=other_reference;"),
+ migrations.RemoveField(
+ model_name='historicaltreatment',
+ name='other_reference',
+ ),
+ migrations.RemoveField(
+ model_name='treatment',
+ name='other_reference',
+ ),
+ migrations.AddField(
+ model_name='findtreatment',
+ name='imports',
+ field=models.ManyToManyField(blank=True, related_name='imported_archaeological_finds_findtreatment', to='ishtar_common.Import', verbose_name='Created by imports'),
+ ),
+ migrations.AddField(
+ model_name='findtreatment',
+ name='imports_updated',
+ field=models.ManyToManyField(blank=True, related_name='import_updated_archaeological_finds_findtreatment', to='ishtar_common.Import', verbose_name='Updated by imports'),
+ ),
+ migrations.AddField(
+ model_name='findtreatment',
+ name='timestamp_geo',
+ field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp geo'),
+ ),
+ migrations.AddField(
+ model_name='findtreatment',
+ name='timestamp_label',
+ field=models.IntegerField(blank=True, null=True, verbose_name='Timestamp label'),
+ ),
+ ]
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 68d49dfd6..fa0a9df9d 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -71,7 +71,7 @@ from ishtar_common.models import (
SearchVectorConfig,
ValueGetter,
)
-from ishtar_common.models_common import HistoricalRecords, SerializeItem, \
+from ishtar_common.models_common import HistoricalRecords, Imported, SerializeItem, \
GeoVectorData, geodata_attached_changed
from ishtar_common.utils import PRIVATE_FIELDS
@@ -2476,6 +2476,31 @@ class Find(
def has_packaging_for_current_container(self):
return FindTreatment.objects.filter(find=self, location_type__in=["B", "C"])
+ @staticmethod
+ def _get_upstream_count(upstream_id, idx):
+ if not upstream_id:
+ return idx
+ q = Find.objects.filter(downstream_treatment_id=upstream_id)
+ if not q.exists(): # upstream find has been deleted?
+ return idx
+ idx += 1
+ upstream_ids = q.values_list("upstream_treatment_id", flat=True)
+ return max([Find._get_upstream_count(up_id, idx) for up_id in upstream_ids])
+
+ @property
+ def upstream_count(self):
+ """
+ Count upstream treatments. Get the maximum count. If equal to 0 return None.
+ Used mainly to generate IDs
+ """
+ if not self.id:
+ return
+ if not hasattr(self, "_cache_upstream_count"):
+ self._cache_upstream_count = Find._get_upstream_count(
+ self.upstream_treatment_id, 0
+ ) or None
+ return self._cache_upstream_count
+
@property
def has_packaging_for_reference_container(self):
return FindTreatment.objects.filter(find=self, location_type__in=["B", "R"])
@@ -3717,7 +3742,7 @@ LOCATION_TYPE = [
LOCATION_TYPE_DICT = dict(LOCATION_TYPE)
-class FindTreatment(models.Model):
+class FindTreatment(Imported):
"""
Record all new location for a find.
"""
@@ -3740,6 +3765,9 @@ class FindTreatment(models.Model):
verbose_name_plural = _("Find - Treatments")
db_table = 'archaeological_finds_find_treatments'
+ def __str__(self):
+ return f"{self.treatment} / {self.find}"
+
def location_type_label(self):
if self.location_type in LOCATION_TYPE_DICT:
return LOCATION_TYPE_DICT[self.location_type]
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index 63ab10896..00c5b4785 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -211,9 +211,9 @@ class Treatment(
"label": SearchAltName(
pgettext_lazy("key for text search", "label"), "label__iexact"
),
- "other_reference": SearchAltName(
- pgettext_lazy("key for text search", "other-reference"),
- "other_reference__iexact",
+ "reference": SearchAltName(
+ pgettext_lazy("key for text search", "reference"),
+ "reference__iexact",
),
"year": SearchAltName(pgettext_lazy("key for text search", "year"), "year"),
"index": SearchAltName(pgettext_lazy("key for text search", "index"), "index"),
@@ -242,7 +242,7 @@ class Treatment(
SearchVectorConfig("external_id"),
SearchVectorConfig("comment", "local"),
SearchVectorConfig("description", "local"),
- SearchVectorConfig("other_reference"),
+ SearchVectorConfig("reference"),
]
PROPERTY_SEARCH_VECTORS = [
SearchVectorConfig("year_index"),
@@ -270,8 +270,8 @@ class Treatment(
objects = ExternalIdManager()
label = models.CharField(_("Label"), blank=True, null=True, max_length=200)
- other_reference = models.CharField(
- _("Other ref."), blank=True, null=True, max_length=200
+ reference = models.CharField(
+ _("Reference"), blank=True, null=True, max_length=200
)
year = models.IntegerField(_("Year"), default=get_current_year)
index = models.IntegerField(_("Index"), default=1)
@@ -440,7 +440,7 @@ class Treatment(
return label
items = [
str(getattr(self, k))
- for k in ["year", "index", "other_reference", "label"]
+ for k in ["year", "index", "reference", "label"]
if getattr(self, k)
]
return "{} | {}".format("-".join(items), self.treatment_types_lbl())
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index fa5abce22..81a8a8ecb 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -3029,9 +3029,9 @@ class AdministrativeAct(DocumentItem, BaseHistorizedItem, OwnPerms, ValueGetter,
pgettext_lazy("key for text search", "treatment-name"),
"treatment__label__icontains",
),
- "treatment__other_reference": SearchAltName(
+ "treatment__reference": SearchAltName(
pgettext_lazy("key for text search", "treatment-reference"),
- "treatment__other_reference__icontains",
+ "treatment__reference__icontains",
),
"treatment__year": SearchAltName(
pgettext_lazy("key for text search", "treatment-year"), "treatment__year"
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index cc26d6253..7b1aa48d4 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -2129,7 +2129,7 @@ serialize_importer_group_action.short_description = SERIALIZE_DESC
@admin.register(models.ImporterGroup, site=admin_site)
-class ImporterTypeAdmin(admin.ModelAdmin):
+class ImporterGroupAdmin(ImportJSONActionAdmin):
list_display = ("name", "importer_types_label", "available")
actions = [
serialize_importer_group_action,
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 7717c0e03..defea4da8 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -1315,6 +1315,9 @@ class Importer(object):
if self.import_instance:
self.import_instance.add_imported_line(self.idx_line)
+ if not obj:
+ return
+
if self.import_instance:
if created:
obj.imports.add(self.import_instance)
@@ -2137,7 +2140,7 @@ class Importer(object):
and type(new_val) == str
):
updated_dct[k] = val + "\n" + new_val
- else:
+ elif "defaults" in dct:
for k in dct["defaults"]:
new_val = dct["defaults"][k]
if new_val is None or new_val == "":
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 9197a67bf..5b4620254 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1388,7 +1388,7 @@ class IshtarSiteProfile(models.Model, Cached):
)
find_external_id = models.TextField(
_("Find external id"),
- default="{get_first_base_find__context_record__external_id}-{label}",
+ default="{{get_first_base_find__context_record__external_id}}-{{label}}{% if upstream_count %}-{{upstream_count}}{% endif %}",
help_text=_(
"Formula to manage find external ID. "
"Change this with care. With incorrect formula, the "