From 02527457bb3df8d905c2ee840f6d601d27890692 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 25 Sep 2012 16:38:33 +0200 Subject: [PATCH] register likes --- oxdata/lookup/models.py | 5 +++++ oxdata/lookup/modules.py | 16 ++++++++++++++++ oxdata/movie/models.py | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/oxdata/lookup/models.py b/oxdata/lookup/models.py index 84152ba..e5b2ddc 100644 --- a/oxdata/lookup/models.py +++ b/oxdata/lookup/models.py @@ -16,6 +16,8 @@ import ox.web.imdb import ox.web.wikipedia import ox.web.allmovie +from modules import get_likes + def get_movie_id(imdb_id): #movies moved in imdb @@ -142,6 +144,9 @@ class MovieId(models.Model): 'url': 'http://google.com/search?q=%s' % quote(qs.encode('utf-8'))}) return links + def likes(self): + return get_likes(self) + def json(self, prefix): from poster.models import getPosters json = {} diff --git a/oxdata/lookup/modules.py b/oxdata/lookup/modules.py index ccd2fec..71de8ea 100644 --- a/oxdata/lookup/modules.py +++ b/oxdata/lookup/modules.py @@ -13,3 +13,19 @@ class IdModules(object): get_ids = IdModules() + +class Likes(object): + def __init__(self): + self._registry = {} + + def __call__(self, movie_id): + for name in self._registry: + return self._registry[name](movie_id) + return 0 + + def register(self, name, get_likes): + if name not in self._registry: + self._registry[name] = get_likes + +get_likes = Likes() + diff --git a/oxdata/movie/models.py b/oxdata/movie/models.py index 714956b..b1c466d 100644 --- a/oxdata/movie/models.py +++ b/oxdata/movie/models.py @@ -157,9 +157,14 @@ class Imdb(models.Model): if not data['reviews']: del data['reviews'] + data['likes'] = self.likes() data['links'] = self.links() data['posters'] = self.posters(request) return data + + def likes(self): + movie_id = get_movie_id(imdb_id=self.imdb) + return movie_id and movie_id.likes() or 0 def links(self): links = []