From dcdbfc3fab85b29954e5ff4468deb967a14dd068 Mon Sep 17 00:00:00 2001 From: Bryan Brancotte <bryan.brancotte@pasteur.fr> Date: Wed, 14 Aug 2019 14:23:10 +0200 Subject: [PATCH] Automatically select the first protein if there is only one --- ippisite/ippidb/forms.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ippisite/ippidb/forms.py b/ippisite/ippidb/forms.py index 206bad70..ab1fb55f 100644 --- a/ippisite/ippidb/forms.py +++ b/ippisite/ippidb/forms.py @@ -716,6 +716,7 @@ class TestActivityDescriptionForm(forms.ModelForm): queryset=Protein.objects.none(), label=_("protein_domain_bound_complex_label"), help_text=_("protein_domain_bound_complex_help_text"), + required=True, ) class Meta: @@ -792,6 +793,8 @@ class TestActivityDescriptionBaseModelFormSet(BaseInlineNestedFormSet): form.nested.set_compound_names(self.__compound_names) form.nested.set_modulation_type(self.__modulation_type) form.fields["protein_complex"].queryset = Protein.objects.filter(id__in=self.__protein_subset_ids) + if Protein.objects.filter(id__in=self.__protein_subset_ids).count() == 1: + form.fields["protein_complex"].initial = Protein.objects.filter(id__in=self.__protein_subset_ids).first() def set_compound_names(self, compound_names): """ -- GitLab