From f815706079b41d9216b2f8b8a4db59e0dfdb3cbc Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 4 Jul 2018 15:39:22 +0200 Subject: Search: manage post process tretment of query (refs #4180) --- archaeological_operations/models.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'archaeological_operations') diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 9565bf144..b929677b8 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -396,10 +396,20 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, ), 'towns__cached_label__iexact' ), + 'towns__numero_insee__startswith': ( + pgettext_lazy( + "key for text search (no accent, no spaces)", u"department" + ), + 'towns__numero_insee__startswith' + ) } for v in ALT_NAMES.values(): EXTRA_REQUEST_KEYS[v[0]] = v[1] + POST_PROCESS_REQUEST = { + 'towns__numero_insee__startswith': '_get_department_code', + } + # fields definition creation_date = models.DateField(_(u"Creation date"), default=datetime.date.today) @@ -567,6 +577,16 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, values = super(Operation, self).get_values(prefix=prefix) return get_values_town_related(self, prefix, values) + @classmethod + def _get_department_code(cls, value): + if not settings.ISHTAR_DPTS: + return u"" + for k, v in settings.ISHTAR_DPTS: + if v.lower() == value: + return k + return u"" + + @property def short_class_name(self): return _(u"OPE") -- cgit v1.2.3