From ba3d1538f45efb9c925e3adc34328fd63d914e36 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 26 Feb 2013 16:12:00 +0000 Subject: [PATCH] use isSubtitles itemKey for subtitles --- pandora/item/models.py | 5 +++-- pandora/item/utils.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index bc42cd9bc..461a80b84 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1249,10 +1249,11 @@ class Item(models.Model): return icon def load_subtitles(self): - if not utils.get_by_id(settings.CONFIG['layers'], 'subtitles'): + subtitles = utils.get_by_key(settings.CONFIG['layers'], 'isSubtitles', True) + if not subtitles: return False with transaction.commit_on_success(): - layer = 'subtitles' + layer = subtitles['id'] Annotation.objects.filter(layer=layer,item=self).delete() offset = 0 language = '' diff --git a/pandora/item/utils.py b/pandora/item/utils.py index 3f7a499f6..fd0eee418 100644 --- a/pandora/item/utils.py +++ b/pandora/item/utils.py @@ -70,6 +70,9 @@ def get_positions(ids, pos): pass return positions -def get_by_id(objects, id): - obj = filter(lambda o: o['id'] == id, objects) +def get_by_key(objects, key, value): + obj = filter(lambda o: o.get(key) == value, objects) return obj and obj[0] or None + +def get_by_id(objects, id): + return get_by_key(objects, 'id', id)