Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions elvis/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ def handle_dynamic_file_table(request, parent, cleanup=Cleanup()):
:param cleanup: Cleanup object.
:return: List of all objects created.
"""
post_dict = request.POST.copy()
results = []
attachments = []
files = {}
for item in request.POST:
if item.startswith("mov_title_") and request.POST[item]:
file_name = request.POST[item]
for item in post_dict:
if item.startswith("mov_title_") and post_dict[item]:
file_name = post_dict[item]
file_num = int(re.findall(r'\d+', item)[0])
files[file_num] = file_name

Expand All @@ -251,11 +252,11 @@ def handle_dynamic_file_table(request, parent, cleanup=Cleanup()):

# Creating movements, then attaching files to them.
for k in keys:
mov_instrumentation_string = request.POST.get('mov' + str(k) + "_instrumentation")
mov_number_of_voices_string = request.POST.get('mov' + str(k) + "_number_of_voices")
mov_free_tags_string = request.POST.get('mov' + str(k) + "_free_tags")
mov_vocalization = request.POST.get('mov' + str(k) + "_vocalization")
mov_comment = request.POST.get('mov' + str(k) + "_comment")
mov_instrumentation_string = post_dict.get('mov' + str(k) + "_instrumentation")
mov_number_of_voices_string = post_dict.get('mov' + str(k) + "_number_of_voices")
mov_free_tags_string = post_dict.get('mov' + str(k) + "_free_tags")
mov_vocalization = post_dict.get('mov' + str(k) + "_vocalization")
mov_comment = post_dict.get('mov' + str(k) + "_comment")
new_mov = Movement(title=files[k], position=i,
composition_start_date=parent.composition_start_date,
composition_end_date=parent.composition_end_date,
Expand Down Expand Up @@ -301,36 +302,36 @@ def handle_dynamic_file_table(request, parent, cleanup=Cleanup()):
if mov_comment:
new_mov.comment = mov_comment

file_keys = [x for x in list(request.POST.keys()) if x.startswith('files_parent_')]
file_keys = [x for x in list(post_dict.keys()) if x.startswith('files_parent_')]
file_numbers = [x.split('files_parent_')[-1] for x in file_keys if
request.POST.get(x) == 'mov_title_' +str(k)]
post_dict.get(x) == 'mov_title_' +str(k)]
for num in file_numbers:
attachments.extend(handle_attachments(request, new_mov, cleanup, "files_files_" + num,
request.POST.get('files_source_' + num)))
request.POST.pop('files_source_' + num)
request.POST.pop('files_parent_' + num)
post_dict.get('files_source_' + num)))
post_dict.pop('files_source_' + num)
post_dict.pop('files_parent_' + num)
request.FILES.pop('files_files_' + num)
request.POST.pop('mov_title_' +str(k))
post_dict.pop('mov_title_' +str(k))

cleanup.list.append({"object": new_mov, "isNew": True})
new_mov.save()
results.append(new_mov)
i += 1

# Attaching other files.
file_numbers = [x for x in list(request.POST.keys()) if x.startswith('files_parent_')]
file_numbers = [x for x in list(post_dict.keys()) if x.startswith('files_parent_') and post_dict[x] == 'piece']
for postfile in file_numbers:
if request.POST.get(postfile) == 'piece':
if post_dict.get(postfile) == 'piece':
# This attaches files to the piece itself - is pretty
# straightforward.
num = postfile.split('files_parent_')[-1]
attachments.extend(handle_attachments(request, parent, cleanup, "files_files_" + num,
request.POST.get('files_source_' + num)))
post_dict.get('files_source_' + num)))
else:
"""
This attaches new files to an existing movement and is *very* hacky.
It finds the html-id of the row of the movement table it is
attached to (request.POST.get(postfile)), then parses
attached to (post_dict.get(postfile)), then parses
the number of that movement-id, then attaches to the [n-1]'th
movement of the piece.
This works because:
Expand All @@ -344,12 +345,12 @@ def handle_dynamic_file_table(request, parent, cleanup=Cleanup()):
By the above logic, the [n-1]'th movement in the table on the
frontend will be the n'th movement on the backend - so this works.
"""
movnum = int(re.findall(r'\d+', request.POST.get(postfile))[0])
movnum = int(re.findall(r'\d+', post_dict.get(postfile))[0])
mov = parent.movements.all()[movnum - 1]
num = postfile.split('files_parent_')[-1]
mov.save()
attachments.extend(handle_attachments(request, mov, cleanup, "files_files_" + num,
request.POST.get('files_source_' + num)))
post_dict.get('files_source_' + num)))

results.extend(attachments)
return results
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ billiard==3.3.0.22
celery==3.1.19
coverage==4.0.3
decorator==4.0.6
Django==1.9.1
Django==1.11.1
django-appconf==1.0.1
django-compressor==2.0
django-debug-toolbar==1.7
django-extensions==1.6.1
django-extensions==1.7.9
django-redis==4.3.0
djangorestframework==3.3.2
funcsigs==0.4
Expand Down