diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-14 18:03:53 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-14 18:03:53 +0200 |
commit | 2331e5eed077f124061e4ba987114dd078ba9aaf (patch) | |
tree | d3a52fda81355786a629b3e38de512e20043c066 /archaeological_finds/models_treatments.py | |
parent | 7bff3eb7ca6e7ea59be77e0bd0d0471a5f8ff97a (diff) | |
download | Ishtar-2331e5eed077f124061e4ba987114dd078ba9aaf.tar.bz2 Ishtar-2331e5eed077f124061e4ba987114dd078ba9aaf.zip |
Treatment searches
Diffstat (limited to 'archaeological_finds/models_treatments.py')
-rw-r--r-- | archaeological_finds/models_treatments.py | 84 |
1 files changed, 75 insertions, 9 deletions
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 4ee5fe08b..68a6ebb13 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -24,7 +24,7 @@ from django.contrib.gis.db import models from django.db.models import Max, Q from django.db.models.signals import post_save, post_delete, pre_delete from django.template.defaultfilters import slugify -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, pgettext_lazy from archaeological_finds.models_finds import Find, FindBasket, TreatmentType from archaeological_operations.models import ClosedItem, Operation @@ -33,7 +33,8 @@ from ishtar_common.models import Document, GeneralType, \ ImageModel, BaseHistorizedItem, OwnPerms, HistoricalRecords, Person, \ Organization, ValueGetter, post_save_cache, ShortMenuItem, \ DashboardFormItem -from ishtar_common.utils import cached_label_changed, get_current_year +from ishtar_common.utils import cached_label_changed, get_current_year, \ + TXT_SEARCH_COMMENT class TreatmentState(GeneralType): @@ -49,20 +50,17 @@ post_delete.connect(post_save_cache, sender=TreatmentState) class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): + SLUG = 'treatment' SHOW_URL = 'show-treatment' TABLE_COLS = ('year', 'index', 'treatment_types__label', 'treatment_state__label', 'label', 'person', 'start_date', 'downstream_cached_label', 'upstream_cached_label') - REVERSED_BOOL_FIELDS = ['image__isnull'] + REVERSED_BOOL_FIELDS = ['documents__image__isnull'] EXTRA_REQUEST_KEYS = { - "label": 'label__icontains', - "other_reference": 'other_reference__icontains', - "treatment_types": "treatment_types__pk", "downstream_cached_label": "downstream__cached_label", "upstream_cached_label": "upstream__cached_label", - 'image': 'image__isnull', } COL_LABELS = { "downstream_cached_label": _(u"Downstream find"), @@ -72,7 +70,37 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, } # extra keys than can be passed to save method EXTRA_SAVED_KEYS = ('items', 'user') - SLUG = 'treatment' + + # alternative names of fields for searches + ALT_NAMES = { + 'label': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"label"), + 'label__icontains' + ), + 'other_reference': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"other-reference"), + 'other_reference__icontains' + ), + 'year': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"year"), + 'year' + ), + 'index': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"index"), + 'index' + ), + 'documents__image__isnull': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"has-image"), + 'documents__image__isnull' + ), + 'treatment_types': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), + 'treatment_types__label__iexact' + ), + } + for v in ALT_NAMES.values(): + EXTRA_REQUEST_KEYS[v[0]] = v[1] + BASE_SEARCH_VECTORS = [ 'treatment_types__label', 'treatment_state__label', 'label', 'goal', 'external_id', 'comment', 'description', 'other_reference', @@ -497,7 +525,45 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem, ] INT_SEARCH_VECTORS = ['year', 'index'] PARENT_SEARCH_VECTORS = ['in_charge', 'applicant', 'applicant_organisation'] - SLUG = 'treatmentfile' + + EXTRA_REQUEST_KEYS = {} + # alternative names of fields for searches + ALT_NAMES = { + 'name': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"name"), + 'name__icontains' + ), + 'internal_reference': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"reference"), + 'internal_reference__icontains' + ), + 'year': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"year"), + 'year' + ), + 'index': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"index"), + 'index' + ), + 'type': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), + 'type__label__iexact' + ), + 'in_charge': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"in-charge"), + 'in_charge__cached_label__iexact' + ), + 'applicant': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"applicant"), + 'applicant__cached_label__iexact' + ), + 'applicant_organisation': ( + pgettext_lazy(TXT_SEARCH_COMMENT, u"applicant-organisation"), + 'applicant_organisation__cached_label__iexact' + ), + } + for v in ALT_NAMES.values(): + EXTRA_REQUEST_KEYS[v[0]] = v[1] # fields year = models.IntegerField(_(u"Year"), default=get_current_year) |