SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 515c7506 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Include invitations in the Contributorsfilter

parent 3935998b
No related branches found
No related tags found
No related merge requests found
......@@ -186,20 +186,27 @@ class DraftInvitationForm(forms.ModelForm):
class ContributorsFilterForm(forms.Form):
names = forms.CharField(widget=forms.Textarea())
include_invitations = forms.BooleanField(required=False, initial=True,
label='Include invitations in the filter.')
def filter(self):
names_found = []
names_not_found = []
invitations_found = []
r = self.cleaned_data['names'].replace('\r', '\n').split('\n')
include_invitations = self.cleaned_data.get('include_invitations', False)
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)
elif include_invitations and RegistrationInvitation.objects.pending_response().filter(
last_name__istartswith=last_name).exists():
invitations_found.append(name)
else:
names_not_found.append(name)
return names_found, names_not_found
return names_found, names_not_found, invitations_found
class RegistrationInvitationForm(forms.ModelForm):
......
......@@ -49,6 +49,9 @@ class RegistrationInvitationManager(models.Manager):
def declined(self):
return self.filter(responded=True, declined=True)
def pending_response(self):
return self.filter(responded=False)
def declined_or_without_response(self):
return self.filter(Q(responded=True, declined=True) | Q(responded=False))
......
......@@ -33,13 +33,17 @@
<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>
<pre class="mb-3"><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>
<pre class="mb-3"><code>{% for name in names_found %}{{ name }}{% if not forloop.last %}<br>{% endif %}{% endfor %}</code></pre>
{% endif %}
{% if invitations_found %}
<h3>Invitations (pending response) found in database</h3>
<pre class="mb-3"><code>{% for name in invitations_found %}{{ name }}{% if not forloop.last %}<br>{% endif %}{% endfor %}</code></pre>
{% endif %}
{% endif %}
......
......@@ -386,17 +386,16 @@ def contributors_filter(request):
view returns all entries of those lists with users that are certainly not registered
or invitated.
"""
names_found = names_not_found = None
names_found = names_not_found = invitations_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'))
names_found, names_not_found, invitations_found = form.filter()
context = {
'form': form,
'names_found': names_found,
'names_not_found': names_not_found,
'invitations_found': invitations_found,
}
return render(request, 'scipost/contributors_filter.html', context)
......
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