diff --git a/scipost/forms.py b/scipost/forms.py index 854726e9340cde25096fd105d51395ddd1ca7ec5..a1a08bda2e0d99bb84cc688d700543c0327ff12b 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -188,6 +188,24 @@ class DraftInvitationForm(forms.ModelForm): return invitation_type +class ContributorsFilterForm(forms.Form): + names = forms.CharField(widget=forms.Textarea()) + + def filter(self): + names_found = [] + names_not_found = [] + r = self.cleaned_data['names'].replace('\r', '\n').split('\n') + for name in r: + last_name = name.split(',')[0] + if not last_name: + continue + if Contributor.objects.filter(user__last_name__istartswith=last_name).exists(): + names_found.append(name) + else: + names_not_found.append(name) + return names_found, names_not_found + + class RegistrationInvitationForm(forms.ModelForm): cited_in_submission = AutoCompleteSelectField('submissions_lookup', required=False) cited_in_publication = AutoCompleteSelectField('publication_lookup', required=False) diff --git a/scipost/templates/partials/scipost/personal_page/editorial_actions.html b/scipost/templates/partials/scipost/personal_page/editorial_actions.html index ffd9844f50aeebf31bc1b66010cab5049542eb23..c614b2e48e939a29a9d7fcfbf319392c95bc6379 100644 --- a/scipost/templates/partials/scipost/personal_page/editorial_actions.html +++ b/scipost/templates/partials/scipost/personal_page/editorial_actions.html @@ -21,6 +21,7 @@ <li><a href="{% url 'scipost:registration_requests' %}">Awaiting validation</a> ({{ nr_reg_awaiting_validation }})</li> {% endif %} {% if perms.scipost.can_draft_registration_invitations %} + <li><a href="{% url 'scipost:contributors_filter' %}">Contributors filter</a></li> <li><a href="{% url 'scipost:draft_registration_invitation' %}">Draft a Registration Invitation</a></li> {% endif %} {% if perms.scipost.can_manage_registration_invitations %} diff --git a/scipost/templates/scipost/contributors_filter.html b/scipost/templates/scipost/contributors_filter.html new file mode 100644 index 0000000000000000000000000000000000000000..2c32cc28cf1a35a49fdd14c5388d0a8ce69d736a --- /dev/null +++ b/scipost/templates/scipost/contributors_filter.html @@ -0,0 +1,42 @@ +{% extends 'scipost/_personal_page_base.html' %} + +{% load bootstrap %} + +{% block pagetitle %}: contributors filter{% endblock pagetitle %} + +{% block breadcrumb_items %} + {{block.super}} + <a href="{% url 'scipost:draft_registration_invitation' %}" class="breadcrumb-item">Draft registration invitation</a> + <span class="breadcrumb-item">Contributors filter</span> +{% endblock %} + +{% block content %} + +<div class="row"> + <div class="col-12"> + <h1 class="highlight">Contributors filter</h1> + <p>This form can be used to split your list of names into a list of names with registered or already invited Contributors and a list of unknown names according to the current database.</p> + <p>Please, for every name use the format <code>{last name}</code> or <code>{last name}, {first name}</code> and use one name per line.</p> + <form method="post"> + {% csrf_token %} + {{ form|bootstrap }} + <input type="submit" class="btn btn-primary" value="Filter"/> + </form> + </div> +</div> + +{% if form.is_bound %} + <hr class="divider"> + <h2>Filter result</h2> + {% if names_not_found %} + <h3>New names</h3> + <pre><code>{% for name in names_not_found %}{{ name }}{% if not forloop.last %}<br>{% endif %}{% endfor %}</code></pre> + {% endif %} + <br> + {% if names_found %} + <h3>Names found in the system</h3> + <pre><code>{% for name in names_found %}{{ name }}{% if not forloop.last %}<br>{% endif %}{% endfor %}</code></pre> + {% endif %} +{% endif %} + +{% endblock %} diff --git a/scipost/templates/scipost/draft_registration_invitation.html b/scipost/templates/scipost/draft_registration_invitation.html index fe8d1f61f63f3f9364dd233cc4815a3398ea742b..4f8900f25de969cfeed59c63bbccb061a33c4c6d 100644 --- a/scipost/templates/scipost/draft_registration_invitation.html +++ b/scipost/templates/scipost/draft_registration_invitation.html @@ -6,7 +6,7 @@ {% block breadcrumb_items %} {{block.super}} - <span class="breadcrumb-item">Pool</span> + <span class="breadcrumb-item">Draft registration invitation</span> {% endblock %} {% block content %} @@ -35,6 +35,7 @@ $(document).ready(function(){ <div class="row"> <div class="col-12"> <h1 class="highlight">Draft a registration invitation</h1> + <p>If you have a list of names you want to check with the current database of users, <a href="{% url 'scipost:contributors_filter' %}">please click here</a>.</p> </div> </div> @@ -47,8 +48,8 @@ $(document).ready(function(){ <form action="{% url 'scipost:draft_registration_invitation' %}" method="post"> {% csrf_token %} - {{draft_inv_form.media}} - {{draft_inv_form|bootstrap}} + {{ form.media }} + {{ form|bootstrap }} <input type="submit" class="btn btn-primary" value="Submit"/> </form> </div> @@ -95,6 +96,4 @@ $(document).ready(function(){ </div> </div> -{% include 'scipost/_draft_registration_tables.html' %} - {% endblock %} diff --git a/scipost/urls.py b/scipost/urls.py index 3c8fb02160d11ca9f26401a791166ca34be9bffb..9ab0cf02bef3b221475c65d090119be5b56fd827 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -89,6 +89,7 @@ urlpatterns = [ views.registration_invitations, name="registration_invitations"), url(r'^draft_registration_invitation$', views.draft_registration_invitation, name="draft_registration_invitation"), + url(r'^contributors_filter$', views.contributors_filter, name="contributors_filter"), url(r'^edit_draft_reg_inv/(?P<draft_id>[0-9]+)$', views.edit_draft_reg_inv, name="edit_draft_reg_inv"), url(r'^map_draft_reg_inv_to_contributor/(?P<draft_id>[0-9]+)/(?P<contributor_id>[0-9]+)$', diff --git a/scipost/views.py b/scipost/views.py index 992def46ff62caf21d8143621e142890cefefba7..64fd94a5749dd079d2f9ddcc32b412d874ad075c 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -36,7 +36,8 @@ from .forms import AuthenticationForm, DraftInvitationForm, UnavailabilityPeriod RegistrationForm, RegistrationInvitationForm, AuthorshipClaimForm,\ ModifyPersonalMessageForm, SearchForm, VetRegistrationForm, reg_ref_dict,\ UpdatePersonalDataForm, UpdateUserDataForm, PasswordChangeForm,\ - EmailGroupMembersForm, EmailParticularForm, SendPrecookedEmailForm + EmailGroupMembersForm, EmailParticularForm, SendPrecookedEmailForm,\ + ContributorsFilterForm from .utils import Utils, EMAIL_FOOTER, SCIPOST_SUMMARY_FOOTER, SCIPOST_SUMMARY_FOOTER_HTML from affiliations.forms import AffiliationsFormset @@ -358,9 +359,9 @@ def draft_registration_invitation(request): This is similar to the registration_invitations method, which is used to complete the invitation process. """ - draft_inv_form = DraftInvitationForm(request.POST or None, current_user=request.user) - if draft_inv_form.is_valid(): - invitation = draft_inv_form.save(commit=False) + form = DraftInvitationForm(request.POST or None, current_user=request.user) + if form.is_valid(): + invitation = form.save(commit=False) invitation.drafted_by = request.user.contributor invitation.save() @@ -369,48 +370,42 @@ def draft_registration_invitation(request): messages.success(request, 'Draft invitation saved.') return redirect(reverse('scipost:draft_registration_invitation')) - sent_reg_inv = RegistrationInvitation.objects.filter(responded=False, declined=False) - sent_reg_inv_fellows = sent_reg_inv.filter(invitation_type='F').order_by('last_name') - sent_reg_inv_contrib = sent_reg_inv.filter(invitation_type='C').order_by('last_name') - sent_reg_inv_ref = sent_reg_inv.filter(invitation_type='R').order_by('last_name') - sent_reg_inv_cited_sub = sent_reg_inv.filter(invitation_type='ci').order_by('last_name') - sent_reg_inv_cited_pub = sent_reg_inv.filter(invitation_type='cp').order_by('last_name') - - resp_reg_inv = RegistrationInvitation.objects.filter(responded=True, declined=False) - resp_reg_inv_fellows = resp_reg_inv.filter(invitation_type='F').order_by('last_name') - resp_reg_inv_contrib = resp_reg_inv.filter(invitation_type='C').order_by('last_name') - resp_reg_inv_ref = resp_reg_inv.filter(invitation_type='R').order_by('last_name') - resp_reg_inv_cited_sub = resp_reg_inv.filter(invitation_type='ci').order_by('last_name') - resp_reg_inv_cited_pub = resp_reg_inv.filter(invitation_type='cp').order_by('last_name') - - decl_reg_inv = RegistrationInvitation.objects.filter( - responded=True, declined=True).order_by('last_name') - - names_reg_contributors = (Contributor.objects.filter(status=1).order_by('user__last_name') - .values_list('user__first_name', 'user__last_name')) existing_drafts = DraftInvitation.objects.filter(processed=False).order_by('last_name') context = { - 'draft_inv_form': draft_inv_form, - 'sent_reg_inv_fellows': sent_reg_inv_fellows, - 'sent_reg_inv_contrib': sent_reg_inv_contrib, - 'sent_reg_inv_ref': sent_reg_inv_ref, - 'sent_reg_inv_cited_sub': sent_reg_inv_cited_sub, - 'sent_reg_inv_cited_pub': sent_reg_inv_cited_pub, - 'resp_reg_inv_fellows': resp_reg_inv_fellows, - 'resp_reg_inv_contrib': resp_reg_inv_contrib, - 'resp_reg_inv_ref': resp_reg_inv_ref, - 'resp_reg_inv_cited_sub': resp_reg_inv_cited_sub, - 'resp_reg_inv_cited_pub': resp_reg_inv_cited_pub, - 'decl_reg_inv': decl_reg_inv, - 'names_reg_contributors': names_reg_contributors, + 'form': form, 'existing_drafts': existing_drafts, } return render(request, 'scipost/draft_registration_invitation.html', context) +@permission_required('scipost.can_draft_registration_invitations', return_403=True) +def contributors_filter(request): + """ + For Invitation Officers that use lists of scientists as a to-do. This + view returns all entries of those lists with users that are certainly not registered + or invitated. + """ + names_found = names_not_found = None + form = ContributorsFilterForm(request.POST or None) + if form.is_valid(): + names_found, names_not_found = form.filter() + # messages.success(request, 'Draft invitation saved.') + # return redirect(reverse('scipost:draft_registration_invitation')) + + context = { + 'form': form, + 'names_found': names_found, + 'names_not_found': names_not_found, + } + return render(request, 'scipost/contributors_filter.html', context) + + @login_required def edit_draft_reg_inv(request, draft_id): + """ + Edit DraftInvitation instance. It's only possible to edit istances created by the User itself. + """ draft = get_object_or_404((get_objects_for_user(request.user, 'scipost.change_draftinvitation') .filter(processed=False)), id=draft_id)