move files to items without id
This commit is contained in:
parent
82336011d5
commit
87584f74fb
2 changed files with 35 additions and 13 deletions
|
@ -239,26 +239,29 @@ def moveFiles(request):
|
||||||
'''
|
'''
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
if models.Item.objects.filter(itemId=data['itemId']).count() == 1:
|
if models.Item.objects.filter(itemId=data['itemId']).count() == 1:
|
||||||
item = models.Item.objects.get(itemId=data['itemId'])
|
i = models.Item.objects.get(itemId=data['itemId'])
|
||||||
else:
|
else:
|
||||||
if len(data['itemId']) != 7:
|
if len(data['itemId']) != 7:
|
||||||
del data['itemId']
|
del data['itemId']
|
||||||
item = get_item(data)
|
i = get_item(data)
|
||||||
else:
|
else:
|
||||||
item = get_item({'imdbId': data['itemId']})
|
i = get_item({'imdbId': data['itemId']})
|
||||||
changed = []
|
changed = []
|
||||||
for f in models.File.objects.filter(oshash__in=data['ids']):
|
for f in models.File.objects.filter(oshash__in=data['ids']):
|
||||||
if f.item.id != data['itemId'] and f.editable(request.user):
|
if f.item.id != i.itemId and f.editable(request.user):
|
||||||
if f.item.itemId not in changed:
|
if f.item.itemId not in changed:
|
||||||
changed.append(f.item.itemId)
|
changed.append(f.item.itemId)
|
||||||
if item.itemId not in changed:
|
if i.itemId not in changed:
|
||||||
changed.append(item.itemId)
|
changed.append(i.itemId)
|
||||||
f.item = item
|
f.item = i
|
||||||
f.save()
|
f.save()
|
||||||
for itemId in changed:
|
for itemId in changed:
|
||||||
|
c = models.Item.objects.get(itemId=itemId)
|
||||||
|
c.rendered = False
|
||||||
|
c.save()
|
||||||
item.tasks.update_streams.delay(itemId)
|
item.tasks.update_streams.delay(itemId)
|
||||||
response = json_response(text='updated')
|
response = json_response(text='updated')
|
||||||
response['data']['itemId'] = item.itemId
|
response['data']['itemId'] = i.itemId
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(moveFiles, cache=False)
|
actions.register(moveFiles, cache=False)
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,24 @@ def get_item(info, user=None):
|
||||||
item.save()
|
item.save()
|
||||||
tasks.update_external.delay(item.itemId)
|
tasks.update_external.delay(item.itemId)
|
||||||
else:
|
else:
|
||||||
q = Item.objects.filter(find__key='title', find__value=info['title'])
|
q = Item.objects.all()
|
||||||
if q.count() > 1:
|
for key in ('title', 'director', 'year'):
|
||||||
print "FIXME: check more than title here!!?"
|
if key in info and info[key]:
|
||||||
|
q = q.filter(find__key=key, find__value=info[key])
|
||||||
|
if q.count() >= 1:
|
||||||
item = q[0]
|
item = q[0]
|
||||||
|
elif not 'oxdbId' in info:
|
||||||
|
item = Item()
|
||||||
|
item.data = {
|
||||||
|
'title': info['title'],
|
||||||
|
'director': info['director'],
|
||||||
|
'year': info.get('year', '')
|
||||||
|
}
|
||||||
|
for key in ('episode_title', 'series_title', 'season', 'episode'):
|
||||||
|
if key in info and info[key]:
|
||||||
|
item.data[key] = info[key]
|
||||||
|
item.oxdbId = item.oxdb_id()
|
||||||
|
item.save()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
item = Item.objects.get(itemId=info['oxdbId'])
|
item = Item.objects.get(itemId=info['oxdbId'])
|
||||||
|
@ -223,6 +237,11 @@ class Item(models.Model):
|
||||||
|
|
||||||
self.oxdbId = self.oxdb_id()
|
self.oxdbId = self.oxdb_id()
|
||||||
|
|
||||||
|
#id changed, what about existing item with new id?
|
||||||
|
if settings.USE_IMDB and len(self.itemId) != 7 and self.oxdbId != self.itemId:
|
||||||
|
self.itemId = self.oxdbId
|
||||||
|
#FIXME: move files to new id here
|
||||||
|
|
||||||
if self.poster:
|
if self.poster:
|
||||||
self.poster_height = self.poster.height
|
self.poster_height = self.poster.height
|
||||||
self.poster_width = self.poster.width
|
self.poster_width = self.poster.width
|
||||||
|
@ -714,7 +733,7 @@ class Item(models.Model):
|
||||||
self.make_local_posters()
|
self.make_local_posters()
|
||||||
self.make_poster()
|
self.make_poster()
|
||||||
self.make_icon()
|
self.make_icon()
|
||||||
self.rendered = True
|
self.rendered = files != {}
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue