From 74d0141f42b184c41626b321a249807bed5f98bf Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 30 Jul 2011 15:51:14 +0200 Subject: [PATCH] add poster precedence to order by --- pandora/item/models.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index e258ad3..0ab7367 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -12,7 +12,7 @@ import unicodedata from urllib import quote from django.db import models -from django.db.models import Sum +from django.db.models import Sum, Count from django.core.files.base import ContentFile from django.utils import simplejson as json from django.conf import settings @@ -303,13 +303,26 @@ class Item(models.Model): def get_posters(self): url = self.prefered_poster_url() + precedence = [] + services = [p['service'] + for p in self.poster_urls.values("service") + .annotate(Count("id")).order_by()] + for service in settings.POSTER_PRECEDENCE: + if service in services: + precedence.append(service) + for service in services: + if service not in precedence: + precedence.append(service) + precedence.append(settings.URL) + posters = [ { 'url': '/%s/poster.pandora.jpg' % self.itemId, 'width': 640, 'height': 1024, 'source': settings.URL, - 'selected': url == None + 'selected': url == None, + 'precedence': precedence.index(settings.URL) } ] got = {} @@ -321,7 +334,8 @@ class Item(models.Model): 'width': p.width, 'height': p.height, 'source': p.service, - 'selected': p.url == url + 'selected': p.url == url, + 'precedence': precedence.index(p.service) }) return posters