diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-09 13:09:00 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:04 +0200 |
commit | a9597946a8c9a1a7de2c590ef0b87d2949994920 (patch) | |
tree | 65cfe7698eb328526dca64e7f36a66aa8b545f73 /ishtar_common | |
parent | fccd2510276e510132d121cd88e76d62b1899122 (diff) | |
download | Ishtar-a9597946a8c9a1a7de2c590ef0b87d2949994920.tar.bz2 Ishtar-a9597946a8c9a1a7de2c590ef0b87d2949994920.zip |
Record quality: migrate to a type
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 1 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 18 |
2 files changed, 14 insertions, 5 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e2b1d5b02..678e2ce41 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -652,6 +652,7 @@ class GeneralType(Cached, models.Model): PREFIX_EMPTY = " " PREFIX_MEDIUM = "├ " PREFIX_LAST = "└ " + PREFIX_CODES = [u"\u2502", u"\u251C", u"\u2514"] @classmethod def _get_childs(cls, item, dct, prefix=0, instances=False, exclude=[], diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 746d359c1..3b09bc7da 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -29,7 +29,7 @@ from weasyprint.fonts import FontConfiguration from ishtar_common.utils import check_model_access_control, CSV_OPTIONS, \ get_all_field_names from ishtar_common.models import HistoryError, get_current_profile, \ - PRIVATE_FIELDS + PRIVATE_FIELDS, GeneralType from menus import Menu import models @@ -492,6 +492,12 @@ def _manage_dated_fields(dated_fields, dct): dct.pop(k) +def _clean_type_val(val): + for prefix in GeneralType.PREFIX_CODES: + val = val.replace(prefix, u"") + return val.strip() + + def _manage_facet_search(model, dct, and_reqs): general_types = model.general_types() for base_k in general_types: @@ -501,7 +507,7 @@ def _manage_facet_search(model, dct, and_reqs): if k not in dct or not dct[k].startswith(u'"') \ or not dct[k].startswith(u'"'): continue - val = dct.pop(k) + val = _clean_type_val(dct.pop(k)) if u";" in val: # OR request values = val.split(u";") @@ -533,7 +539,7 @@ def _manage_facet_search(model, dct, and_reqs): def _manage_hierarchic_fields(dct, and_reqs): for req in dct.copy(): if req.endswith('areas__pk'): - val = dct.pop(req) + val = _clean_type_val(dct.pop(req)) reqs = Q(**{req: val}) base_req = req[:-2] + '__' req = base_req[:] @@ -550,7 +556,7 @@ def _manage_hierarchic_fields(dct, and_reqs): continue if req.endswith('town__pk') or req.endswith('towns__pk'): - val = dct.pop(req) + val = _clean_type_val(dct.pop(req)) reqs = Q(**{req: val}) base_req = req[:-2] + '__' req = base_req[:] @@ -571,6 +577,7 @@ def _manage_hierarchic_fields(dct, and_reqs): val = dct.pop(req) q = None for idx, r in enumerate(req): + r = _clean_type_val(r) if not idx: q = Q(**{r: val}) else: @@ -578,7 +585,7 @@ def _manage_hierarchic_fields(dct, and_reqs): and_reqs.append(q) break elif req.endswith(k_hr + '__pk'): - val = dct.pop(req) + val = _clean_type_val(dct.pop(req)) if u";" in val: # OR request @@ -619,6 +626,7 @@ def _manage_clean_search_field(dct): # clean quoted search field if type(dct[k]) == unicode: dct[k] = dct[k].replace(u'"', '') + dct[k] = _clean_type_val(dct[k]) def _manage_relation_types(relation_types, dct, query, or_reqs): |