find, posters, typos

This commit is contained in:
j 2011-10-14 14:55:45 +02:00
parent 7fc52f5076
commit 1d38283276
2 changed files with 35 additions and 17 deletions

View file

@ -11,9 +11,12 @@ def find(info):
q = Imdb.objects.all()
for key in Imdb.keys:
if key in info and info[key]:
fkey = '%s_iexact'
if isinstance(info[key], basestring):
fkey = '%s__iexact'%key
else:
fkey = key
if isinstance(info[key], list):
q = q.filter(**{fkey: '\n'.join(info[key])})
q = q.filter(**{fkey: '\n'.join(info[key]) + '\n'})
else:
q = q.filter(**{fkey:info[key]})
if q.count() == 1:
@ -27,7 +30,7 @@ class Imdb(models.Model):
imdb = models.CharField(max_length=7, unique=True)
title = models.CharField(max_length=1000, blank=True, default='')
year = models.CharField(max_length=4, blank=True, default='')
director = models.CharField(max_length=1000, blank=True, default='')
director = models.CharField(max_length=9000, blank=True, default='')
season = models.IntegerField(blank=True, null=True)
episode = models.IntegerField(blank=True, null=True)
@ -59,6 +62,10 @@ class Imdb(models.Model):
if isinstance(value, list):
value = '\n'.join(value) + '\n'
setattr(self, key, value)
if self.season < 0:
self.season = None
if self.episode < 0:
self.episode = None
self.save()
def json(self):
@ -67,7 +74,7 @@ class Imdb(models.Model):
for key in self.keys:
j[key] = getattr(self, key)
for key in ('director', 'episodeDirector'):
if j[key].srip():
if j[key].strip():
j[key] = j[key].strip().split('\n')
else:
del j[key]

View file

@ -11,10 +11,15 @@ import ox.web.imdb
from ox.utils import json
from api.actions import actions
from poster.models import getPosters
from lookup.models import getMovieIdByImdbId
import models
def posters(request, imdbId):
movie_id = getMovieIdByImdbId(imdb_id=imdbId)
return getPosters(movie_id, request.build_absolute_uri('/'))
def getId(request):
data = json.loads(request.POST['data'])
response = json_response()
@ -32,6 +37,9 @@ def getData(request):
id = data['id']
if len(id) == 7:
data = ox.web.imdb.Imdb(id)
i, created = models.Imdb.objects.get_or_create(imdb=id)
if created:
i.update()
#FIXME: all this should be in ox.web.imdb.Imdb
for key in ('directors', 'writers', 'editors', 'producers',
'cinematographers', 'languages', 'genres', 'keywords',
@ -51,20 +59,22 @@ def getData(request):
data['cast'] = [data['cast']]
data['actor'] = [c[0] for c in data['cast']]
data['cast'] = map(lambda x: {'actor': x[0], 'character': x[1]}, data['cast'])
def fix_links(t):
def fix_names(m):
return '<a href="/name=%s">%s</a>' % (
quote(m.group(2).encode('utf-8')), m.group(2)
)
t = re.sub('<a href="(/name/.*?/)">(.*?)</a>', fix_names, t)
def fix_titles(m):
return '<a href="/title=%s">%s</a>' % (
quote(m.group(2).encode('utf-8')), m.group(2)
)
t = re.sub('<a href="(/title/.*?/)">(.*?)</a>', fix_titles, t)
return t
if 'trivia' in data:
def fix_links(t):
def fix_names(m):
return '<a href="/name=%s">%s</a>' % (
quote(m.group(2).encode('utf-8')), m.group(2)
)
t = re.sub('<a href="(/name/.*?/)">(.*?)</a>', fix_names, t)
def fix_titles(m):
return '<a href="/title=%s">%s</a>' % (
quote(m.group(2).encode('utf-8')), m.group(2)
)
t = re.sub('<a href="(/title/.*?/)">(.*?)</a>', fix_titles, t)
return t
data['trivia'] = [fix_links(t) for t in data['trivia']]
if 'summary' in data:
data['summary'] = fix_links(data['summary'])
if 'aspectratio' in data:
data['aspectRatio'] = data.pop('aspectratio')
@ -81,6 +91,7 @@ def getData(request):
if not data['reviews']:
del data['reviews']
data['posters'] = posters(request, id)
response['data'] = data
else:
response['status'] = {'text':'not found', 'code': 404}