From 67ad70d69f46ac42ee99a6af91d09c477325ac43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Sat, 29 Jan 2022 21:35:17 +0100 Subject: [PATCH] Improve eligibility checks --- scipost_django/colleges/forms.py | 6 +++--- scipost_django/colleges/utils.py | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scipost_django/colleges/forms.py b/scipost_django/colleges/forms.py index 37da59bae..4ea2a5dc9 100644 --- a/scipost_django/colleges/forms.py +++ b/scipost_django/colleges/forms.py @@ -288,12 +288,9 @@ class PotentialFellowshipEventForm(forms.ModelForm): class FellowshipNominationForm(forms.ModelForm): - #profile_id = forms.IntegerField() - class Meta: model = FellowshipNomination fields = [ - #'profile_id', 'nominated_by', # hidden 'college', 'nominator_comments' # visible ] @@ -301,6 +298,9 @@ class FellowshipNominationForm(forms.ModelForm): def __init__(self, *args, **kwargs): self.profile = kwargs.pop('profile') super().__init__(*args, **kwargs) + self.fields['college'].queryset = College.objects.filter( + acad_field=self.profile.acad_field) + self.fields['college'].empty_label = None self.fields['nominator_comments'].widget.attrs['rows'] = 4 self.helper = FormHelper() self.helper.layout = Layout( diff --git a/scipost_django/colleges/utils.py b/scipost_django/colleges/utils.py index a41e3ca20..cd2602350 100644 --- a/scipost_django/colleges/utils.py +++ b/scipost_django/colleges/utils.py @@ -2,7 +2,7 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" -from .models import Fellowship, FellowshipNomination +from .models import College, Fellowship, FellowshipNomination def check_profile_eligibility_for_fellowship(profile): @@ -11,12 +11,20 @@ def check_profile_eligibility_for_fellowship(profile): Requirements: + - Profile has a known acad_field + - There is an active College in the Profile's acad_field - no current Fellowship exists - no current FellowshipNomination exists - no 'not elected' decision in last 2 years - no invitation was turned down in the last 2 years """ blocks = [] + if not profile.acad_field: + blocks.append('No academic field is specified for this profile. ' + 'Contact EdAdmin or techsupport.') + if not College.objects.filter(acad_field=profile.acad_field).exists(): + blocks.append('There is currently no College in {profile.acad_field}. ' + 'Contact EdAdmin or techsupport to get one started.') if Fellowship.objects.active().regular_or_senior().filter( contributor__profile=profile).exists(): blocks.append('This Profile is associated to an active Fellowship.') -- GitLab