diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-21 12:21:58 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-21 12:21:58 +0200 |
commit | 9a42480febe04f2fa1e2416310906dfab57b0cb9 (patch) | |
tree | de2ae36f8c87a50c0ca91b74df183af1ec287075 /ishtar_common/models.py | |
parent | fab4d28bed4ec75e2efa6527503f3a5ca466534c (diff) | |
download | Ishtar-9a42480febe04f2fa1e2416310906dfab57b0cb9.tar.bz2 Ishtar-9a42480febe04f2fa1e2416310906dfab57b0cb9.zip |
External ID: general filters - deduplicate filter
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 8d0545885..d14e9b346 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1634,11 +1634,21 @@ class LightHistorizedItem(BaseHistorizedItem): PARSE_FORMULA = re.compile("{([^}]*)}") + +def _deduplicate(value): + new_values = [] + for v in value.split(u'-'): + if v not in new_values: + new_values.append(v) + return u'-'.join(new_values) + + FORMULA_FILTERS = { 'upper': lambda x: x.upper(), 'lower': lambda x: x.lower(), 'capitalize': lambda x: x.capitalize(), - 'slug': lambda x: slugify(x) + 'slug': lambda x: slugify(x), + 'deduplicate': _deduplicate } @@ -1675,7 +1685,14 @@ def get_external_id(key, item): dct[initial_key] = unicode(obj) for filtr in filters: dct[initial_key] = filtr(dct[initial_key]) - return formula.format(**dct) + values = formula.format(**dct).split('||') + value = values[0] + for filtr in values[1:]: + if filtr not in FORMULA_FILTERS: + value += u'||' + filtr + continue + value = FORMULA_FILTERS[filtr](value) + return value CURRENCY = ((u"€", _(u"Euro")), |