diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-01 15:58:39 +0200 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-02 13:30:50 +0200 |
| commit | 205ad98138447af4b86cd11d38c3c382ea1656cd (patch) | |
| tree | 221ada912a6f6f74cfd4699b30bd0a2488b4a586 /archaeological_context_records | |
| parent | 986d6c2c372df1bf1962533e4a24080da4d79c8a (diff) | |
| download | Ishtar-205ad98138447af4b86cd11d38c3c382ea1656cd.tar.bz2 Ishtar-205ad98138447af4b86cd11d38c3c382ea1656cd.zip | |
♻ refactor dating fields searches
Diffstat (limited to 'archaeological_context_records')
| -rw-r--r-- | archaeological_context_records/forms.py | 45 | ||||
| -rw-r--r-- | archaeological_context_records/models.py | 10 |
2 files changed, 9 insertions, 46 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 93ff65c25..0e5b752eb 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -20,7 +20,6 @@ """ Context records forms definitions """ -from collections import OrderedDict from copy import copy from itertools import groupby @@ -54,6 +53,7 @@ from ishtar_common.forms import ( MultiSearchForm, LockForm, GeoItemSelect, + DatingSelect, QAForm, ) from ishtar_common.forms_common import get_town_field @@ -90,46 +90,7 @@ class OperationFormSelection(CustomForm, forms.Form): ) -class PeriodSelect(forms.Form): - datings__period = forms.ChoiceField(label=_("Dating - period"), choices=[]) - datings__precise_dating = forms.CharField(label=_("Dating - precise")) - datings__start_date = forms.IntegerField(label=_("Dating - start date")) - datings__end_date = forms.IntegerField(label=_("Dating - end date")) - datings__dating_type = forms.ChoiceField( - label=_("Dating - dating type"), choices=[] - ) - datings__quality = forms.ChoiceField(label=_("Dating - dating quality"), choices=[]) - TYPES = [ - FieldType("datings__period", Period), - FieldType("datings__dating_type", models.DatingType), - FieldType("datings__quality", models.DatingQuality), - ] - PERIOD_FIELDS = [ - "datings__period", - "datings__precise_dating", - "datings__start_date", - "datings__end_date", - "datings__dating_type", - "datings__quality", - ] - - def _reorder_period_fields(self, insert_period_after): - fields = OrderedDict() - for key in self.fields: - if key in self.PERIOD_FIELDS: - continue - fields[key] = self.fields[key] - if key == insert_period_after: - for period_key in self.PERIOD_FIELDS: - if period_key not in self.fields: - continue - fields[period_key] = self.fields[period_key] - if period_key in self.fields: - fields[period_key] = self.fields[period_key] - self.fields = fields - - -class RecordSelect(GeoItemSelect, PeriodSelect): +class RecordSelect(GeoItemSelect, DatingSelect): _model = models.ContextRecord form_admin_name = _("Context record - 001 - Search") form_slug = "contextrecord-001-search" @@ -192,7 +153,7 @@ class RecordSelect(GeoItemSelect, PeriodSelect): colors = forms.ChoiceField(label=_("Colors"), choices=[]) details_on_color = forms.CharField(label=_("Details on color")) - TYPES = PeriodSelect.TYPES + [ + TYPES = DatingSelect.TYPES + [ FieldType('area', Area), FieldType("periods", Period), FieldType('cultural_attributions', models.CulturalAttributionType), diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index d1b1fb147..6b6f0f039 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -440,8 +440,9 @@ class ContextRecord( "documents__associated_file__isnull", "documents__associated_url__isnull", ] - NUMBER_FIELDS = ["operation__year", "operation__operation_code", "datings__start_date", - "datings__end_date"] + GeographicSubTownItem.NUMBER_FIELDS + NUMBER_FIELDS = [ + "operation__year", "operation__operation_code" + ] + GeographicSubTownItem.NUMBER_FIELDS + BaseDating.NUMBER_FIELDS RELATION_TYPES_PREFIX = { "ope_relation_types": "operation__", @@ -486,9 +487,9 @@ class ContextRecord( pgettext_lazy("key for text search", "operation-relation-type"), "ope_relation_types", ), - "datings__period": SearchAltName( + "period": SearchAltName( pgettext_lazy("key for text search", "period"), - "datings__period__label__iexact", + "periods__label__iexact", ), "unit": SearchAltName( pgettext_lazy("key for text search", "unit-type"), "unit__label__iexact" @@ -573,6 +574,7 @@ class ContextRecord( ALT_NAMES.update(Dating.ASSOCIATED_ALT_NAMES) ALT_NAMES.update(GeoItem.ALT_NAMES) ALT_NAMES.update(Imported.ALT_NAMES) + ALT_NAMES.update(BaseDating.ALT_NAMES) DEFAULT_SEARCH_FORM = ("archaeological_context_records.forms", "RecordSelect") |
