register likes

This commit is contained in:
j 2012-09-25 16:38:33 +02:00
parent acfd3e1fbc
commit 02527457bb
3 changed files with 26 additions and 0 deletions

View file

@ -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 = {}

View file

@ -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()

View file

@ -157,10 +157,15 @@ 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 = []
movie_id = get_movie_id(imdb_id=self.imdb)