register likes
This commit is contained in:
parent
acfd3e1fbc
commit
02527457bb
3 changed files with 26 additions and 0 deletions
|
@ -16,6 +16,8 @@ import ox.web.imdb
|
||||||
import ox.web.wikipedia
|
import ox.web.wikipedia
|
||||||
import ox.web.allmovie
|
import ox.web.allmovie
|
||||||
|
|
||||||
|
from modules import get_likes
|
||||||
|
|
||||||
|
|
||||||
def get_movie_id(imdb_id):
|
def get_movie_id(imdb_id):
|
||||||
#movies moved in imdb
|
#movies moved in imdb
|
||||||
|
@ -142,6 +144,9 @@ class MovieId(models.Model):
|
||||||
'url': 'http://google.com/search?q=%s' % quote(qs.encode('utf-8'))})
|
'url': 'http://google.com/search?q=%s' % quote(qs.encode('utf-8'))})
|
||||||
return links
|
return links
|
||||||
|
|
||||||
|
def likes(self):
|
||||||
|
return get_likes(self)
|
||||||
|
|
||||||
def json(self, prefix):
|
def json(self, prefix):
|
||||||
from poster.models import getPosters
|
from poster.models import getPosters
|
||||||
json = {}
|
json = {}
|
||||||
|
|
|
@ -13,3 +13,19 @@ class IdModules(object):
|
||||||
|
|
||||||
get_ids = IdModules()
|
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()
|
||||||
|
|
||||||
|
|
|
@ -157,10 +157,15 @@ class Imdb(models.Model):
|
||||||
if not data['reviews']:
|
if not data['reviews']:
|
||||||
del data['reviews']
|
del data['reviews']
|
||||||
|
|
||||||
|
data['likes'] = self.likes()
|
||||||
data['links'] = self.links()
|
data['links'] = self.links()
|
||||||
data['posters'] = self.posters(request)
|
data['posters'] = self.posters(request)
|
||||||
return data
|
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):
|
def links(self):
|
||||||
links = []
|
links = []
|
||||||
movie_id = get_movie_id(imdb_id=self.imdb)
|
movie_id = get_movie_id(imdb_id=self.imdb)
|
||||||
|
|
Loading…
Reference in a new issue