Commit 5a1bb016 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

form instantiation and cleaning now properly works for m2m with blocked students

parent 9b5ea1db
......@@ -178,6 +178,8 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
'graduating_year': me.graduating_year,
'on_campus': me.on_campus, })
form.fields['blocked_kids'].queryset = Student.objects.exclude(user=self.request.user)
if me.recent_changes() > 2:
form.fields['room'].widget = HiddenInput()
form.fields['privacy'].widget = HiddenInput()
......@@ -192,6 +194,7 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
# chosen
form.fields['major'].widget.attrs['class'] = 'chosen-select'
form.fields['blocked_kids'].widget.attrs['class'] = 'blocked-select'
context['my_form'] = form
......@@ -261,12 +264,27 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
# don't change majors
# replicate the same thing for the other m2m field
form_blocked_pks = set('blocked_kids'))
current_blocked = me.blocked_kids.all()
# most people will not being blocking other students
if form_blocked_pks:
form_blocked = [Student.objects.get(pk=pk) for pk in form_blocked_pks]
for current_block in current_blocked:
if current_block not in form_blocked:
for form_block in form_blocked:
if form_block not in current_blocked:
me.user.first_name =['first_name']
me.user.last_name =['last_name']
me.gender ='gender')
me.show_gender = strtobool('show_gender', 'False'))
me.privacy =['privacy']
me.blocked_kids =['blocked_kids']
me.graduating_year =['graduating_year']
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment