From 7b74c5f2ec7f7a041b6a131032d531b2e75b1803 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 7 Aug 2010 18:48:10 +0200 Subject: [PATCH] update to django 1.2.x, local urls, add suggested path --- oxdata/lookup/models.py | 19 ++++++++++++++++++- oxdata/poster/views.py | 6 ++++++ oxdata/urls.py | 7 +++++++ requirements.txt | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/oxdata/lookup/models.py b/oxdata/lookup/models.py index 1f582ee..ccbf7fc 100644 --- a/oxdata/lookup/models.py +++ b/oxdata/lookup/models.py @@ -8,6 +8,7 @@ from django.db.models import Q, Max from django.contrib.auth.models import User import ox +from ox.normalize import canonicalName from ox import stripTags import ox.web.imdb import ox.web.wikipedia @@ -107,6 +108,18 @@ class MovieId(models.Model): self.oxdb_id = u"0x" + oxid self.save() + def suggested_path(self): + if self.series_title: + title = self.series_title + return os.path.join('S', 'Series', title) + else: + directors = '; '.join(map(canonicalName, self.director.split(', '))) + if not directors: directors = "Unknown Director" + title = self.title + if self.year: + title += ' (%s)' % self.year + return os.path.join(directors[0], directors, title) + def json(self): json = {} keys = [ @@ -128,7 +141,11 @@ class MovieId(models.Model): json[key] = value if 'director' in json: json['directors'] = json.pop('director').split(', ') - if 'year' in json and json['year']: json['year'] = int(json['year']) + if 'year' in json and json['year']: + json['year'] = int(json['year']) + + json['suggested_path'] = self.suggested_path() + return json diff --git a/oxdata/poster/views.py b/oxdata/poster/views.py index d6411e5..4e1c1e3 100644 --- a/oxdata/poster/views.py +++ b/oxdata/poster/views.py @@ -13,6 +13,12 @@ from oxdata.lookup.models import MovieId import models def get_movie_id(request): + if 'movieId' in request.GET: + movieId = request.GET['movieId'] + if len(movieId) == 7: + movie_id = MovieId.objects.get(imdb_id=imdbId) + else: + movie_id = MovieId.objects.get(oxdb_id=oxdbId) if 'imdb' in request.GET: imdbId = request.GET['imdb'] movie_id = MovieId.objects.get(imdb_id=imdbId) diff --git a/oxdata/urls.py b/oxdata/urls.py index 789b284..fe7e432 100644 --- a/oxdata/urls.py +++ b/oxdata/urls.py @@ -24,3 +24,10 @@ if settings.DEBUG: ) + +#load local urls if present +try: + from local_urls import urlpatterns +except ImportError: + pass + diff --git a/requirements.txt b/requirements.txt index 61a069f..be56740 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ --e svn+http://code.djangoproject.com/svn/django/branches/releases/1.1.X/#egg=django +-e svn+http://code.djangoproject.com/svn/django/branches/releases/1.2.X/#egg=django South==0.6.1 -e bzr+http://code.0x2620.org/python-oxdjango/#egg=python-oxdjango -e bzr+http://code.0x2620.org/python-ox/#egg=python-ox