From 37b5fe05adbc804dd38088552b3fab93adb5cec4 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Mon, 26 Apr 2021 17:26:44 +0200 Subject: [PATCH] Prevent creation of PotFel for Profile if one already exists --- colleges/forms.py | 9 +++++++++ .../templates/colleges/potentialfellowship_list.html | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/colleges/forms.py b/colleges/forms.py index c7035df09..7099a0c47 100644 --- a/colleges/forms.py +++ b/colleges/forms.py @@ -225,6 +225,15 @@ class PotentialFellowshipForm(RequestFormMixin, forms.ModelForm): model = PotentialFellowship fields = ['college', 'profile'] + def clean_profile(self): + """Check that no preexisting PotentialFellowship exists.""" + cleaned_profile = self.cleaned_data['profile'] + if cleaned_profile.potentialfellowship_set.all(): + self.add_error( + 'profile', + 'This profile already has a PotentialFellowship. Update that instead.') + return cleaned_profile + def save(self): """ The default status is IDENTIFIED, which is appropriate diff --git a/colleges/templates/colleges/potentialfellowship_list.html b/colleges/templates/colleges/potentialfellowship_list.html index 08bcceb89..346b92d93 100644 --- a/colleges/templates/colleges/potentialfellowship_list.html +++ b/colleges/templates/colleges/potentialfellowship_list.html @@ -116,7 +116,7 @@ <div class="row"> <div class="col-12"> - {% if view.kwargs.acad_field or request.GET.status %} + {% if view.kwargs.acad_field or request.GET.status or request.GET.text %} <h3>Potential Fellowships {% if view.kwargs.acad_field %}in {{ view.kwargs.acad_field }} {% if view.kwargs.specialty %}, {{ view.kwargs.specialty }}{% endif %} -- GitLab