diff options
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 |
commit | e131856e48cc4644443c62f3f826fa451cb7e66b (patch) | |
tree | 5888b277c026e0c6e9209472f016055ba73d77c4 /ishtar_common | |
parent | ad0c40ca519ec3d81120744e6c511fb3d5992897 (diff) | |
download | Ishtar-e131856e48cc4644443c62f3f826fa451cb7e66b.tar.bz2 Ishtar-e131856e48cc4644443c62f3f826fa451cb7e66b.zip |
Geodata - search: add search fields on related items searches
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms.py | 21 | ||||
-rw-r--r-- | ishtar_common/models_common.py | 25 |
2 files changed, 46 insertions, 0 deletions
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 |