diff --git a/src/repository/urls.py b/src/repository/urls.py index 6a80ad2d20..fd327cf9fc 100755 --- a/src/repository/urls.py +++ b/src/repository/urls.py @@ -106,6 +106,13 @@ url(r'^manager/(?P\d+)/add/author/$', views.repository_edit_author, name='repository_add_author'), + url(r'^manager/(?P\d+)/author/order/$', + views.reorder_preprint_authors, + name='repository_manager_order_authors'), + url(r'^manager/(?P\d+)/author/delete/$', + views.delete_preprint_author, + name='repository_manager_delete_author'), + url(r'^manager/(?P\d+)/download/(?P\d+)/$', views.repository_download_file, diff --git a/src/repository/views.py b/src/repository/views.py index a6f0fb2f6f..1bb1ee274c 100755 --- a/src/repository/views.py +++ b/src/repository/views.py @@ -1699,3 +1699,58 @@ def delete_supplementary_file(request, preprint_id): kwargs={'preprint_id': preprint.pk}, ) ) + + +@is_repository_manager +@require_POST +def reorder_preprint_authors(request, preprint_id): + preprint = models.Preprint.objects.get( + pk=preprint_id, + repository=request.repository, + ) + posted_author_pks = [int(pk) for pk in request.POST.getlist('authors[]')] + preprint_authors = models.PreprintAuthor.objects.filter( + preprint=preprint, + ) + utils_shared.set_order( + objects=preprint_authors, + order_attr_name='order', + pk_list=posted_author_pks, + ) + return HttpResponse('Author Order Updated') + + +@is_repository_manager +@require_POST +def delete_preprint_author(request, preprint_id): + preprint = models.Preprint.objects.get( + pk=preprint_id, + repository=request.repository, + ) + + if 'author_id' in request.POST: + try: + author = models.PreprintAuthor.objects.get( + preprint=preprint, + pk=request.POST.get('author_id'), + ) + author.delete() + messages.add_message( + request, + messages.SUCCESS, + 'Author record deleted.', + ) + except models.PreprintAuthor.DoesNotExist: + messages.add_message( + request, + messages.WARNING, + 'No author found.', + ) + + return redirect( + reverse( + 'repository_manager_article', + kwargs={'preprint_id': preprint.pk}, + ) + ) + diff --git a/src/templates/admin/repository/article.html b/src/templates/admin/repository/article.html index aa6119a73e..0e7c80c25c 100644 --- a/src/templates/admin/repository/article.html +++ b/src/templates/admin/repository/article.html @@ -183,7 +183,7 @@

Authors

Add Author
-
+ {% csrf_token %} @@ -385,7 +385,7 @@

Supplementary Files

$.ajax({ data: data, type: 'POST', - url: '{% url 'preprints_author_order' preprint.pk %}' + url: '{% url 'repository_manager_order_authors' preprint.pk %}' }); } });