From e3b948f08f351ee8d49ecef69b51e054fbf4be43 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 26 Dec 2011 21:30:21 +0100 Subject: [PATCH] use facets if possible for layer values --- pandora/item/managers.py | 8 ++++++-- pandora/item/models.py | 2 +- pandora/padma.jsonc | 4 ++-- static/js/pandora/placesDialog.js | 5 ++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pandora/item/managers.py b/pandora/item/managers.py index 40b18ba0..56d4088c 100644 --- a/pandora/item/managers.py +++ b/pandora/item/managers.py @@ -39,6 +39,10 @@ def parseCondition(condition, user): else: exclude = False + facet_keys = models.Item.facet_keys + ['title'] + for f in settings.CONFIG['filters']: + if f['id'] not in facet_keys: + facet_keys.append(f['id']) key_type = settings.CONFIG['keys'].get(k, {'type':'string'}).get('type') if isinstance(key_type, list): key_type = key_type[0] @@ -48,8 +52,8 @@ def parseCondition(condition, user): 'text': 'string', 'year': 'string', 'length': 'string', - 'list': 'list', 'layer': 'string', + 'list': 'list', }.get(key_type, key_type) if k == 'list': key_type = '' @@ -95,7 +99,7 @@ def parseCondition(condition, user): value_key = 'find__value' else: value_key = k - if k in models.Item.facet_keys + ['title']: + if k in facet_keys: in_find = False facet_value = 'facets__value%s' % { '==': '__iexact', diff --git a/pandora/item/models.py b/pandora/item/models.py index 47bf5d39..8cc97910 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -541,7 +541,7 @@ class Item(models.Model): '\n'.join([f.path for f in self.files.all()])) elif key['type'] == 'layer': qs = Annotation.objects.filter(layer=i, item=self).order_by('start') - save(i, '\n'.join([l.findvalue for l in qs])) + save(i, u'\n'.join([l.findvalue for l in qs])) elif i != '*' and i not in self.facet_keys: value = self.get(i) if isinstance(value, list): diff --git a/pandora/padma.jsonc b/pandora/padma.jsonc index 346b61d7..5f353ef1 100644 --- a/pandora/padma.jsonc +++ b/pandora/padma.jsonc @@ -45,7 +45,7 @@ {"id": "collection", "title": "Collection", "type": "string"}, {"id": "source", "title": "Source", "type": "string"}, {"id": "director", "title": "Director", "type": "string"}, - {"id": "location", "title": "Location", "type": "string"}, + {"id": "locations", "title": "Location", "type": "string"}, {"id": "year", "title": "Year", "type": "integer"}, {"id": "language", "title": "Language", "type": "string"}, {"id": "category", "title": "Category", "type": "string"}, @@ -478,7 +478,7 @@ {"id": "source", "sort": [{"key": "name", "operator": "+"}]}, {"id": "category", "sort": [{"key": "items", "operator": "-"}]}, {"id": "keywords", "sort": [{"key": "items", "operator": "-"}]}, - {"id": "location", "sort": [{"key": "items", "operator": "-"}]} + {"id": "locations", "sort": [{"key": "items", "operator": "-"}]} ], "filtersSize": 176, "find": {"conditions": [], "operator": "&"}, diff --git a/static/js/pandora/placesDialog.js b/static/js/pandora/placesDialog.js index fa40663b..c7b6d2e7 100644 --- a/static/js/pandora/placesDialog.js +++ b/static/js/pandora/placesDialog.js @@ -30,7 +30,10 @@ pandora.ui.placesDialog = function() { pandora.api.findClips({ query: { conditions: names.map(function(name) { - return {key: 'subtitles', value: name, operator: '='}; + //FIXME: this should be more generic + return Ox.getObjectById(pandora.site.layers, 'subtitles') + ? {key: 'subtitles', value: name, operator: '='} + : {key: 'locations', value: name, operator: '=='}; }), operator: names.length == 1 ? '&' : '|' }