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'])
|
||||
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:
|
||||
if len(data['itemId']) != 7:
|
||||
del data['itemId']
|
||||
item = get_item(data)
|
||||
i = get_item(data)
|
||||
else:
|
||||
item = get_item({'imdbId': data['itemId']})
|
||||
i = get_item({'imdbId': data['itemId']})
|
||||
changed = []
|
||||
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:
|
||||
changed.append(f.item.itemId)
|
||||
if item.itemId not in changed:
|
||||
changed.append(item.itemId)
|
||||
f.item = item
|
||||
if i.itemId not in changed:
|
||||
changed.append(i.itemId)
|
||||
f.item = i
|
||||
f.save()
|
||||
for itemId in changed:
|
||||
c = models.Item.objects.get(itemId=itemId)
|
||||
c.rendered = False
|
||||
c.save()
|
||||
item.tasks.update_streams.delay(itemId)
|
||||
response = json_response(text='updated')
|
||||
response['data']['itemId'] = item.itemId
|
||||
response['data']['itemId'] = i.itemId
|
||||
return render_to_json_response(response)
|
||||
actions.register(moveFiles, cache=False)
|
||||
|
||||
|
|
|
@ -56,10 +56,24 @@ def get_item(info, user=None):
|
|||
item.save()
|
||||
tasks.update_external.delay(item.itemId)
|
||||
else:
|
||||
q = Item.objects.filter(find__key='title', find__value=info['title'])
|
||||
if q.count() > 1:
|
||||
print "FIXME: check more than title here!!?"
|
||||
q = Item.objects.all()
|
||||
for key in ('title', 'director', 'year'):
|
||||
if key in info and info[key]:
|
||||
q = q.filter(find__key=key, find__value=info[key])
|
||||
if q.count() >= 1:
|
||||
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:
|
||||
try:
|
||||
item = Item.objects.get(itemId=info['oxdbId'])
|
||||
|
@ -223,6 +237,11 @@ class Item(models.Model):
|
|||
|
||||
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:
|
||||
self.poster_height = self.poster.height
|
||||
self.poster_width = self.poster.width
|
||||
|
@ -714,7 +733,7 @@ class Item(models.Model):
|
|||
self.make_local_posters()
|
||||
self.make_poster()
|
||||
self.make_icon()
|
||||
self.rendered = True
|
||||
self.rendered = files != {}
|
||||
self.save()
|
||||
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue