SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit b1bf0232 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Move Publication add_author to Profiles

parent c6c52297
No related branches found
No related tags found
No related merge requests found
......@@ -83,23 +83,17 @@ class PublicationAuthorsTable(models.Model):
@property
def is_registered(self):
"""Check if author is registered at SciPost."""
return self.contributor is not None
return self.profile.contributor is not None
@property
def first_name(self):
"""Return first name of author."""
if self.contributor:
return self.contributor.user.first_name
if self.unregistered_author:
return self.unregistered_author.first_name
return self.profile.first_name
@property
def last_name(self):
"""Return last name of author."""
if self.contributor:
return self.contributor.user.last_name
if self.unregistered_author:
return self.unregistered_author.last_name
return self.profile.last_name
class Journal(models.Model):
......
......@@ -32,9 +32,9 @@
{% for author in publication.authors.all %}
<li>
{% if author.is_registered %}
<a href="{{ author.contributor.get_absolute_url }}">{{ author.contributor }}</a>
<a href="{{ author.profile.contributor.get_absolute_url }}">{{ author.profile.contributor }}</a>
{% else %}
{{ author.unregistered_author }}
<a href="{{ author.profile }}">{{ author.profile }}</a>
{% endif %}
</li>
{% empty %}
......@@ -43,36 +43,16 @@
</ul>
<br>
<h2 class="highlight">Add an (unregistered) author</h2>
<h2 class="highlight">Add another author</h2>
<h3>Search for missing author</h3>
<form method="get">
{{ form|bootstrap }}
<input class="btn btn-primary" type="submit" value="Search">
<form action="{% url 'journals:add_author' doi_label=publication.doi_label %}" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input class="btn btn-primary" type="submit" value="Add this author">
</form>
<br/>
<h3>Not found? Then you can <a href="{% url 'profiles:profile_create' %}" target="_blank">add the required Profile</a> and come back to this page.</h3>
{% if form.has_changed %}
<br>
<h3>Identified as Contributor:</h3>
<ul>
{% for contributor in contributors_found %}
<li>
<div class="font-weight-bold">{{ contributor.user.first_name }} {{ contributor.user.last_name }}</div>
<a href="{% url 'journals:add_author' doi_label=publication.doi_label contributor_id=contributor.id %}">Add this Contributor as author of this Publication</a>
</li>
{% empty %}
<li><span class="text-danger">No Contributor with this name could be identified.</span></li>
{% endfor %}
</ul>
<h3>You can otherwise add the author manually and link it to the publication</h3>
<form action="{% url 'journals:add_author' doi_label=publication.doi_label %}" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input class="btn btn-primary" type="submit" value="Add">
</form>
<br>
{% endif %}
</div>
</div>
......@@ -80,3 +60,8 @@
{% endblock content %}
{% block footer_script %}
{{ block.super }}
{{ form.media }}
{% endblock footer_script %}
......@@ -49,10 +49,10 @@ urlpatterns = [
name='remove_grant'),
# Editorial and Administrative Workflow
url(r'^admin/(?P<doi_label>{regex})/authors/add/(?P<contributor_id>[0-9]+)$'.format(
regex=PUBLICATION_DOI_REGEX),
journals_views.add_author,
name='add_author'),
# url(r'^admin/(?P<doi_label>{regex})/authors/add/(?P<profile_id>[0-9]+)$'.format(
# regex=PUBLICATION_DOI_REGEX),
# journals_views.add_author,
# name='add_author'),
url(r'^admin/(?P<doi_label>{regex})/authors/add$'.format(regex=PUBLICATION_DOI_REGEX),
journals_views.add_author,
name='add_author'),
......
......@@ -49,6 +49,7 @@ from mails.views import MailEditorSubview
from ontology.models import Topic
from ontology.forms import SelectTopicForm
from organizations.models import Organization
from profiles.forms import ProfileSelectForm
from submissions.constants import STATUS_PUBLISHED
from submissions.models import Submission, Report
from scipost.constants import SCIPOST_SUBJECT_AREAS
......@@ -361,44 +362,34 @@ def manage_metadata(request, doi_label=None, issue_doi_label=None, journal_doi_l
@permission_required('scipost.can_draft_publication', return_403=True)
@transaction.atomic
def add_author(request, doi_label, contributor_id=None, unregistered_author_id=None):
def add_author(request, doi_label):
"""
If not all authors are registered Contributors or if they have not
all claimed authorship, this method allows editorial administrators
to associate them to the publication.
Link authors (via their Profile) to a Publication.
To be used for registered Contributors who have not claimed authorship,
as well as for unregistered authors.
This is important for the Crossref metadata, in which all authors must appear.
"""
publication = get_object_or_404(Publication, doi_label=doi_label)
if not publication.is_draft and not request.user.has_perm('can_publish_accepted_submission'):
raise Http404('You do not have permission to edit this non-draft Publication')
if contributor_id:
contributor = get_object_or_404(Contributor, id=contributor_id)
PublicationAuthorsTable.objects.create(contributor=contributor, publication=publication)
publication.save()
messages.success(request, 'Added {} as an author.'.format(contributor))
return redirect(reverse('journals:manage_metadata',
kwargs={'doi_label': publication.doi_label}))
contributors_found = None
form = UnregisteredAuthorForm(request.POST or request.GET or None)
form = ProfileSelectForm(request.POST or None)
if request.POST and form.is_valid():
unregistered_author = form.save()
PublicationAuthorsTable.objects.create(
table, created = PublicationAuthorsTable.objects.get_or_create(
publication=publication,
unregistered_author=unregistered_author)
messages.success(request, 'Added {} as an unregistered author.'.format(
unregistered_author
))
return redirect(reverse('journals:add_author',
profile=form.cleaned_data['profile'])
if created:
messages.success(request, 'Added {} as an author.'.format(table.profile))
else:
messages.warning(request, ('Author {} was already associated to this '
'Publication.'.format(table.profile)))
return redirect(reverse('journals:manage_metadata',
kwargs={'doi_label': publication.doi_label}))
elif form.is_valid():
contributors_found = Contributor.objects.filter(
user__last_name__icontains=form.cleaned_data['last_name'])
context = {
'publication': publication,
'contributors_found': contributors_found,
'form': form,
}
return render(request, 'journals/add_author.html', context)
......
......@@ -175,6 +175,13 @@ class ProfileEmailForm(forms.ModelForm):
return super().save()
class ProfileSelectForm(forms.Form):
profile = AutoCompleteSelectField(
'profile_lookup',
help_text=('Start typing, and select from the popup.'),
show_help_text=False)
class AffiliationForm(forms.ModelForm):
organization = AutoCompleteSelectField('organization_lookup')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment