fix import

This commit is contained in:
j 2011-02-22 17:09:13 +01:00
parent b5b4afec5e
commit 72b8f86172
3 changed files with 10 additions and 7 deletions

View file

@ -15,6 +15,7 @@ from glob import glob
import numpy as np import numpy as np
import Image import Image
import ox import ox
import ox.image
img_extension='jpg' img_extension='jpg'

View file

@ -13,7 +13,7 @@ import models
_INSTANCE_KEYS = ('mtime', 'name', 'folder') _INSTANCE_KEYS = ('mtime', 'name', 'folder')
def get_or_create_item(volume, f): def get_or_create_item(volume, f, user):
in_same_folder = models.Instance.objects.filter(folder=f['folder'], volume=volume) in_same_folder = models.Instance.objects.filter(folder=f['folder'], volume=volume)
if in_same_folder.count() > 0: if in_same_folder.count() > 0:
i = in_same_folder[0].file.item i = in_same_folder[0].file.item
@ -22,17 +22,17 @@ def get_or_create_item(volume, f):
item_info = parse_path(f['folder']) item_info = parse_path(f['folder'])
else: else:
item_info = parse_path(f['path']) item_info = parse_path(f['path'])
i = get_item(item_info) i = get_item(item_info, user)
return i return i
def get_or_create_file(volume, f): def get_or_create_file(volume, f, user):
try: try:
file = models.File.objects.get(oshash=f['oshash']) file = models.File.objects.get(oshash=f['oshash'])
except models.File.DoesNotExist: except models.File.DoesNotExist:
file = models.File() file = models.File()
file.oshash = f['oshash'] file.oshash = f['oshash']
file.name = f['name'] file.name = f['name']
file.item = get_or_create_item(volume, f) file.item = get_or_create_item(volume, f, user)
file.save() file.save()
return file return file
@ -50,7 +50,7 @@ def update_or_create_instance(volume, f):
else: else:
instance = models.Instance() instance = models.Instance()
instance.volume = volume instance.volume = volume
instance.file = get_or_create_file(volume, f) instance.file = get_or_create_file(volume, f, volume.user)
for key in _INSTANCE_KEYS: for key in _INSTANCE_KEYS:
setattr(instance, key, f[key]) setattr(instance, key, f[key])
instance.save() instance.save()

View file

@ -31,7 +31,7 @@ from person.models import get_name_sort
from app.models import site_config from app.models import site_config
def get_item(info): def get_item(info, user=None):
''' '''
info dict with: info dict with:
imdbId, title, director, episode_title, season, series imdbId, title, director, episode_title, season, series
@ -48,6 +48,7 @@ def get_item(info):
'director': info['director'], 'director': info['director'],
'year': info.get('year', '') 'year': info.get('year', '')
} }
item.user = user
item.save() item.save()
tasks.update_external.delay(item.itemId) tasks.update_external.delay(item.itemId)
else: else:
@ -84,6 +85,7 @@ def get_item(info):
item.data = { item.data = {
'title': info['title'] 'title': info['title']
} }
item.user = user
item.save() item.save()
return item return item
@ -93,7 +95,7 @@ class Item(models.Model):
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
published = models.DateTimeField(default=datetime.now, editable=False) published = models.DateTimeField(default=datetime.now, editable=False)
user = models.ForeignKey(User, related_name='items') user = models.ForeignKey(User, null=True, related_name='items')
groups = models.ManyToManyField(Group, related_name='items') groups = models.ManyToManyField(Group, related_name='items')
#only items that have data from files are available, #only items that have data from files are available,