From ea859b54ec20b1456e93d22d47ec5a36ff5325b5 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 30 Jul 2011 14:52:49 +0200 Subject: [PATCH] set poster source --- pandora/item/models.py | 17 +++++++---------- pandora/item/views.py | 8 ++++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 6e3f6e9ac..e258ad307 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -127,7 +127,7 @@ class Item(models.Model): json = fields.DictField(default={}, editable=False) poster = models.ImageField(default=None, blank=True, upload_to=lambda i, x: i.path("poster.jpg")) - poster_url = models.TextField(blank=True) + poster_source = models.TextField(blank=True) poster_height = models.IntegerField(default=0) poster_width = models.IntegerField(default=0) poster_frame = models.FloatField(default=-1) @@ -299,12 +299,6 @@ class Item(models.Model): poster['width'] = self.poster_width poster['height'] = self.poster_height poster['url'] = '/%s/poster.jpg' % self.itemId - ''' - if self.poster: - poster['url'] = self.poster.url - else: - poster['url'] = self.poster_url - ''' return poster def get_posters(self): @@ -789,12 +783,15 @@ class Item(models.Model): os.unlink(f) def prefered_poster_url(self): - if self.poster_url: - return self.poster_url self.update_poster_urls() - for service in settings.POSTER_PRECEDENCE: + service = self.poster_source + if service and service != settings.URL: for u in self.poster_urls.filter(service=service).order_by('-height'): return u.url + if not service: + for service in settings.POSTER_PRECEDENCE: + for u in self.poster_urls.filter(service=service).order_by('-height'): + return u.url return None def make_poster(self, force=False): diff --git a/pandora/item/views.py b/pandora/item/views.py index c8dcfc5e3..b8e042e40 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -460,7 +460,7 @@ def setPoster(request): #parse path and return info ''' param data { id: itemId, - url: string + source: string } return { status: {'code': int, 'text': string}, @@ -473,9 +473,9 @@ def setPoster(request): #parse path and return info item = get_object_or_404_json(models.Item, itemId=data['id']) response = json_response() if item.editable(request.user): - valid_urls = [p['url'] for p in item.get_posters()] - if data['url'] in valid_urls: - item.poster_url = data['url'] + valid_sources = [p['source'] for p in item.get_posters()] + if data['source'] in valid_sources: + item.poster_source = data['source'] if item.poster: item.poster.delete() item.save()