summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-11-02 16:03:26 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:19 +0100
commit49baa55756d8f6427f382c327ec7fe233b2c05d3 (patch)
tree5888b277c026e0c6e9209472f016055ba73d77c4
parent4ed26f54bde75a1a392b717d5306a3f59802206b (diff)
downloadIshtar-49baa55756d8f6427f382c327ec7fe233b2c05d3.tar.bz2
Ishtar-49baa55756d8f6427f382c327ec7fe233b2c05d3.zip
Geodata - search: add search fields on related items searches
-rw-r--r--archaeological_context_records/forms.py6
-rw-r--r--archaeological_context_records/models.py1
-rw-r--r--archaeological_finds/forms.py6
-rw-r--r--archaeological_finds/models_finds.py2
-rw-r--r--archaeological_operations/forms.py12
-rw-r--r--archaeological_operations/models.py2
-rw-r--r--ishtar_common/forms.py21
-rw-r--r--ishtar_common/models_common.py25
8 files changed, 63 insertions, 12 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index 8d05e50e1..27900ef80 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -52,7 +52,7 @@ from ishtar_common.forms import (
HistorySelect,
MultiSearchForm,
LockForm,
- DocumentItemSelect,
+ GeoItemSelect,
QAForm,
)
from ishtar_common.forms_common import get_town_field
@@ -133,7 +133,7 @@ class PeriodSelect(forms.Form):
self.fields = fields
-class RecordSelect(DocumentItemSelect, PeriodSelect):
+class RecordSelect(GeoItemSelect, PeriodSelect):
_model = models.ContextRecord
form_admin_name = _("Context record - 001 - Search")
form_slug = "contextrecord-001-search"
@@ -177,7 +177,7 @@ class RecordSelect(DocumentItemSelect, PeriodSelect):
FieldType("cr_relation_types", models.RelationType),
FieldType("ope_relation_types", OpeRelationType),
FieldType("excavation_technics", models.ExcavationTechnicType),
- ]
+ ] + GeoItemSelect.TYPES
SITE_KEYS = {"archaeological_site": None}
def __init__(self, *args, **kwargs):
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 09733b566..da6b3b86a 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -631,6 +631,7 @@ class ContextRecord(
ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)
ALT_NAMES.update(DocumentItem.ALT_NAMES)
ALT_NAMES.update(Dating.ASSOCIATED_ALT_NAMES)
+ ALT_NAMES.update(GeoItem.ALT_NAMES)
PARENT_ONLY_SEARCH_VECTORS = ["operation", "archaeological_site", "parcel"]
BASE_SEARCH_VECTORS = [
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index fc1816d32..5a6e066ea 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -90,7 +90,7 @@ from ishtar_common.forms import (
QAForm,
MultiSearchForm,
LockForm,
- DocumentItemSelect,
+ GeoItemSelect,
)
from ishtar_common.forms_common import get_town_field
from archaeological_context_records.forms import PeriodSelect
@@ -1277,7 +1277,7 @@ DatingFormSet.form_admin_name = _("Find - 040 - Dating")
DatingFormSet.form_slug = "find-040-dating"
-class FindSelect(DocumentItemSelect, PeriodSelect):
+class FindSelect(GeoItemSelect, PeriodSelect):
_model = models.Find
form_admin_name = _("Find - 001 - Search")
form_slug = "find-001-search"
@@ -1646,7 +1646,7 @@ class FindSelect(DocumentItemSelect, PeriodSelect):
FieldType("alteration_causes", models.AlterationCauseType),
FieldType("treatment_emergency", models.TreatmentEmergencyType),
FieldType("cultural_attributions", CulturalAttributionType),
- ]
+ ] + GeoItemSelect.TYPES
SITE_KEYS = {
"archaeological_sites": "attached-to-operation",
"archaeological_sites_name": "name-attached-to-operation",
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index d53f45fdb..04af22d21 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -65,6 +65,7 @@ from ishtar_common.models import (
CompleteIdentifierItem,
SearchVectorConfig,
DocumentItem,
+ GeoItem
)
from ishtar_common.models_common import HistoricalRecords, SerializeItem, \
GeoVectorData, geodata_attached_changed
@@ -1624,6 +1625,7 @@ class Find(
ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)
ALT_NAMES.update(DocumentItem.ALT_NAMES)
ALT_NAMES.update(Dating.ASSOCIATED_ALT_NAMES)
+ ALT_NAMES.update(GeoItem.ALT_NAMES_FOR_FIND())
"""
# kept as an example
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 4609813b8..b4822e496 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -42,7 +42,7 @@ from ishtar_common import widgets
from ishtar_common.forms import FinalForm, FormSet, get_now, \
reverse_lazy, TableSelect, get_data_from_formset, QAForm, CustomFormSearch,\
ManageOldType, IshtarForm, CustomForm, FieldType, FormHeader, \
- DocumentItemSelect, LockForm, MultiSearchForm
+ GeoItemSelect, LockForm, MultiSearchForm
from ishtar_common.forms_common import TownFormSet, get_town_field, TownForm
from ishtar_common.models import valid_id, valid_ids, Person, Town, \
DocumentTemplate, Organization, get_current_profile, \
@@ -479,7 +479,7 @@ RecordRelationsFormSet.form_admin_name = _("Operation - 080 - Relations")
RecordRelationsFormSet.form_slug = "operation-080-relations"
-class OperationSelect(DocumentItemSelect):
+class OperationSelect(GeoItemSelect):
_model = models.Operation
form_admin_name = _("Operation - 001 - Search")
form_slug = "operation-001-search"
@@ -587,7 +587,7 @@ class OperationSelect(DocumentItemSelect):
FieldType('record_quality_type', models.RecordQualityType),
FieldType('relation_types', models.RelationType),
FieldType('towns__areas', Area),
- ]
+ ] + GeoItemSelect.TYPES
SITE_KEYS = {"archaeological_sites": None}
def __init__(self, *args, **kwargs):
@@ -1303,7 +1303,7 @@ class OperationDeletionForm(FinalForm):
#########
-class SiteSelect(DocumentItemSelect):
+class SiteSelect(GeoItemSelect):
_model = models.ArchaeologicalSite
form_admin_name = _("Archaeological site - 001 - Search")
form_slug = "archaeological_site-001-search"
@@ -1365,7 +1365,7 @@ class SiteSelect(DocumentItemSelect):
FieldType('remains', models.RemainType),
FieldType('cultural_attributions', models.CulturalAttributionType),
FieldType('towns__areas', Area),
- ]
+ ] + GeoItemSelect.TYPES
def __init__(self, *args, **kwargs):
super(SiteSelect, self).__init__(*args, **kwargs)
@@ -1968,7 +1968,7 @@ class QAArchaeologicalSiteFormMulti(QAForm):
choices=[],
)
qa_remains = forms.ChoiceField(
- label=("Remains"),
+ label=_("Remains"),
required=False,
choices=[],
)
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 0888345d7..9e038adeb 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -431,6 +431,7 @@ class ArchaeologicalSite(
}
ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)
ALT_NAMES.update(DocumentItem.ALT_NAMES)
+ ALT_NAMES.update(GeoItem.ALT_NAMES)
UP_MODEL_QUERY = {
"operation": (
@@ -1207,6 +1208,7 @@ class Operation(
}
ALT_NAMES.update(BaseHistorizedItem.ALT_NAMES)
ALT_NAMES.update(DocumentItem.ALT_NAMES)
+ ALT_NAMES.update(GeoItem.ALT_NAMES)
QA_EDIT = QuickAction(
url="operation-qa-bulk-update",
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index c5058ab0d..d15352e64 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -1292,3 +1292,24 @@ class DocumentGenerationForm(forms.Form):
except models.DocumentTemplate.DoesNotExist:
return
return template.publish(c_object)
+
+
+class GeoItemSelect(DocumentItemSelect): # all geo item can have documents
+ geodata__name = forms.CharField(label=_("Geo - Name"), max_length=300)
+ geodata__data_type = forms.ChoiceField(label=_("Geo - Data type"), choices=[])
+ geodata__origin = forms.ChoiceField(label=_("Geo - Origin"), choices=[])
+ geodata__provider = forms.ChoiceField(label=_("Geo - Provider"), choices=[])
+ geodata__comment = forms.CharField(label=_("Geo - Comment"), max_length=500)
+ CURRENT_FIELDS = [
+ "geodata__name",
+ "geodata__data_type",
+ "geodata__origin",
+ "geodata__provider",
+ "geodata__comment",
+ ] + DocumentItemSelect.CURRENT_FIELDS
+ _explicit_ordering = True
+ TYPES = [
+ FieldType("geodata__data_type", models.GeoDataType),
+ FieldType("geodata__origin", models.GeoOriginType),
+ FieldType("geodata__provider", models.GeoProviderType),
+ ] + DocumentItemSelect.TYPES
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 1c77d1a90..779af635b 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2687,6 +2687,31 @@ class GeographicItem(models.Model):
geodata = models.ManyToManyField(
GeoVectorData, blank=True, related_name="related_items_%(app_label)s_%(class)s"
)
+ ALT_NAMES = {
+ "geodata__name": SearchAltName(
+ pgettext_lazy("key for text search", "geo-name"), "geodata__name__iexact"
+ ),
+ "geodata__data_type": SearchAltName(
+ pgettext_lazy("key for text search", "geo-type"), "geodata__data_type__label__iexact"
+ ),
+ "geodata__origin": SearchAltName(
+ pgettext_lazy("key for text search", "geo-origin"), "geodata__origin__label__iexact"
+ ),
+ "geodata__provider": SearchAltName(
+ pgettext_lazy("key for text search", "geo-provider"), "geodata__provider__label__iexact"
+ ),
+ "geodata__comment": SearchAltName(
+ pgettext_lazy("key for text search", "geo-comment"), "geodata__comment__iexact"
+ ),
+ }
+
+ @classmethod
+ def ALT_NAMES_FOR_FIND(cls):
+ dct = {}
+ for k in cls.ALT_NAMES:
+ sa = cls.ALT_NAMES[k]
+ dct[k] = SearchAltName(sa.search_key, "base_finds__" + sa.search_query)
+ return dct
class Meta:
abstract = True