From f7f1e6cd78ae567098815962856b704de22ec241 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 16 Nov 2014 13:54:08 +0000 Subject: [PATCH] add itemKey value/map and filterMap options --- pandora/item/models.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandora/item/models.py b/pandora/item/models.py index c1d750e4b..c54c788e7 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -193,6 +193,12 @@ class Item(models.Model): return self.data[key] if self.external_data and key in self.external_data: return self.external_data[key] + item_key = utils.get_by_id(settings.CONFIG['itemKeys'], key) + if item_key and 'value' in item_key \ + and item_key['value'].get('type') == 'map' \ + and self.get(item_key['value']['key']): + value = re.compile(item_key['value']['map']).findall(self.get(item_key['value']['key'])) + return value[0] if value else default return default def access(self, user): @@ -1051,6 +1057,16 @@ class Item(models.Model): current_values = [] else: current_values = [unicode(current_values)] + filter_map = utils.get_by_id(settings.CONFIG['itemKeys'], key).get('filterMap') + if filter_map: + filter_map = re.compile(filter_map) + _current_values = [] + for value in current_values: + value = filter_map.findall(value) + if value: + _current_values.append(value[0]) + current_values = _current_values + current_values = list(set(current_values)) current_values = [ox.decode_html(ox.strip_tags(v)) for v in current_values] saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)]