From 78e80b0ce5a35be1b26b147ee6ab4314747ebe6e Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Fri, 1 Dec 2023 12:10:57 +0100 Subject: [PATCH] require short motivation and specialties for fellowship nomination --- scipost_django/colleges/forms.py | 46 +++++++++++++++++-- .../_hx_nomination_details_contents.html | 19 ++++---- .../scipost/personal_page/_hx_edadmin.html | 1 + 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/scipost_django/colleges/forms.py b/scipost_django/colleges/forms.py index 1c9fa9c47..ac2d09774 100644 --- a/scipost_django/colleges/forms.py +++ b/scipost_django/colleges/forms.py @@ -415,6 +415,13 @@ class FellowshipNominationForm(forms.ModelForm): model = FellowshipNomination fields = ["nominated_by", "college", "nominator_comments"] # hidden # visible + specialties = forms.MultipleChoiceField( + choices=[], + label="Specialties", + required=False, + widget=forms.CheckboxSelectMultiple(), + ) + def __init__(self, *args, **kwargs): self.profile = kwargs.pop("profile") super().__init__(*args, **kwargs) @@ -426,10 +433,23 @@ class FellowshipNominationForm(forms.ModelForm): ) self.fields["college"].empty_label = None self.fields["nominator_comments"].label = False - self.fields["nominator_comments"].widget.attrs["rows"] = 4 - self.fields["nominator_comments"].widget.attrs[ - "placeholder" - ] = "Optional comments and/or recommendations" + self.fields["nominator_comments"].widget = forms.Textarea( + attrs={ + "rows": 4, + "placeholder": "Please provide a short motivation for the nomination, " + "as well as a personal website or external profile page to help us identify the nominee.", + } + ) + self.fields["nominator_comments"].required = True + + self.fields["specialties"].choices = [ + (s.pk, s.name) + for s in Specialty.objects.filter(acad_field=self.profile.acad_field) + ] + self.fields["specialties"].initial = list( + self.profile.specialties.all().values_list("pk", flat=True) + ) + self.helper = FormHelper() self.helper.layout = Layout( Field("profile_id", type="hidden"), @@ -445,6 +465,13 @@ class FellowshipNominationForm(forms.ModelForm): ), css_class="col-lg-4", ), + Div( + Field( + "specialties", + css_class="border border-secondary p-2 d-flex flex-wrap gap-3", + ), + css_class="col-12", + ), css_class="row pt-1", ), ) @@ -471,11 +498,22 @@ class FellowshipNominationForm(forms.ModelForm): "college", "You do not have an active Fellowship in the selected College.", ) + + profile_specialties_of_field = self.profile.specialties.filter( + acad_field=data["college"].acad_field + ) + if profile_specialties_of_field.count() == 0 and len(data["specialties"]) == 0: + self.add_error( + None, + "You must denote at least one specialty for the nominee in their nominated college.", + ) return data def save(self): nomination = super().save(commit=False) nomination.profile = self.profile + # add specialties to profile + nomination.profile.specialties.add(*self.cleaned_data["specialties"]) nomination.save() return nomination diff --git a/scipost_django/colleges/templates/colleges/_hx_nomination_details_contents.html b/scipost_django/colleges/templates/colleges/_hx_nomination_details_contents.html index a49c2ecaf..0f5c52223 100644 --- a/scipost_django/colleges/templates/colleges/_hx_nomination_details_contents.html +++ b/scipost_django/colleges/templates/colleges/_hx_nomination_details_contents.html @@ -7,6 +7,15 @@ <div id="profile-{{ nomination.profile.id }}-specialties" class="border border-danger mb-4 d-none-empty"></div> + {% if nomination.nominator_comments %} + <div class="col-12 mb-3"> + <div class="card"> + <div class="card-header">Nominator motivation</div> + <div class="card-body">{{ nomination.nominated_by.profile.full_name }}: {{ nomination.nominator_comments }}</div> + </div> + </div> + {% endif %} + <div class="col-12 col-md mb-3"> <div class="card"> <div class="card-header">Details</div> @@ -112,16 +121,6 @@ <div class="card-body"> <div class="p-3"> - {% if nomination.nominator_comments %} - <div class="row"> - <div class="fs-6">Nominator comments:</div> - <div> - <em>{{ nomination.nominator_comments }}</em> - </div> - </div> - <hr class="text-muted" /> - {% endif %} - <div id="nomination-{{ nomination.id }}-comments" hx-get="{% url 'colleges:_hx_nomination_comments' nomination_id=nomination.id %}" hx-trigger="intersect once"></div> diff --git a/scipost_django/scipost/templates/scipost/personal_page/_hx_edadmin.html b/scipost_django/scipost/templates/scipost/personal_page/_hx_edadmin.html index 15f90ab60..19d2a5c7d 100644 --- a/scipost_django/scipost/templates/scipost/personal_page/_hx_edadmin.html +++ b/scipost_django/scipost/templates/scipost/personal_page/_hx_edadmin.html @@ -102,6 +102,7 @@ {% if perms.scipost.can_manage_college_composition %} <li><a href="{% url 'colleges:fellowships' %}">Fellowships</a></li> {% endif %} + <li><a href="{% url 'colleges:nominations' %}">Fellowship Nominations</a></li> <li><a href="{% url 'colleges:potential_fellowships' %}">Potential Fellowships: view{% if perms.scipost.can_manage_college_composition %} and manage{% endif %}</a></li> </ul> {% endif %} -- GitLab