remove editFile, clenaup editFiles

This commit is contained in:
j 2013-02-08 17:05:18 +00:00
parent 7951c42609
commit e1889397b2

View file

@ -341,11 +341,12 @@ def editFiles(request):
''' '''
change file / item link change file / item link
param data { param data {
ids: ids of files files: [
part: {id:, key1: value1, key2: value2}
language: ...
ignore: boolean ]
} }
possible keys: part, partTitle, language, ignore, extension, version, episodes
return { return {
status: {'code': int, 'text': string}, status: {'code': int, 'text': string},
@ -354,70 +355,42 @@ def editFiles(request):
} }
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
files = models.File.objects.filter(oshash__in=data['ids'])
response = json_response() ignore = []
#FIXME: only editable files! dont_ignore = []
if True: response = json_response(status=200, text='updated')
if 'ignore' in data: response['data']['files'] = []
models.Instance.objects.filter(file__in=files).update(ignore=data['ignore']) for info in data['files']:
f = get_object_or_404_json(models.File, oshash=info['id'])
if f.editable(request.user):
if 'ignore' in info:
if info['ignore']:
ignore.append(info['id'])
else:
dont_ignore.append(info['id'])
update = False
for key in ('episodes', 'extension', 'language', 'part', 'partTitle', 'version'):
if key in info:
f.path_info[key] = info[key]
update = True
if update:
f.save()
response['data']['files'].append(f.json())
else:
response['data']['files'].append({'id': info['id'], 'error': 'permission denied'})
if ignore:
models.Instance.objects.filter(file__oshash__in=ignore).update(ignore=True)
if dont_ignore:
models.Instance.objects.filter(file__oshash__in=dont_ignore).update(ignore=False)
if ignore or dont_ignore:
files = models.File.objects.filter(oshash__in=ignore+dont_ignore)
#FIXME: is this to slow to run sync? #FIXME: is this to slow to run sync?
for i in Item.objects.filter(files__in=files).distinct(): for i in Item.objects.filter(files__in=files).distinct():
i.update_selected() i.update_selected()
i.update_wanted() i.update_wanted()
response = json_response(status=200, text='updated')
updates = {}
for key in ('part', 'language'):
if key in data:
updates[key] = data[key]
if updates:
files.update(**updates)
response = json_response(status=200, text='updated')
else:
response = json_response(status=403, text='permissino denied')
return render_to_json_response(response) return render_to_json_response(response)
actions.register(editFiles, cache=False) actions.register(editFiles, cache=False)
@login_required_json
def editFile(request):
'''
change file / item link
param data {
id: hash of file
part:
language:
ignore: boolean
}
return {
status: {'code': int, 'text': string},
data: {
}
}
'''
data = json.loads(request.POST['data'])
f = get_object_or_404_json(models.File, oshash=data['id'])
response = json_response()
if f.editable(request.user):
update = False
#FIXME: should all instances be ignored?
if 'ignore' in data:
f.instances.update(ignore=data['ignore'])
f.save()
#FIXME: is this to slow to run sync?
if f.item:
f.item.update_selected()
f.item.update_wanted()
for key in ('episodes', 'extension', 'language', 'part', 'partTitle', 'version'):
if key in data:
f.path_info[key] = data[key]
update = True
if update:
f.save()
response = json_response(status=200, text='updated')
else:
response = json_response(status=403, text='permissino denied')
return render_to_json_response(response)
actions.register(editFile, cache=False)
@login_required_json @login_required_json
def removeFiles(request): def removeFiles(request):