From 1d38283276d57c7ca572f501b72c8320f3401d59 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 14 Oct 2011 14:55:45 +0200 Subject: [PATCH] find, posters, typos --- oxdata/movie/models.py | 15 +++++++++++---- oxdata/movie/views.py | 37 ++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/oxdata/movie/models.py b/oxdata/movie/models.py index 98f9c71..3a7ba2e 100644 --- a/oxdata/movie/models.py +++ b/oxdata/movie/models.py @@ -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] diff --git a/oxdata/movie/views.py b/oxdata/movie/views.py index bf03a2e..49d03c6 100644 --- a/oxdata/movie/views.py +++ b/oxdata/movie/views.py @@ -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 '%s' % ( + quote(m.group(2).encode('utf-8')), m.group(2) + ) + t = re.sub('(.*?)', fix_names, t) + def fix_titles(m): + return '%s' % ( + quote(m.group(2).encode('utf-8')), m.group(2) + ) + t = re.sub('(.*?)', fix_titles, t) + return t if 'trivia' in data: - def fix_links(t): - def fix_names(m): - return '%s' % ( - quote(m.group(2).encode('utf-8')), m.group(2) - ) - t = re.sub('(.*?)', fix_names, t) - def fix_titles(m): - return '%s' % ( - quote(m.group(2).encode('utf-8')), m.group(2) - ) - t = re.sub('(.*?)', 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}