Skip to content
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
74 changes: 14 additions & 60 deletions templates/back_content/author_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,25 @@
<div class="large-12 columns box">
<div class="title-area">
<h2 id="edit-metadata-authors">Article Authors</h2>
{% if frozen_author %}
<a href="{% url 'edit_metadata' article.pk %}?modal=author&return={{ return }}" class="button">Add Author</a>
{% else %}
<a href="#" class="button" data-open="author">Add Author</a>
{% endif %}
</div>
<div class="submission-content">
<form method="POST">
{% csrf_token %}
<table class="small scroll">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
<th>Display Email Link?</th>
<th>Institution</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody id="sortable">
{% for f_author in article.frozen_authors %}
<tr id="authors-{{ f_author.pk }}">
<td><i class="fa fa-sort"></i></td>
<td>{{ f_author.full_name|se_can_see_pii:article }}</td>
<td>{{ f_author.email|se_can_see_pii:article }}</td>
<td>{{ f_author.display_email|bool_fa }}</td>
<td>{{ f_author.institution|se_can_see_pii:article }}</td>
<td>{% if can_see_pii %}
<a href="?author={{ f_author.pk }}&return={{ return }}"><i
class="fa fa-edit">&nbsp;</i>Edit</a>
{% else %}
Author data cannot be edited
{% endif %}
</td>
<td>
<form method="POST">
{% csrf_token %}
<button type="submit" name="delete" value="{{ f_author.pk }}"><i
class="fa fa-trash">&nbsp;</i>Delete
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="pull-right">
<button class="success button" type="submit" name="back">
<i class="fa fa-arrow-left">&nbsp;</i>Back
</button>
<button class="success button" type="submit" name="close">
<i class="fa fa-close">&nbsp;</i>Save & Close
</button>
<button class="success button" type="submit" name="continue">
<i class="fa fa-arrow-right">&nbsp;</i>Save & Continue
</button>
</div>
</form>
<div class="content" data-equalizer data-equalize-on="medium">
<div class="large-4 columns" data-equalizer-watch>
<p>{% trans "You can add an author by clicking the button below. This will open a popup modal for you to complete their details. If you do not have a legitimate email address for this author use @journal.com as a prefix for their email address and Janeway will ignore it." %}</p>
<a href="#" data-open="author" class="small success button">{% trans "Add New Author" %}</a>
{% include "back_content/elements/add_new_author.html" %}
<p>{% trans "If you know of an existing author, you can search for them." %}</p>
<a href="{% url 'bc_article_authors' article.pk %}" class="small success button">Search Accounts for Authors</a>

</div>
<div class="large-8 columns" data-equalizer-watch>
<h4>{% trans "Current Authors" %}</h4>
{% include "elements/current_authors.html" %}
</div>
</div>
</div>
</div>
</section>
{% include "admin/elements/submission/edit_author.html" %}
{% include "back_content/elements/add_new_author.html" %}
{% endblock body %}

{% block js %}
Expand Down
46 changes: 46 additions & 0 deletions templates/back_content/elements/add_new_author.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% load foundation %}
{% load i18n %}

