use ox/ox.web/ox.django

This commit is contained in:
j 2009-10-11 15:00:16 +02:00
parent f68c43780c
commit e98b6828fe
9 changed files with 27 additions and 59 deletions

View file

@ -5,8 +5,8 @@ import os.path
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
import oxweb.imdb import ox.web.imdb
from oxlib import stripTags, findRe from ox import stripTags, findRe
import models import models
@ -37,7 +37,7 @@ def loadIMDb(imdbId):
movie = models.Movie() movie = models.Movie()
movie.imdb = imdb movie.imdb = imdb
info = oxweb.imdb.getMovieInfo(imdbId) info = ox.web.imdb.getMovieInfo(imdbId)
for key in ('title', for key in ('title',
'tagline', 'tagline',
'year', 'year',
@ -58,11 +58,11 @@ def loadIMDb(imdbId):
if key in info: if key in info:
setattr(movie.imdb, _info_map.get(key, key), info[key]) setattr(movie.imdb, _info_map.get(key, key), info[key])
movie.imdb.plot = oxweb.imdb.getMoviePlot(imdbId) movie.imdb.plot = ox.web.imdb.getMoviePlot(imdbId)
debug("plot", movie.imdb.plot) debug("plot", movie.imdb.plot)
movie.imdb.runtime = oxweb.imdb.getMovieRuntimeSeconds(imdbId) movie.imdb.runtime = ox.web.imdb.getMovieRuntimeSeconds(imdbId)
business = oxweb.imdb.getMovieBusinessSum(imdbId) business = ox.web.imdb.getMovieBusinessSum(imdbId)
for key in ('gross', 'profit', 'budget'): for key in ('gross', 'profit', 'budget'):
setattr(movie.imdb, key, business[key]) setattr(movie.imdb, key, business[key])
@ -70,7 +70,7 @@ def loadIMDb(imdbId):
movie.oxdbId = "__init__%s" % random.randint(0, 100000) movie.oxdbId = "__init__%s" % random.randint(0, 100000)
movie.save() movie.save()
models.AlternativeTitle.objects.filter(movie=movie, manual=False).delete() models.AlternativeTitle.objects.filter(movie=movie, manual=False).delete()
for i in oxweb.imdb.getMovieAKATitles(imdbId): for i in ox.web.imdb.getMovieAKATitles(imdbId):
t = models.AlternativeTitle() t = models.AlternativeTitle()
t.movie = movie t.movie = movie
t.title = i[0] t.title = i[0]
@ -100,7 +100,7 @@ def loadIMDb(imdbId):
#Location #Location
movie.locations_all.filter(manual=False).delete() movie.locations_all.filter(manual=False).delete()
locations = oxweb.imdb.getMovieLocations(imdbId) locations = ox.web.imdb.getMovieLocations(imdbId)
for i in locations: for i in locations:
debug("add location", i) debug("add location", i)
location = models.Location.get_or_create(i) location = models.Location.get_or_create(i)
@ -116,7 +116,7 @@ def loadIMDb(imdbId):
#Keyword #Keyword
movie.keywords_all.filter(manual=False).delete() movie.keywords_all.filter(manual=False).delete()
keywords = oxweb.imdb.getMovieKeywords(imdbId) keywords = ox.web.imdb.getMovieKeywords(imdbId)
for g in keywords: for g in keywords:
debug("add keyword", g) debug("add keyword", g)
keyword = models.Keyword.get_or_create(g) keyword = models.Keyword.get_or_create(g)
@ -124,7 +124,7 @@ def loadIMDb(imdbId):
movie.trivia_all.filter(manual=False).delete() movie.trivia_all.filter(manual=False).delete()
position = 0 position = 0
trivia = oxweb.imdb.getMovieTrivia(imdbId) trivia = ox.web.imdb.getMovieTrivia(imdbId)
for i in trivia: for i in trivia:
debug("add trivia", i) debug("add trivia", i)
t = models.Trivia() t = models.Trivia()
@ -136,7 +136,7 @@ def loadIMDb(imdbId):
position = 0 position = 0
models.Cast.objects.filter(movie=movie).filter(manual=False).delete() models.Cast.objects.filter(movie=movie).filter(manual=False).delete()
credits = oxweb.imdb.getMovieCredits(imdbId) credits = ox.web.imdb.getMovieCredits(imdbId)
for role in credits: for role in credits:
for p in credits[role]: for p in credits[role]:
name = stripTags(p[0]) name = stripTags(p[0])
@ -149,7 +149,7 @@ def loadIMDb(imdbId):
position += 1 position += 1
movie.connections_all.filter(manual=False).delete() movie.connections_all.filter(manual=False).delete()
connections = oxweb.imdb.getMovieConnections(imdbId) connections = ox.web.imdb.getMovieConnections(imdbId)
for relation in connections: for relation in connections:
for otherId in connections[relation]: for otherId in connections[relation]:
try: try:
@ -159,7 +159,7 @@ def loadIMDb(imdbId):
except models.Movie.DoesNotExist: except models.Movie.DoesNotExist:
pass pass
reviews = oxweb.imdb.getMovieExternalReviews(imdbId) reviews = ox.web.imdb.getMovieExternalReviews(imdbId)
movie.reviews_all.filter(manual=False).delete() movie.reviews_all.filter(manual=False).delete()
for r in reviews: for r in reviews:
debug("add review", r) debug("add review", r)

View file

@ -7,9 +7,9 @@ import random
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
from django.contrib.auth.models import User from django.contrib.auth.models import User
import oxlib import ox
from oxlib import stripTags from ox import stripTags
from oxlib.normalize import canonicalTitle, canonicalName from ox.normalize import canonicalTitle, canonicalName
import utils import utils
import managers import managers
@ -522,7 +522,7 @@ class Person(models.Model):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.name_sort: if not self.name_sort:
self.name_sort = oxlib.normalize.canonicalName(self.name) self.name_sort = ox.normalize.canonicalName(self.name)
super(Person, self).save(*args, **kwargs) super(Person, self).save(*args, **kwargs)
def get_or_create(model, name, imdbId=None): def get_or_create(model, name, imdbId=None):
@ -736,7 +736,7 @@ class Trivia(models.Model):
def json(self): def json(self):
trivia = self.trivia trivia = self.trivia
trivia = oxlib.fixAmpersands(trivia) trivia = ox.fixAmpersands(trivia)
trivia = re.sub('<a href="(/name/nm.*?)">(.*?)</a>', '<a href="/?f=name&amp;q=\\2">\\2</a>', trivia) trivia = re.sub('<a href="(/name/nm.*?)">(.*?)</a>', '<a href="/?f=name&amp;q=\\2">\\2</a>', trivia)
trivia = re.sub('<a href="/title/tt(.*?)/">(.*?)</a>', '<a href="/\\1">\\2</a>', trivia) trivia = re.sub('<a href="/title/tt(.*?)/">(.*?)</a>', '<a href="/\\1">\\2</a>', trivia)
return trivia return trivia

View file

@ -8,9 +8,9 @@ import sys
import re import re
import hashlib import hashlib
import oxlib import ox
import oxlib.iso import ox.iso
from oxlib.normalize import normalizeName from ox.normalize import normalizeName
def oxid(title, director, year='', seriesTitle='', episodeTitle='', season=0, episode=0): def oxid(title, director, year='', seriesTitle='', episodeTitle='', season=0, episode=0):
oxid_value = u"\n".join([title, director, year]) oxid_value = u"\n".join([title, director, year])
@ -62,7 +62,7 @@ def oxdb_title(_title, searchTitle = False):
return title return title
def oxdb_year(data): def oxdb_year(data):
return oxlib.findRe(data, '\.(\d{4})\.') return ox.findRe(data, '\.(\d{4})\.')
def oxdb_series_title(path): def oxdb_series_title(path):
seriesTitle = u'' seriesTitle = u''

View file

@ -12,8 +12,8 @@ from django.template import RequestContext
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.utils import simplejson as json from django.utils import simplejson as json
from oxdb.utils.shortcuts import render_to_json_response from ox.django.shortcuts import render_to_json_response
from oxdb.utils.decorators import login_required_json from ox.django.decorators import login_required_json
import models import models
import utils import utils

View file

@ -6,8 +6,8 @@ from django.shortcuts import render_to_response, get_object_or_404, get_list_or_
from django.template import RequestContext from django.template import RequestContext
from django.utils import simplejson as json from django.utils import simplejson as json
from oxdb.utils.shortcuts import render_to_json_response from ox.django.shortcuts import render_to_json_response
from oxdb.utils.decorators import login_required_json from ox.django.decorators import login_required_json
import models import models

View file

View file

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.contrib.auth.decorators import user_passes_test
def login_required_json(function=None):
"""
Decorator for views that checks that the user is logged in
return json error if not logged in.
"""
actual_decorator = user_passes_test(
lambda u: u.is_authenticated(),
login_url='/json/login',
)
if function:
return actual_decorator(function)
return actual_decorator

View file

@ -1,14 +0,0 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.http import HttpResponse
from django.utils import simplejson
from django.conf import settings
def render_to_json_response(dictionary, content_type="text/json"):
indent=None
if settings.DEBUG:
content_type = "text/javascript"
indent = 2
return HttpResponse(simplejson.dumps(dictionary, indent=indent), content_type=content_type)

View file

@ -15,7 +15,7 @@ sys.path.append(root_dir)
sys.path.append(os.path.join(root_dir, project_module)) sys.path.append(os.path.join(root_dir, project_module))
#reload if this django.wsgi gets touched #reload if this django.wsgi gets touched
from utils import monitor from ox.django import monitor
monitor.start(interval=1.0) monitor.start(interval=1.0)
monitor.track(os.path.abspath(os.path.dirname(__file__))) monitor.track(os.path.abspath(os.path.dirname(__file__)))