diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-16 18:27:22 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-16 18:27:22 +0200 |
commit | 7daf9f5a72d576c878cab159756934a3d7124dd8 (patch) | |
tree | 7859e2fcc08787d41a4d65db3721006bc5554c13 | |
parent | fe61620820ea704d5087bbdc8088f1c024ca73c0 (diff) | |
download | Ishtar-7daf9f5a72d576c878cab159756934a3d7124dd8.tar.bz2 Ishtar-7daf9f5a72d576c878cab159756934a3d7124dd8.zip |
Search: manage open search
-rw-r--r-- | archaeological_context_records/models.py | 19 | ||||
-rw-r--r-- | archaeological_files/models.py | 6 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 33 | ||||
-rw-r--r-- | archaeological_finds/models_treatments.py | 8 | ||||
-rw-r--r-- | archaeological_operations/models.py | 26 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 21 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 8 | ||||
-rw-r--r-- | ishtar_common/models.py | 30 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 3 |
9 files changed, 90 insertions, 64 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index e3c7ff4e5..04639bb56 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -261,7 +261,7 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, ALT_NAMES = { 'label': ( pgettext_lazy("key for text search", u"id"), - 'label' + 'label__iexact' ), 'town': ( pgettext_lazy("key for text search", u"town"), @@ -273,7 +273,7 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, ), 'operation__code_patriarche': ( pgettext_lazy("key for text search", u"patriarche"), - 'operation__code_patriarche' + 'operation__code_patriarche__iexact' ), 'operation__operation_code': ( pgettext_lazy("key for text search", u"operation-code"), @@ -310,6 +310,14 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, EXTRA_REQUEST_KEYS[unicode(v[0])] = v[1] deactivate() + PARENT_ONLY_SEARCH_VECTORS = ['operation', "archaeological_site"] + BASE_SEARCH_VECTORS = ["cached_label", "label", "location", "town__name", + "interpretation", "filling", "datings_comment", + "identification__label", "activity__label", + "excavation_technic__label"] + M2M_SEARCH_VECTORS = ["datings__period__label"] + history = HistoricalRecords() + # fields external_id = models.TextField(_(u"External ID"), blank=True, null=True) auto_external_id = models.BooleanField( @@ -385,13 +393,6 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, blank=True) cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, db_index=True) - PARENT_SEARCH_VECTORS = ['operation', "archaeological_site"] - BASE_SEARCH_VECTORS = ["cached_label", "label", "location", "town__name", - "interpretation", "filling", "datings_comment", - "identification__label", "activity__label", - "excavation_technic__label"] - M2M_SEARCH_VECTORS = ["datings__period__label"] - history = HistoricalRecords() class Meta: verbose_name = _(u"Context Record") diff --git a/archaeological_files/models.py b/archaeological_files/models.py index a7fa9428b..a60e01f64 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -134,7 +134,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, ), 'internal_reference': ( pgettext_lazy("key for text search", u"other-reference"), - 'internal_reference' + 'internal_reference__iexact' ), 'towns': ( pgettext_lazy("key for text search", u"town"), @@ -150,7 +150,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, ), 'name': ( pgettext_lazy("key for text search", u"name"), - 'name__icontains' + 'name__iexact' ), 'file_type': ( pgettext_lazy("key for text search", u"type"), @@ -174,7 +174,7 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, ), 'comment': ( pgettext_lazy("key for text search", u"comment"), - 'comment__icontains' + 'comment__iexact' ), 'in_charge': ( pgettext_lazy("key for text search", u"in-charge"), diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 40bcf52c7..41752be0b 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -720,19 +720,19 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, ALT_NAMES = { 'base_finds__cache_short_id': ( pgettext_lazy("key for text search", u"short-id"), - 'base_finds__cache_short_id__contains' + 'base_finds__cache_short_id__iexact' ), 'base_finds__cache_complete_id': ( pgettext_lazy("key for text search", u"complete-id"), - 'base_finds__cache_complete_id__icontains' + 'base_finds__cache_complete_id__iexact' ), 'label': ( pgettext_lazy("key for text search", u"free-id"), - 'label__icontains' + 'label__iexact' ), 'denomination': ( pgettext_lazy("key for text search", u"denomination"), - 'denomination__icontains' + 'denomination__iexact' ), 'base_finds__context_record__town': ( pgettext_lazy("key for text search", u"town"), @@ -748,7 +748,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, ), 'base_finds__context_record__operation__code_patriarche': ( pgettext_lazy("key for text search", u"code-patriarche"), - 'base_finds__context_record__operation__code_patriarche' + 'base_finds__context_record__operation__code_patriarche__iexact' ), 'base_finds__context_record__operation__operation_type': ( pgettext_lazy("key for text search", u"operation-type"), @@ -811,7 +811,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, ), 'base_finds__find__description': ( pgettext_lazy("key for text search", u"description"), - 'base_finds__find__description__icontains', + 'base_finds__find__description__iexact', ), 'base_finds__batch': ( pgettext_lazy("key for text search", u"batch"), @@ -848,6 +848,17 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, EXTRA_REQUEST_KEYS[unicode(v[0])] = v[1] deactivate() + PARENT_SEARCH_VECTORS = ['base_finds'] + BASE_SEARCH_VECTORS = [ + "cached_label", "label", "description", "container__location__name", + "container__reference", "mark", "comment", "dating_comment", + "previous_id", "denomination", "museum_id", "decoration", + "manufacturing_place" + ] + M2M_SEARCH_VECTORS = [ + "datings__period__label", "object_types__label", "integrities__label", + "remarkabilities__label", "material_types__label"] + # fields base_finds = models.ManyToManyField(BaseFind, verbose_name=_(u"Base find"), related_name='find') @@ -978,16 +989,6 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms, db_index=True) history = HistoricalRecords() BASKET_MODEL = FindBasket - PARENT_SEARCH_VECTORS = ['base_finds'] - BASE_SEARCH_VECTORS = [ - "cached_label", "label", "description", "container__location__name", - "container__reference", "mark", "comment", "dating_comment", - "previous_id", "denomination", "museum_id", "decoration", - "manufacturing_place" - ] - M2M_SEARCH_VECTORS = [ - "datings__period__label", "object_types__label", "integrities__label", - "remarkabilities__label", "material_types__label"] class Meta: verbose_name = _(u"Find") diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 2bc02288b..cd52791e7 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -75,11 +75,11 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, ALT_NAMES = { 'label': ( pgettext_lazy("key for text search", u"label"), - 'label__icontains' + 'label__iexact' ), 'other_reference': ( pgettext_lazy("key for text search", u"other-reference"), - 'other_reference__icontains' + 'other_reference__iexact' ), 'year': ( pgettext_lazy("key for text search", u"year"), @@ -534,11 +534,11 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem, ALT_NAMES = { 'name': ( pgettext_lazy("key for text search", u"name"), - 'name__icontains' + 'name__iexact' ), 'internal_reference': ( pgettext_lazy("key for text search", u"reference"), - 'internal_reference__icontains' + 'internal_reference__iexact' ), 'year': ( pgettext_lazy("key for text search", u"year"), diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 435394592..004ee8d06 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -125,11 +125,11 @@ class ArchaeologicalSite(BaseHistorizedItem): ALT_NAMES = { 'reference': ( pgettext_lazy("key for text search", u"reference"), - 'reference' + 'reference__iexact' ), 'name': ( pgettext_lazy("key for text search", u"name"), - 'name' + 'name__iexact' ), 'periods': ( pgettext_lazy("key for text search", u"period"), @@ -145,15 +145,15 @@ class ArchaeologicalSite(BaseHistorizedItem): ), 'comment': ( pgettext_lazy("key for text search", u"comment"), - 'comment__icontains' + 'comment__iexact' ), 'locality_ngi': ( pgettext_lazy("key for text search", u"locality-ngi"), - 'locality_ngi__icontains' + 'locality_ngi__iexact' ), 'locality_cadastral': ( pgettext_lazy("key for text search", u"locality-cadastral"), - 'locality_cadastral__icontains' + 'locality_cadastral__iexact' ), 'shipwreck_name': ( pgettext_lazy("key for text search", u"shipwreck-name"), @@ -162,7 +162,7 @@ class ArchaeologicalSite(BaseHistorizedItem): 'oceanographic_service_localisation': ( pgettext_lazy("key for text search", u"oceanographic-service-localisation"), - 'oceanographic_service_localisation__icontains' + 'oceanographic_service_localisation__iexact' ), 'shipwreck_code': ( pgettext_lazy("key for text search", u"shipwreck-code"), @@ -174,7 +174,7 @@ class ArchaeologicalSite(BaseHistorizedItem): ), 'discovery_area': ( pgettext_lazy("key for text search", u"discovery-area"), - 'discovery_area__icontains' + 'discovery_area__iexact' ), } for v in ALT_NAMES.values(): @@ -474,7 +474,7 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, ), 'code_patriarche': ( pgettext_lazy("key for text search", u"patriarche"), - 'code_patriarche' + 'code_patriarche__iexact' ), 'towns': ( pgettext_lazy("key for text search", u"town"), @@ -490,11 +490,11 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, ), 'common_name': ( pgettext_lazy("key for text search", u"name"), - 'common_name__icontains' + 'common_name__iexact' ), 'address': ( pgettext_lazy("key for text search", u"address"), - 'address__icontains' + 'address__iexact' ), 'operation_type': ( pgettext_lazy("key for text search", u"type"), @@ -546,16 +546,16 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, ), 'comment': ( pgettext_lazy("key for text search", u"comment"), - 'comment__icontains' + 'comment__iexact' ), 'abstract': ( pgettext_lazy("key for text search", u"abstract"), - 'abstract__icontains' + 'abstract__iexact' ), 'scientific_documentation_comment': ( pgettext_lazy("key for text search", u"scientific-documentation-comment"), - 'scientific_documentation_comment__icontains' + 'scientific_documentation_comment__iexact' ), 'record_quality_type': ( pgettext_lazy("key for text search", u"record-quality"), diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index a396adecf..f45355558 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2467,3 +2467,24 @@ class SiteTest(TestCase, OperationInitTest): ] self.assertIn(operation_0, attached) self.assertIn(operation_1, attached) + + def test_search(self): + site = models.ArchaeologicalSite.objects.create( + reference="reference-site" + ) + c = Client() + search = {'search_vector': 'reference="reference-site"'} + response = c.get(reverse('get-site'), search) + # no result when no authentication + self.assertTrue(not json.loads(response.content)) + c.login(username=self.username, password=self.password) + response = c.get(reverse('get-site'), search) + self.assertEqual(json.loads(response.content)['recordsTotal'], 1) + + search = {'search_vector': 'reference="reference"'} + response = c.get(reverse('get-site'), search) + self.assertEqual(json.loads(response.content)['recordsTotal'], 0) + + search = {'search_vector': 'reference="reference*"'} + response = c.get(reverse('get-site'), search) + self.assertEqual(json.loads(response.content)['recordsTotal'], 1) diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 8dcb1c700..a21f5ab78 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -57,7 +57,7 @@ class Warehouse(Address, DashboardFormItem, OwnPerms): ALT_NAMES = { 'name': ( pgettext_lazy("key for text search", u"name"), - 'name__icontains' + 'name__iexact' ), 'warehouse_type': ( pgettext_lazy("key for text search", u"type"), @@ -317,11 +317,11 @@ class Container(LightHistorizedItem, ImageModel): ALT_NAMES = { 'location': ( pgettext_lazy("key for text search", u"location"), - 'location__name__icontains' + 'location__name__iexact' ), 'responsible': ( pgettext_lazy("key for text search", u"responsible-warehouse"), - 'responsible__name__icontains' + 'responsible__name__iexact' ), 'container_type': ( pgettext_lazy("key for text search", u"type"), @@ -329,7 +329,7 @@ class Container(LightHistorizedItem, ImageModel): ), 'reference': ( pgettext_lazy("key for text search", u"reference"), - 'reference__icontains' + 'reference__iexact' ), } for v in ALT_NAMES.values(): diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 38e58955b..800d2a6ae 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2547,7 +2547,7 @@ class Organization(Address, Merge, OwnPerms, ValueGetter): ALT_NAMES = { 'name': ( pgettext_lazy("key for text search", u"name"), - 'name__icontains' + 'name__iexact' ), 'organization_type': ( pgettext_lazy("key for text search", u"type"), @@ -2678,15 +2678,15 @@ class Person(Address, Merge, OwnPerms, ValueGetter): ALT_NAMES = { 'name': ( pgettext_lazy("key for text search", u"name"), - 'name__icontains' + 'name__iexact' ), 'surname': ( pgettext_lazy("key for text search", u"surname"), - 'surname__icontains' + 'surname__iexact' ), 'email': ( pgettext_lazy("key for text search", u"email"), - 'email__icontains' + 'email__iexact' ), 'person_types': ( pgettext_lazy("key for text search", u"type"), @@ -3048,19 +3048,19 @@ class IshtarUser(FullSearch): ALT_NAMES = { 'username': ( pgettext_lazy("key for text search", u"username"), - 'user_ptr__username__icontains' + 'user_ptr__username__iexact' ), 'name': ( pgettext_lazy("key for text search", u"name"), - 'person__name__icontains' + 'person__name__iexact' ), 'surname': ( pgettext_lazy("key for text search", u"surname"), - 'person__surname__icontains' + 'person__surname__iexact' ), 'email': ( pgettext_lazy("key for text search", u"email"), - 'person__email__icontains' + 'person__email__iexact' ), 'person_types': ( pgettext_lazy("key for text search", u"type"), @@ -3329,11 +3329,11 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported): ALT_NAMES = { 'authors': ( pgettext_lazy("key for text search", u"author"), - 'authors__cached_label__icontains' + 'authors__cached_label__iexact' ), 'title': ( pgettext_lazy("key for text search", u"title"), - 'title__icontains' + 'title__iexact' ), 'source_type': ( pgettext_lazy("key for text search", u"type"), @@ -3341,23 +3341,23 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported): ), 'reference': ( pgettext_lazy("key for text search", u"reference"), - 'reference__icontains' + 'reference__iexact' ), 'internal_reference': ( pgettext_lazy("key for text search", u"internal-reference"), - 'internal_reference__icontains' + 'internal_reference__iexact' ), 'description': ( pgettext_lazy("key for text search", u"description"), - 'description__icontains' + 'description__iexact' ), 'comment': ( pgettext_lazy("key for text search", u"comment"), - 'comment__icontains' + 'comment__iexact' ), 'additional_information': ( pgettext_lazy("key for text search", u"additional-information"), - 'additional_information__icontains' + 'additional_information__iexact' ), 'duplicate': ( pgettext_lazy("key for text search", u"has-duplicate"), diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 211cb7897..e536713f7 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -647,6 +647,9 @@ def _manage_clean_search_field(dct): if type(dct[k]) == unicode: dct[k] = dct[k].replace(u'"', '') dct[k] = _clean_type_val(dct[k]) + if '*' in dct[k] and k.endswith('__iexact'): + value = dct.pop(k).replace(u'*', u'') + dct[k[:-len('__iexact')] + '__icontains'] = value def _manage_relation_types(relation_types, dct, query, or_reqs): |