From 94b3aa7c0beecdc2ed09684f3294cf7cfb5e6fe2 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 26 Apr 2022 18:02:28 -0300 Subject: [PATCH] fix: use ModelMultipleChoiceField for 'bethere' when hidden The select2-based fields do not behave well on the SubmissionForm when hidden=True. The ModelMultipleChoiceField is enough for this case. --- ietf/secr/sreq/forms.py | 8 ++++++++ ietf/secr/sreq/views.py | 5 ++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ietf/secr/sreq/forms.py b/ietf/secr/sreq/forms.py index ecad4ce7e5..baba79c970 100644 --- a/ietf/secr/sreq/forms.py +++ b/ietf/secr/sreq/forms.py @@ -11,6 +11,7 @@ from ietf.meeting.forms import sessiondetailsformset_factory from ietf.meeting.models import ResourceAssociation, Constraint from ietf.person.fields import SearchablePersonsField +from ietf.person.models import Person from ietf.utils.html import clean_text_field from ietf.utils import log @@ -154,10 +155,17 @@ def __init__(self, group, meeting, data=None, *args, **kwargs): self.fields["resources"].choices = [(x.pk,x.desc) for x in ResourceAssociation.objects.filter(name__used=True).order_by('name__order') ] if self.hidden: + # replace all the widgets to start... for key in list(self.fields.keys()): self.fields[key].widget = forms.HiddenInput() + # re-replace a couple special cases self.fields['resources'].widget = forms.MultipleHiddenInput() self.fields['timeranges'].widget = forms.MultipleHiddenInput() + # and entirely replace bethere - no need to support searching if input is hidden + self.fields['bethere'] = forms.ModelMultipleChoiceField( + widget=forms.MultipleHiddenInput, required=False, + queryset=Person.objects.all(), + ) def wg_constraint_fields(self): """Iterates over wg constraint fields diff --git a/ietf/secr/sreq/views.py b/ietf/secr/sreq/views.py index 57d519d01d..fab408e03d 100644 --- a/ietf/secr/sreq/views.py +++ b/ietf/secr/sreq/views.py @@ -289,9 +289,8 @@ def confirm(request, acronym): return redirect('ietf.secr.sreq.views.main') session_data = form.data.copy() - if 'bethere' in session_data: - person_id_list = [ id for id in form.data['bethere'].split(',') if id ] - session_data['bethere'] = Person.objects.filter(pk__in=person_id_list) + # use cleaned_data for the 'bethere' field so we get the Person instances + session_data['bethere'] = form.cleaned_data['bethere'] if 'bethere' in form.cleaned_data else [] if session_data.get('session_time_relation'): session_data['session_time_relation_display'] = dict(Constraint.TIME_RELATION_CHOICES)[session_data['session_time_relation']] if session_data.get('joint_for_session'):