<div class="reveal large" id="author" data-reveal data-animation-in="slide-in-up"
data-animation-out="slide-out-down">
<div class="card">
<div class="card-divider">
<h4><i class="fa fa-user">&nbsp;</i>{% trans "Add New Author" %}</h4>
</div>
<div class="card-section">
<button class="close-button" data-close aria-label="Close reveal" type="button">
<span aria-hidden="true">&times;</span>
</button>
{% include "admin/elements/forms/errors.html" with form=form %}
<form method="POST">
{% csrf_token %}
<div class="flex direction-column row-gap-0">
<div class="grid auto row-gap-0">
{% include "admin/elements/forms/field.html" with field=form.first_name %}
{% include "admin/elements/forms/field.html" with field=form.middle_name %}
{% include "admin/elements/forms/field.html" with field=form.last_name %}
</div>
<div class="grid auto row-gap-0">
{% include "admin/elements/forms/field.html" with field=form.name_prefix %}
{% include "admin/elements/forms/field.html" with field=form.name_suffix %}
{% include "admin/elements/forms/field.html" with field=form.is_corporate %}
</div>
<div class="grid auto row-gap-0">
{% include "admin/elements/forms/field.html" with field=form.frozen_email %}
{% include "admin/elements/forms/field.html" with field=form.display_email %}
</div>
<div class="flex wrap gap-1 items-end">
<div class="button-group">
<button
name="add_author"
class="button">
<span class="fa fa-user-plus"></span>
{% trans "Add author manually" %}
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
83 changes: 36 additions & 47 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
FrozenAuthor,
STAGE_PUBLISHED)
from submission.forms import FileDetails, EditFrozenAuthor
from submission.logic import get_author
from submission.logic import add_new_author_from_form, get_credit_form

from production.forms import GalleyForm
from production.logic import (save_galley,
Expand Down Expand Up @@ -126,48 +126,36 @@ def add_authors(request, article_id):
pk=article_id,
journal=request.journal,
)

frozen_author, modal, author_form = None, None, EditFrozenAuthor()
if request.GET.get('author'):
frozen_author, modal = get_author(request, article)
author_form = EditFrozenAuthor(instance=frozen_author)
elif request.GET.get('modal') == 'author':
modal = 'author'

author_form = EditFrozenAuthor()
modal = None

if request.method == "POST":
if 'author' in request.POST:
author_form = EditFrozenAuthor(
request.POST,
instance=frozen_author,
if 'add_author' in request.POST:
add_new_author_from_form(
request,
article,
)

if author_form.is_valid():
saved_author = author_form.save()
saved_author.article = article
saved_author.save()
messages.add_message(
return redirect(reverse('bc_add_authors', kwargs={"article_id": article.pk}))
elif 'remove_author' in request.POST:
author_pk = request.POST.get('remove_author', None)
if author_pk:
author_to_remove = get_object_or_404(
FrozenAuthor,
pk=author_pk,
)
author_to_remove.delete()
if author_to_remove.author == article.correspondence_author:
article.correspondence_author = None
article.save()
messages.success(
request,
messages.SUCCESS,
_('Author {author_name} updated.').format(
author_name=saved_author.full_name(),
),
f'{author_to_remove} removed from article.',
)
else:
messages.warning(
request,
f'No author ID provided.',
)
return redirect(reverse('bc_add_authors', kwargs={"article_id": article.pk}))
elif 'delete' in request.POST:
frozen_author_id = request.POST.get('delete')
frozen_author = get_object_or_404(
FrozenAuthor,
pk=frozen_author_id,
article=article,
article__journal=request.journal,
)
frozen_author.delete()
messages.add_message(
request,
messages.SUCCESS,
_('Frozen Author deleted.'),
)
return redirect(reverse('bc_add_authors', kwargs={"article_id": article.pk}))
else:
if "continue" in request.POST:
Expand All @@ -177,11 +165,16 @@ def add_authors(request, article_id):
else:
return redirect(reverse('bc_index'))

authors = []
for author, credits in article.authors_and_credits().items():
credit_form = get_credit_form(request, author)
authors.append((author, credits, credit_form))

context = {
'article': article,
'author_form': author_form,
'form': author_form,
"modal": modal,
'frozen_author': frozen_author,
"authors": authors,
}
return render(request, "back_content/author_form.html", context)

Expand Down Expand Up @@ -406,13 +399,9 @@ def post(self, request, *args, **kwargs):
pk=author_id,
)
if author in self.get_queryset():
self.article.authors.add(author)
ArticleAuthorOrder.objects.get_or_create(
article=self.article,
author=author,
defaults={
'order': self.article.next_author_sort(),
}
author, _created = FrozenAuthor.get_or_snapshot_if_email_found(
author.email,
self.article,
)
messages.success(
request,
Expand Down