Commit 3b2966cc authored by Daniel W Bond's avatar Daniel W Bond

form is now being modified diredtly through get_initial and get_form, rather...

form is now being modified diredtly through get_initial and get_form, rather than through get_context_data
parent a8ea548d
...@@ -126,48 +126,45 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView): ...@@ -126,48 +126,45 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
else: else:
return super(UpdateStudent, self).get(request, *args, **kwargs) return super(UpdateStudent, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs): def get_initial(self):
context = super(UpdateStudent, self).get_context_data(**kwargs) initial = super(UpdateStudent, self).get_initial()
me = self.request.user.student me = self.request.user.student
majors = [pk_or_none(me, major) for major in me.major.all()] majors = [pk_or_none(me, major) for major in me.major.all()]
form = StudentUpdateForm(initial={'first_name': me.user.first_name, initial = {'first_name': me.user.first_name,
'last_name': me.user.last_name, 'last_name': me.user.last_name,
'gender': me.gender, 'gender': me.gender,
'show_gender': me.show_gender, 'show_gender': me.show_gender,
'room': pk_or_none(me, me.room), 'room': pk_or_none(me, me.room),
'privacy': me.privacy, 'privacy': me.privacy,
'blocked_kids': me.blocked_kids.all(), 'blocked_kids': me.blocked_kids.all(),
'major': majors, 'major': majors,
'graduating_year': me.graduating_year, 'graduating_year': me.graduating_year,
'on_campus': me.on_campus, }) 'on_campus': me.on_campus, }
return initial
def get_form(self):
form = super(UpdateStudent, self).get_form(StudentUpdateForm)
me = self.request.user.student
form.fields['blocked_kids'].queryset = Student.objects.exclude(user=self.request.user) form.fields['blocked_kids'].queryset = Student.objects.exclude(user=self.request.user)
form.fields['room'].widget.user = self.request.user
if me.recent_changes() > 2: if me.recent_changes() > 2:
form.fields['room'].required = False
form.fields['room'].widget = HiddenInput() form.fields['room'].widget = HiddenInput()
form.fields['privacy'].widget = HiddenInput() form.fields['on_campus'].required = False
form.fields['on_campus'].widget = HiddenInput() form.fields['on_campus'].widget = HiddenInput()
else:
form.fields['room'].widget.user = self.request.user
# RAs and RDs cannot move off campus # RAs and RDs cannot move off campus
if me.is_staff(): if me.is_staff():
form.fields['on_campus'].required = False
form.fields['on_campus'].disabled = True form.fields['on_campus'].disabled = True
# bootstrap return form
form.fields['first_name'].widget.attrs['class'] = 'form-control'
form.fields['last_name'].widget.attrs['class'] = 'form-control'
form.fields['graduating_year'].widget.attrs['class'] = 'form-control'
# chosen
form.fields['major'].widget.attrs['class'] = 'form-control chosen-select'
form.fields['blocked_kids'].widget.attrs['class'] = 'form-control blocked-select'
context['my_form'] = form
return context
@ratelimit(key='user', rate='5/m', method='POST', block=True) @ratelimit(key='user', rate='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True) @ratelimit(key='user', rate='10/d', method='POST', block=True)
......
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