From 3cd321a1169a73e3d21e2959098604ccd70eb27f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 26 Dec 2011 20:13:41 +0100 Subject: [PATCH] add filter of layer values(i.e. keywords) --- pandora/item/models.py | 19 ++++++++++++++++++- pandora/padma.jsonc | 37 ++++--------------------------------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index f70fbd2d..a9ce4174 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.value for l in qs])) + save(i, '\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): @@ -733,6 +733,22 @@ class Item(models.Model): #update cached values in clips self.clips.all().update(director=s.director, title=s.title) + def update_layer_facets(self): + filters = [f['id'] for f in settings.CONFIG['filters']] + for layer in settings.CONFIG['layers']: + if layer['id'] in filters: + key = layer['id'] + current_values = [a['value'] + for a in self.annotations.filter(layer=key).distinct().values('value')] + saved_values = [i.value for i in Facet.objects.filter(item=self, key=key)] + removed_values = filter(lambda i: i not in current_values, saved_values) + if removed_values: + Facet.objects.filter(item=self, key=key, value__in=removed_values).delete() + for value in current_values: + if value not in saved_values: + sortvalue = value + Facet.objects.get_or_create(item=self, key=key, value=value, sortvalue=sortvalue) + def update_facets(self): for key in self.facet_keys + ['title']: current_values = self.get(key, []) @@ -769,6 +785,7 @@ class Item(models.Model): if key in self.person_keys + ['name']: sortvalue = get_name_sort(value) Facet.objects.get_or_create(item=self, key=key, value=value, sortvalue=sortvalue) + self.update_layer_facets() def path(self, name=''): h = self.itemId diff --git a/pandora/padma.jsonc b/pandora/padma.jsonc index aa33c76f..346b61d7 100644 --- a/pandora/padma.jsonc +++ b/pandora/padma.jsonc @@ -49,12 +49,7 @@ {"id": "year", "title": "Year", "type": "integer"}, {"id": "language", "title": "Language", "type": "string"}, {"id": "category", "title": "Category", "type": "string"}, - {"id": "writer", "title": "Writer", "type": "string"}, - {"id": "producer", "title": "Producer", "type": "string"}, - {"id": "cinematographer", "title": "Cinematographer", "type": "string"}, - {"id": "editor", "title": "Editor", "type": "string"}, - {"id": "actor", "title": "Actor", "type": "string"}, - {"id": "keyword", "title": "Keyword", "type": "string"} + {"id": "keywords", "title": "Keyword", "type": "string"} ], /* An itemKey must have the following properties: @@ -174,30 +169,6 @@ "filter": true, "find": true }, - { - "id": "genre", - "title": "Genre", - "type": ["string"], - "autocomplete": true, - "columnWidth": 120, - "filter": true, - "find": true - }, - { - "id": "keyword", - "title": "Keyword", - "type": ["string"], - "autocomplete": true, - "filter": true, - "find": true - }, - { - "id": "numberofkeywords", - "title": "Number of Keywords", - "type": "integer", - "columnWidth": 60, - "value": {"key": "keyword", "type": "length"} - }, { "id": "description", "title": "Description", @@ -503,10 +474,10 @@ } }, "filters": [ - {"id": "collection", "sort": [{"key": "name", "operator": "-"}]}, - {"id": "source", "sort": [{"key": "items", "operator": "-"}]}, + {"id": "collection", "sort": [{"key": "name", "operator": "+"}]}, + {"id": "source", "sort": [{"key": "name", "operator": "+"}]}, {"id": "category", "sort": [{"key": "items", "operator": "-"}]}, - {"id": "keyword", "sort": [{"key": "items", "operator": "-"}]}, + {"id": "keywords", "sort": [{"key": "items", "operator": "-"}]}, {"id": "location", "sort": [{"key": "items", "operator": "-"}]} ], "filtersSize": 176,