diff --git a/scipost/forms.py b/scipost/forms.py index e52294ab5362d54b5bec7edc06fb0c5cc2c52fa4..60c748382e617c1bc3a971b3caefdddb3ebb3f63 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -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): diff --git a/scipost/managers.py b/scipost/managers.py index 5ed6efd72c6b6dd4ee64791308fa36efafb79cfe..72557dcef9879842d124f5960986d443cdc913b0 100644 --- a/scipost/managers.py +++ b/scipost/managers.py @@ -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)) diff --git a/scipost/templates/scipost/contributors_filter.html b/scipost/templates/scipost/contributors_filter.html index eedc758ad56422aea9a9aeee8717b017e1f594f9..12418bd8a252a1be98829df8c4ee790cd806ce2a 100644 --- a/scipost/templates/scipost/contributors_filter.html +++ b/scipost/templates/scipost/contributors_filter.html @@ -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 %} diff --git a/scipost/views.py b/scipost/views.py index a5623844ce987e0e22377214c96b7982ef32e095..b9d8656f910498ac50b5d7993d097c7f8b7eb00b 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -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)