Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2128 overwriting a file retains the original file label. #2136

Merged
merged 4 commits into from
Apr 14, 2021
Merged
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
2 changes: 1 addition & 1 deletion src/copyediting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def author_update_file(request, article_id, author_review_id, file_id):
label = request.POST.get('label')
new_file = files.save_file_to_article(uploaded_file, copyedit.article, request.user,
replace=file, is_galley=False, label=label)
files.replace_file(copyedit.article, file, new_file, copyedit=copyedit)
files.replace_file(copyedit.article, file, new_file, copyedit=copyedit, retain_old_label=False)
author_review.files_updated.add(new_file)

return redirect(reverse('author_copyedit',
Expand Down
9 changes: 5 additions & 4 deletions src/core/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def delete_file(article_object, file_object):
article_object.data_figure_files.remove(file_object)


def replace_file(article_to_replace, file_to_replace, new_file, copyedit=None, galley=None):
def replace_file(article_to_replace, file_to_replace, new_file, copyedit=None, galley=None, retain_old_label=True):
""" Replaces an existing file with a new record

:param article_to_replace: the article in which we replace the file
Expand All @@ -491,8 +491,8 @@ def replace_file(article_to_replace, file_to_replace, new_file, copyedit=None, g

# reload the new file to avoid conflicts with raw SQL due to materialized path tree structure
new_file = get_object_or_404(models.File, pk=new_file.pk)
new_file.label = file_to_replace.label
new_file.parent = file_to_replace

new_file.save()
article_to_replace.manuscript_files.add(new_file)

Expand All @@ -501,14 +501,12 @@ def replace_file(article_to_replace, file_to_replace, new_file, copyedit=None, g

# reload the new file to avoid conflicts with raw SQL due to materialized path tree structure
new_file = get_object_or_404(models.File, pk=new_file.pk)
new_file.label = file_to_replace.label
new_file.parent = file_to_replace
new_file.save()
article_to_replace.data_figure_files.add(new_file)

else:
new_file = get_object_or_404(models.File, pk=new_file.pk)
new_file.label = file_to_replace.label
new_file.parent = file_to_replace
new_file.save()
else:
Expand All @@ -521,6 +519,9 @@ def replace_file(article_to_replace, file_to_replace, new_file, copyedit=None, g
new_file.save()
copyedit.copyeditor_files.add(new_file)

if retain_old_label:
new_file.label = file_to_replace.label

return new_file


Expand Down
14 changes: 11 additions & 3 deletions src/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,12 @@ def replace_file(request, article_id, revision_id, file_id):
new_file = files.save_file_to_article(uploaded_file, revision_request.article, request.user,
replace=file, is_galley=False, label=label)

files.replace_file(revision_request.article, file, new_file)
files.replace_file(
revision_request.article,
file,
new_file,
retain_old_label=False,
)
logic.log_revision_event(
'File {0} ({1}) replaced with {2} ({3})'.format(file.label, file.original_filename, new_file.label,
new_file.original_filename),
Expand Down Expand Up @@ -1855,7 +1860,11 @@ def upload_new_file(request, article_id, revision_id):
uploaded_file = request.FILES.get('file')
label = request.POST.get('label')
new_file = files.save_file_to_article(
uploaded_file, article, request.user, label=label)
uploaded_file,
article,
request.user,
label=label,
)

if file_type == 'manuscript':
article.manuscript_files.add(new_file)
Expand Down Expand Up @@ -2251,7 +2260,6 @@ def order_review_elements(request, form_id):
return HttpResponse('Ok')



@reviewer_user_for_assignment_required
def hypothesis_review(request, assignment_id):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/templates/admin/review/revision/replace_file.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>Submission Guidelines</h2>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<p>Upload Your File</p>
<input name="label" type="text" placeholder="Add a file label">
<input name="label" type="text" value="Revised Manuscript">
<input name="replacement-file" type="file" class="filestyle" data-placeholder="No file"
data-buttonName="btn-primary">
<br/>
Expand Down