Commit b831ab73 authored by Daniel W Bond's avatar Daniel W Bond

making full use of get_inital and get_form instead of cramming everything into get_context_data

parent 13649278
......@@ -40,18 +40,15 @@ class WelcomeName(LoginRequiredMixin, FormView):
else:
return super(WelcomeName, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(WelcomeName, self).get_context_data(**kwargs)
def get_initial(self):
me = self.request.user.student
form = WelcomeNameForm(initial={'first_name': me.user.first_name,
'last_name': me.user.last_name,
'gender': me.gender,
'show_gender': me.show_gender, })
initial = {'first_name': me.user.first_name,
'last_name': me.user.last_name,
'gender': me.gender,
'show_gender': me.show_gender, }
context['my_form'] = form
return context
return initial
@ratelimit(key='user', rate='5/m', method='POST', block=True)
@ratelimit(key='user', rate='10/d', method='POST', block=True)
......@@ -94,17 +91,27 @@ class WelcomePrivacy(LoginRequiredMixin, FormView):
else:
return super(WelcomePrivacy, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(WelcomePrivacy, self).get_context_data(**kwargs)
def get_initial(self):
me = self.request.user.student
form = WelcomePrivacyForm(initial={'on_campus': me.on_campus,
'privacy': me.privacy, })
initial={'on_campus': me.on_campus,
'privacy': me.privacy, }
return initial
def get_form(self):
form = super(WelcomePrivacy, self).get_form(WelcomePrivacyForm)
me = self.request.user.student
form.fields['room'].widget.user = self.request.user
context['my_form'] = form
return form
def get_context_data(self, **kwargs):
context = super(WelcomePrivacy, self).get_context_data(**kwargs)
me = self.request.user.student
context['student'] = me
......@@ -174,17 +181,19 @@ class WelcomeMajor(LoginRequiredMixin, FormView):
else:
return super(WelcomeMajor, self).get(request, *args, **kwargs)
def get_initial(self):
me = self.request.user.student
initial={'major': me.major.all(),
'graduating_year': me.graduating_year, }
return initial
def get_context_data(self, **kwargs):
context = super(WelcomeMajor, self).get_context_data(**kwargs)
me = self.request.user.student
form = WelcomeMajorForm(initial={'major': me.major.all(),
'graduating_year': me.graduating_year, })
form.fields['major'].widget.attrs['class'] = 'form-control chosen-select'
context['my_form'] = form
context['student'] = me
return context
......
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