summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-07-04 17:50:10 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-13 18:26:03 +0200
commitf642961947a1a4fb79e49ff764d93b3f0ab474db (patch)
tree79b25c8593b8bdec8c938e12da00b1da9f57bba4
parentaac03c20b75d0d12b63d532766b55714866d103e (diff)
downloadIshtar-f642961947a1a4fb79e49ff764d93b3f0ab474db.tar.bz2
Ishtar-f642961947a1a4fb79e49ff764d93b3f0ab474db.zip
Criteria search: manage boolean search (refs #4180)
-rw-r--r--archaeological_operations/models.py64
-rw-r--r--archaeological_operations/tests.py24
-rw-r--r--ishtar_common/utils.py3
-rw-r--r--ishtar_common/views_item.py11
4 files changed, 53 insertions, 49 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index b929677b8..1c3bbde99 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -37,7 +37,7 @@ from ishtar_common.models import BaseHistorizedItem, Dashboard, \
post_delete_record_relation, post_save_cache, RelationItem, \
ShortMenuItem, SourceType, Town, ValueGetter
from ishtar_common.utils import cached_label_changed, \
- force_cached_label_changed, mode
+ force_cached_label_changed, mode, TXT_SEARCH_COMMENT
class RemainType(GeneralType):
@@ -357,51 +357,50 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
# alternative names of fields for searches
ALT_NAMES = {
- 'periods': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"period"),
- 'periods__pk'
- ),
- 'operation_type': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"type"
- ),
- 'operation_type__pk'
- ),
- 'remains': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"remain"),
- 'remains__pk'
- ),
'year': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"year"),
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"year"),
'year'
),
'operation_code': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"operation-code"
- ),
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"operation-code"),
'operation_code'
),
'code_patriarche': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"patriarche"
- ),
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"patriarche"),
'code_patriarche'
),
'towns': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"town"
- ),
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"town"),
'towns__cached_label__iexact'
),
'towns__numero_insee__startswith': (
- pgettext_lazy(
- "key for text search (no accent, no spaces)", u"department"
- ),
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"department"),
'towns__numero_insee__startswith'
- )
+ ),
+ 'common_name': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"name"),
+ 'common_name'
+ ),
+ 'address': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"address"),
+ 'address'
+ ),
+ 'operation_type': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"type"),
+ 'operation_type__pk'
+ ),
+ 'end_date': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"is-open"),
+ 'end_date__isnull'
+ ),
+ 'periods': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"period"),
+ 'periods__pk'
+ ),
+ 'remains': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"remain"),
+ 'remains__pk'
+ ),
}
for v in ALT_NAMES.values():
EXTRA_REQUEST_KEYS[v[0]] = v[1]
@@ -586,7 +585,6 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return k
return u""
-
@property
def short_class_name(self):
return _(u"OPE")
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index cfcbe010b..38f832cf8 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -50,6 +50,8 @@ from archaeological_context_records.models import Unit, ContextRecord
from ishtar_common import forms_common
from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \
create_superuser, create_user, TestCase, OPERATION_FIXTURES
+from ishtar_common.utils import TXT_SEARCH_COMMENT
+
OPERATION_TOWNS_FIXTURES = \
OPERATION_FIXTURES + \
@@ -1568,6 +1570,7 @@ class OperationSearchTest(TestCase, OperationInitTest):
c.login(username=self.username, password=self.password)
ope1.year = 2042
+ ope1.end_date = "2010-01-01"
ope1.save()
ope2.year = 2020
ope2.save()
@@ -1589,22 +1592,15 @@ class OperationSearchTest(TestCase, OperationInitTest):
villa = models.RemainType.objects.get(txt_idx='villa')
ope1.remains.add(villa)
- search_period_q = unicode(
- pgettext("key for text search (no accent, no spaces)", u"period")
- )
-
+ search_period_q = unicode(pgettext(TXT_SEARCH_COMMENT, u"period"))
self._test_search(c, search_period_q, final_neo.label, 1, "Simple")
- search_year_q = unicode(
- pgettext("key for text search (no accent, no spaces)", u"year")
- )
+ search_year_q = unicode(pgettext(TXT_SEARCH_COMMENT, u"year"))
self._test_search(c, search_year_q, "2042", 1, "Integer")
self._test_search(c, search_year_q, '2042";"2020', 2, "Many integer")
- search_town_q = unicode(
- pgettext("key for text search (no accent, no spaces)", u"town")
- )
+ search_town_q = unicode(pgettext(TXT_SEARCH_COMMENT, u"town"))
self._test_search(c, search_town_q, town.cached_label, 1,
"String search with parenthesis and minus")
@@ -1627,12 +1623,14 @@ class OperationSearchTest(TestCase, OperationInitTest):
u'{}*'.format(neo.label[:3]), 2, "Open search")
# non hierarchic search
- search_remain_q = unicode(
- pgettext("key for text search (no accent, no spaces)", u"remain")
- )
+ search_remain_q = unicode(pgettext(TXT_SEARCH_COMMENT, u"remain"))
self._test_search(c, search_remain_q, villa.label,
1, "Non hierarchic search")
+ # boolean search
+ search_open_q = unicode(pgettext(TXT_SEARCH_COMMENT, u"is-open"))
+ self._test_search(c, search_open_q, u"Yes", 2, "Boolean")
+
def create_relations(self):
rel1 = models.RelationType.objects.create(
symmetrical=True, label='Include', txt_idx='include')
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 189e91b8c..34d170892 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -62,6 +62,9 @@ class BColors:
CSV_OPTIONS = {'delimiter': ',', 'quotechar': '"', 'quoting': QUOTE_ALL}
+TXT_SEARCH_COMMENT = "key for text search (no accent, no spaces)"
+
+
def check_rights(rights=None, redirect_url='/'):
"""
Decorator that checks the rights to access the view.
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 9941f338c..854c91ce5 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -450,7 +450,11 @@ def _manage_bool_fields(model, bool_fields, reversed_bool_fields, dct, or_reqs):
if dct[k] == u"1":
dct.pop(k)
else:
- dct[k] = dct[k] == u"2" and True or False
+ dct[k] = dct[k].replace(u'"', u'')
+ if dct[k] in [u"2", u"yes", unicode(_(u"Yes")).lower()]:
+ dct[k] = True
+ else:
+ dct[k] = False
if k in reversed_bool_fields:
dct[k] = not dct[k]
# check also for empty value with image field
@@ -609,7 +613,8 @@ def _manage_hierarchic_fields(dct, and_reqs):
def _manage_clean_search_field(dct):
for k in dct:
# clean quoted search field
- dct[k] = dct[k].replace(u'"', '')
+ if type(dct[k]) == unicode:
+ dct[k] = dct[k].replace(u'"', '')
def _manage_relation_types(relation_types, dct, query, or_reqs):
@@ -656,7 +661,7 @@ def _contruct_query(relation_types, dct, or_reqs, and_reqs):
# manage multi value not already managed
for key in dct.keys():
- if ";" in dct[key]:
+ if type(dct[key]) == unicode and u";" in dct[key]:
values = [v for v in dct[key].split(u';') if v]
if not values:
dct.pop(key)