From 337cafcf764d208b31b1b0b8bc71f60a1c882919 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 8 Aug 2016 15:54:52 +0200 Subject: [PATCH] don't add base keys to Item.data --- pandora/annotation/tasks.py | 2 +- pandora/item/models.py | 71 +++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 38ad440c..9afb9b25 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -92,7 +92,7 @@ def add_annotations(data): start=float(a['in']), end=float(a['out']), value=value) annotation.save() - #update facets if needed + # update facets if needed if layer_id in item.facet_keys: item.update_layer_facet(layer_id) if annotation: diff --git a/pandora/item/models.py b/pandora/item/models.py index 36220356..ad3f991f 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -79,9 +79,11 @@ def get_item(info, user=None): item_data['year'] = info.get('year', '') or '' # add additional item metadata parsed from path - for key in [i for i in info if i in set([k['id'] for k in settings.CONFIG['itemKeys']]) - and i not in ('language', ) and i not in item_data]: - item_data[key] = info[key] + ignore_keys = set(list(Item.base_keys) + ['language'] + list(item_data)) + possible_keys = set([k['id'] for k in settings.CONFIG['itemKeys'] if k['id'] not in ignore_keys]) + for key in info: + if key in possible_keys: + item_data[key] = info[key] for key in ('episodeTitle', 'episodeDirector', 'episodeYear', 'season', 'episode', 'seriesTitle'): @@ -830,6 +832,37 @@ class Item(models.Model): self.get('seriesTitle')))) is not None save('series', isSeries) + base_keys = ( + 'aspectratio', + 'bitrate', + 'clips', + 'created', + 'cutsperminute', + 'duration', + 'hue', + 'id', + 'oxdbId', + 'lightness', + 'modified', + 'numberofannotations', + 'numberofcuts', + 'numberofdocuments', + 'numberoffiles', + 'parts', + 'pixels', + 'random', + 'timesaccessed', + 'accessed', + 'resolution', + 'width', + 'height', + 'rendered', + 'rightslevel', + 'saturation', + 'size', + 'volume', + ) + def update_sort(self): try: s = self.sort @@ -865,36 +898,6 @@ class Item(models.Model): value = len(value.split(' ')) if value else 0 return value - base_keys = ( - 'aspectratio', - 'bitrate', - 'clips', - 'created', - 'cutsperminute', - 'duration', - 'hue', - 'id', - 'oxdbId', - 'lightness', - 'modified', - 'numberofannotations', - 'numberofcuts', - 'numberofdocuments', - 'numberoffiles', - 'parts', - 'pixels', - 'random', - 'timesaccessed', - 'accessed', - 'resolution', - 'width', - 'height', - 'rendered', - 'rightslevel', - 'saturation', - 'size', - 'volume', - ) # sort keys based on database, these will always be available s.public_id = self.public_id.replace('0x', 'xx') @@ -971,7 +974,7 @@ class Item(models.Model): sort_type = key['value'].get('type', sort_type) if isinstance(sort_type, list): sort_type = sort_type[0] - if name not in base_keys: + if name not in self.base_keys: if sort_type == 'title': value = get_title_sort(self.get(source, u'Untitled')) value = utils.sort_title(value)[:955]