remove editFile, clenaup editFiles
This commit is contained in:
parent
7951c42609
commit
e1889397b2
1 changed files with 38 additions and 65 deletions
|
@ -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']:
|
||||||
#FIXME: is this to slow to run sync?
|
f = get_object_or_404_json(models.File, oshash=info['id'])
|
||||||
for i in Item.objects.filter(files__in=files).distinct():
|
if f.editable(request.user):
|
||||||
i.update_selected()
|
if 'ignore' in info:
|
||||||
i.update_wanted()
|
if info['ignore']:
|
||||||
response = json_response(status=200, text='updated')
|
ignore.append(info['id'])
|
||||||
updates = {}
|
else:
|
||||||
for key in ('part', 'language'):
|
dont_ignore.append(info['id'])
|
||||||
if key in data:
|
update = False
|
||||||
updates[key] = data[key]
|
for key in ('episodes', 'extension', 'language', 'part', 'partTitle', 'version'):
|
||||||
if updates:
|
if key in info:
|
||||||
files.update(**updates)
|
f.path_info[key] = info[key]
|
||||||
response = json_response(status=200, text='updated')
|
update = True
|
||||||
else:
|
if update:
|
||||||
response = json_response(status=403, text='permissino denied')
|
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?
|
||||||
|
for i in Item.objects.filter(files__in=files).distinct():
|
||||||
|
i.update_selected()
|
||||||
|
i.update_wanted()
|
||||||
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):
|
||||||
|
|
Loading…
Reference in a new issue