diff options
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")), |