diff options
| -rw-r--r-- | archaeological_context_records/forms.py | 17 | ||||
| -rw-r--r-- | archaeological_context_records/migrations/0117_identification_m2m.py | 52 | ||||
| -rw-r--r-- | archaeological_context_records/models.py | 20 | ||||
| -rw-r--r-- | archaeological_context_records/templates/ishtar/sheet_contextrecord.html | 4 | ||||
| -rw-r--r-- | archaeological_context_records/tests/importer-GIS-UE.zip | bin | 18198 -> 5223 bytes | |||
| -rw-r--r-- | ishtar_common/fixtures/initial_importtypes-fr.json | 6 | ||||
| -rw-r--r-- | ishtar_common/fixtures/initial_importtypes-tests-fr.json | 4 | ||||
| -rw-r--r-- | ishtar_common/views_item.py | 2 | 
8 files changed, 80 insertions, 25 deletions
| diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 2ddb8c42d..3a04567ba 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -156,7 +156,7 @@ class RecordSelect(GeoItemSelect, PeriodSelect):      )      unit = forms.ChoiceField(label=_("Unit type"), choices=[])      activity = forms.ChoiceField(label=_("Activity"), choices=[]) -    identification = forms.ChoiceField(label=_("Identification"), choices=[]) +    identifications = forms.ChoiceField(label=_("Identification"), choices=[])      cultural_attributions = forms.ChoiceField(          label=_("Cultural attribution"), choices=[], required=False)      parcel = forms.CharField(label=_("Parcel")) @@ -173,7 +173,7 @@ class RecordSelect(GeoItemSelect, PeriodSelect):          FieldType("ope_relation_types", OpeRelationType),          FieldType("excavation_technics", models.ExcavationTechnicType),          FieldType("activity", models.ActivityType), -        FieldType("identification", models.IdentificationType), +        FieldType("identifications", models.IdentificationType),      ] + GeoItemSelect.TYPES      SITE_KEYS = {"archaeological_site": None} @@ -494,7 +494,7 @@ class RecordFormInterpretation(CustomForm, ManageOldType):      form_label = _("Interpretation")      form_admin_name = _("Context record - 040 - Interpretation")      form_slug = "contextrecord-040-interpretation" -    base_models = ["cultural_attribution"] +    base_models = ["cultural_attribution", "identification"]      associated_models = {          "activity": models.ActivityType, @@ -505,8 +505,10 @@ class RecordFormInterpretation(CustomForm, ManageOldType):          label=_("Interpretation"), widget=forms.Textarea, required=False      )      activity = forms.ChoiceField(label=_("Activity"), required=False, choices=[]) -    identification = forms.ChoiceField( -        label=_("Identification"), required=False, choices=[] +    identification = forms.MultipleChoiceField( +        label=_("Identification"), choices=[], +        widget=widgets.Select2Multiple, +        required=False      )      HEADERS['taq'] = FormHeader(_("Dating complements"))      taq = forms.IntegerField(label=_("TAQ"), required=False) @@ -516,14 +518,15 @@ class RecordFormInterpretation(CustomForm, ManageOldType):      cultural_attribution = forms.MultipleChoiceField(          label=_("Cultural attributions"), choices=[],          widget=widgets.Select2Multiple, -        required=False) +        required=False +    )      datings_comment = forms.CharField(          label=_("Comments on dating"), required=False, widget=forms.Textarea      )      TYPES = [          FieldType("activity", models.ActivityType), -        FieldType("identification", models.IdentificationType), +        FieldType("identification", models.IdentificationType, True),          FieldType('cultural_attribution', models.CulturalAttributionType,                    True),      ] diff --git a/archaeological_context_records/migrations/0117_identification_m2m.py b/archaeological_context_records/migrations/0117_identification_m2m.py new file mode 100644 index 000000000..0e91aa3e6 --- /dev/null +++ b/archaeological_context_records/migrations/0117_identification_m2m.py @@ -0,0 +1,52 @@ +# Generated by Django 2.2.24 on 2024-07-08 13:30 + +from django.db import migrations, models + + +def m2m_identification_type(apps, __): +    ContextRecord = apps.get_model("archaeological_context_records", "contextrecord") +    for cr in ContextRecord.objects.filter(identification__isnull=False).all(): +        cr.identifications.add(cr.identification) + + +SQL1 = """ +UPDATE ishtar_common_importtarget +    SET target='identifications' +WHERE target='identification'; +""" + +SQL2 = """ +UPDATE ishtar_common_formatertype +    SET many_split='&' +WHERE options='archaeological_context_records.models.IdentificationType'; +""" + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('archaeological_context_records', '0116_recordrelations_import_relationship'), +    ] + +    operations = [ +        migrations.AlterModelOptions( +            name='activitytype', +            options={'ordering': ('order', 'label'), 'verbose_name': 'Activity Type', 'verbose_name_plural': 'Activity Types'}, +        ), +        migrations.AddField( +            model_name='contextrecord', +            name='identifications', +            field=models.ManyToManyField(blank=True, related_name='context_records', to='archaeological_context_records.IdentificationType', verbose_name='Identification'), +        ), +        migrations.RunPython(m2m_identification_type), +        migrations.RemoveField( +            model_name='contextrecord', +            name='identification', +        ), +        migrations.RemoveField( +            model_name='historicalcontextrecord', +            name='identification', +        ), +        migrations.RunSQL(SQL1), +        migrations.RunSQL(SQL2), +    ] diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 0c245abd4..c41b691cf 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -520,7 +520,7 @@ class ContextRecord(              ("unit__label", _("Context record type")),              ("operation__cached_label", _("Operation")),              ("datings__period__label", _("Chronological period")), -            ("identification__label", _("Identification")), +            ("identifications__label", _("Identification")),              ("activity__label", _("Activity")),              ("excavation_technics__label", _("Excavation techniques")),              ("documents__source_type__label", _("Associated document type")), @@ -532,6 +532,7 @@ class ContextRecord(          "documentations",          "cultural_attributions",          "excavation_technics", +        "identifications"      ]      # search parameters @@ -614,10 +615,6 @@ class ContextRecord(          "activity": SearchAltName(              pgettext_lazy("key for text search", "activity"), "activity__label__iexact"          ), -        "identification": SearchAltName( -            pgettext_lazy("key for text search", "identification"), -            "identification__label__iexact" -        ),          "parcel": SearchAltName(              pgettext_lazy("key for text search", "parcel"),              "parcel__cached_label__iexact", @@ -637,6 +634,10 @@ class ContextRecord(              pgettext_lazy("key for text search", "cultural-attribution"),              "cultural_attributions__label__iexact",          ), +        "identifications": SearchAltName( +            pgettext_lazy("key for text search", "identification"), +            "identifications__label__iexact" +        ),      }      ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)      ALT_NAMES.update(DocumentItem.ALT_NAMES) @@ -653,13 +654,13 @@ class ContextRecord(          SearchVectorConfig("interpretation", "local"),          SearchVectorConfig("filling", "local"),          SearchVectorConfig("datings_comment", "local"), -        SearchVectorConfig("identification__label"),          SearchVectorConfig("unit__label"),          SearchVectorConfig("activity__label"),      ]      M2M_SEARCH_VECTORS = [          SearchVectorConfig("datings__period__label", "local"),          SearchVectorConfig("excavation_technics__label", "local"), +        SearchVectorConfig("identifications__label", "local"),      ]      UP_MODEL_QUERY = {          "operation": ( @@ -674,7 +675,7 @@ class ContextRecord(          ("site", "archaeological_site__pk"),          ("file", "operation__associated_file__pk"),      ] -    HISTORICAL_M2M = ["datings", "documentations", "excavation_technics"] +    HISTORICAL_M2M = ["datings", "documentations", "excavation_technics", "identifications"]      CACHED_LABELS = ["cached_label", "cached_periods", "cached_related_context_records"]      DOWN_MODEL_UPDATE = ["base_finds"] @@ -815,12 +816,11 @@ class ContextRecord(          null=True,          help_text=_('Estimation of a "Terminus Post Quem"'),      ) -    identification = models.ForeignKey( +    identifications = models.ManyToManyField(          IdentificationType,          blank=True, -        null=True, -        on_delete=models.SET_NULL,          verbose_name=_("Identification"), +        related_name="context_records",      )      activity = models.ForeignKey(          ActivityType, diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index 71207acca..2229c06cf 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -25,7 +25,7 @@  {% with display_relations=item|safe_or:"right_relations.count|left_relations.count" %}  {% with has_image=item|safe_or:"images.count" %}  {% with has_cultural_attributions=item|safe_or:"cultural_attributions.count" %} -{% with display_interpretation=item.activity|or_:item.identification|or_:item.interpretation %} +{% with display_interpretation=item.activity|safe_or:"item.identifications.count"|or_:item.interpretation %}  {% with display_datations=dating_list|or_:item.taq|or_:item.taq_estimated|or_:item.tpq|or_:item.tpq_estimated|or_:has_cultural_attributions %}  {% with can_view_finds=permission_view_own_find|or_:permission_view_find %}  {% with has_finds=item|safe_or:"base_finds.count" %} @@ -185,7 +185,7 @@          <h3>{% trans "Interpretation"%}</h3>          <div class='row'>              {% field_flex "Activity" item.activity %} -            {% field_flex "Identification" item.identification %} +            {% field_flex_multiple_obj "Identification" item 'identifications' %}              {% field_flex_full "Interpretation" item.interpretation "<pre>" "</pre>" %}          </div>      </div> diff --git a/archaeological_context_records/tests/importer-GIS-UE.zip b/archaeological_context_records/tests/importer-GIS-UE.zipBinary files differ index bd541051e..2c514a211 100644 --- a/archaeological_context_records/tests/importer-GIS-UE.zip +++ b/archaeological_context_records/tests/importer-GIS-UE.zip diff --git a/ishtar_common/fixtures/initial_importtypes-fr.json b/ishtar_common/fixtures/initial_importtypes-fr.json index 450883d08..c99d82da3 100644 --- a/ishtar_common/fixtures/initial_importtypes-fr.json +++ b/ishtar_common/fixtures/initial_importtypes-fr.json @@ -3263,7 +3263,7 @@      "fields": {          "formater_type": "TypeFormater",          "options": "archaeological_context_records.models.IdentificationType", -        "many_split": "" +        "many_split": "&"      }  },  { @@ -5628,11 +5628,11 @@              "ishtar-context-record",              21          ], -        "target": "identification", +        "target": "identifications",          "formater_type": [              "TypeFormater",              "archaeological_context_records.models.IdentificationType", -            "" +            "&"          ],          "force_new": false,          "concat": false, diff --git a/ishtar_common/fixtures/initial_importtypes-tests-fr.json b/ishtar_common/fixtures/initial_importtypes-tests-fr.json index 8088e9aae..eadf26ff5 100644 --- a/ishtar_common/fixtures/initial_importtypes-tests-fr.json +++ b/ishtar_common/fixtures/initial_importtypes-tests-fr.json @@ -1686,11 +1686,11 @@              "mcc-ue",              7          ], -        "target": "identification", +        "target": "identifications",          "formater_type": [              "TypeFormater",              "archaeological_context_records.models.IdentificationType", -            "" +            "&"          ],          "force_new": false,          "concat": false, diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index f26aa12e5..9e347a08d 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -561,7 +561,7 @@ HIERARCHIC_LEVELS = 5  LIST_FIELDS = {  # key: hierarchic depth      "conservatory_states": HIERARCHIC_LEVELS, -    "identification": HIERARCHIC_LEVELS, +    "identifications": HIERARCHIC_LEVELS,      "material_types": HIERARCHIC_LEVELS,      "material_type": HIERARCHIC_LEVELS,      "object_types": HIERARCHIC_LEVELS, | 
