unique urls
This commit is contained in:
parent
3cf265e461
commit
6c3c128dc9
3 changed files with 76 additions and 3 deletions
70
oxdata/poster/migrations/0004_unique_urls.py
Normal file
70
oxdata/poster/migrations/0004_unique_urls.py
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
import datetime
|
||||||
|
from south.db import db
|
||||||
|
from south.v2 import SchemaMigration
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
class Migration(SchemaMigration):
|
||||||
|
|
||||||
|
def forwards(self, orm):
|
||||||
|
|
||||||
|
# Removing unique constraint on 'PosterCache', fields ['url']
|
||||||
|
db.delete_unique('poster_postercache', ['url'])
|
||||||
|
|
||||||
|
# Adding unique constraint on 'PosterCache', fields ['url', 'movie_id']
|
||||||
|
db.create_unique('poster_postercache', ['url', 'movie_id_id'])
|
||||||
|
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
|
||||||
|
# Adding unique constraint on 'PosterCache', fields ['url']
|
||||||
|
db.create_unique('poster_postercache', ['url'])
|
||||||
|
|
||||||
|
# Removing unique constraint on 'PosterCache', fields ['url', 'movie_id']
|
||||||
|
db.delete_unique('poster_postercache', ['url', 'movie_id_id'])
|
||||||
|
|
||||||
|
|
||||||
|
models = {
|
||||||
|
'lookup.movieid': {
|
||||||
|
'Meta': {'object_name': 'MovieId'},
|
||||||
|
'amg_id': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||||
|
'criterion_id': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'director': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '1000', 'blank': 'True'}),
|
||||||
|
'episode': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
|
||||||
|
'episode_title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '1000', 'blank': 'True'}),
|
||||||
|
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'imdb_id': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '7', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'impawards_id': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||||
|
'oxdb_id': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '42', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'season': ('django.db.models.fields.IntegerField', [], {'default': '-1'}),
|
||||||
|
'series_title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '1000', 'blank': 'True'}),
|
||||||
|
'title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '1000', 'blank': 'True'}),
|
||||||
|
'wikipedia_id': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'year': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '4', 'blank': 'True'})
|
||||||
|
},
|
||||||
|
'poster.poster': {
|
||||||
|
'Meta': {'object_name': 'Poster'},
|
||||||
|
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||||
|
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||||
|
'movie_id': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'poster'", 'to': "orm['lookup.MovieId']"}),
|
||||||
|
'poster': ('django.db.models.fields.files.ImageField', [], {'max_length': '255'})
|
||||||
|
},
|
||||||
|
'poster.postercache': {
|
||||||
|
'Meta': {'unique_together': "(('movie_id', 'url'),)", 'object_name': 'PosterCache'},
|
||||||
|
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||||
|
'failed': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
|
||||||
|
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '255'}),
|
||||||
|
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||||
|
'movie_id': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'postercache'", 'to': "orm['lookup.MovieId']"}),
|
||||||
|
'site': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'site_id': ('django.db.models.fields.CharField', [], {'max_length': '42'}),
|
||||||
|
'status': ('django.db.models.fields.CharField', [], {'default': "'200'", 'max_length': '1024'}),
|
||||||
|
'url': ('django.db.models.fields.CharField', [], {'max_length': '1024'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['poster']
|
|
@ -50,11 +50,14 @@ def poster_path(url, filename):
|
||||||
return os.path.join('posters', h[:2], h[2:4], h[4:6], name)
|
return os.path.join('posters', h[:2], h[2:4], h[4:6], name)
|
||||||
|
|
||||||
class PosterCache(models.Model):
|
class PosterCache(models.Model):
|
||||||
|
class Meta:
|
||||||
|
unique_together = ("movie_id", "url")
|
||||||
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
movie_id = models.ForeignKey(MovieId, related_name='postercache')
|
movie_id = models.ForeignKey(MovieId, related_name='postercache')
|
||||||
url = models.CharField(max_length=1024, unique=True)
|
url = models.CharField(max_length=1024)
|
||||||
site = models.CharField(max_length=255)
|
site = models.CharField(max_length=255)
|
||||||
site_id = models.CharField(max_length=42)
|
site_id = models.CharField(max_length=42)
|
||||||
image = models.ImageField(max_length=255, upload_to=lambda i, f: poster_path(i.url.encode('utf-8'), f))
|
image = models.ImageField(max_length=255, upload_to=lambda i, f: poster_path(i.url.encode('utf-8'), f))
|
||||||
|
@ -99,7 +102,7 @@ class Poster(models.Model):
|
||||||
|
|
||||||
def getPosterUrls(m):
|
def getPosterUrls(m):
|
||||||
def addPoster(url, site, site_id):
|
def addPoster(url, site, site_id):
|
||||||
if PosterCache.objects.all().filter(url=url).count() == 0:
|
if PosterCache.objects.all().filter(url=url, movie_id=m).count() == 0:
|
||||||
p = PosterCache(url=url, site=site, site_id=site_id, movie_id=m)
|
p = PosterCache(url=url, site=site, site_id=site_id, movie_id=m)
|
||||||
p.save()
|
p.save()
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ def cronjob(**kwargs):
|
||||||
def getMovieposteredb(imdb_id):
|
def getMovieposteredb(imdb_id):
|
||||||
m = getMovieIdByImdbId(imdb_id)
|
m = getMovieIdByImdbId(imdb_id)
|
||||||
def addPoster(url, site, site_id):
|
def addPoster(url, site, site_id):
|
||||||
if PosterCache.objects.all().filter(url=url).count() == 0:
|
if PosterCache.objects.all().filter(url=url, movie_id=m).count() == 0:
|
||||||
p = PosterCache(url=url, site=site, site_id=site_id, movie_id=m)
|
p = PosterCache(url=url, site=site, site_id=site_id, movie_id=m)
|
||||||
p.save()
|
p.save()
|
||||||
for poster in ox.web.movieposterdb.getData(imdb_id)['posters']:
|
for poster in ox.web.movieposterdb.getData(imdb_id)['posters']:
|
||||||
|
|
Loading…
Reference in a new issue