Commit 1b8360cc authored by Daniel W Bond's avatar Daniel W Bond

finished gender welcome page

parent d7d2e796
......@@ -4,6 +4,7 @@ from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout
from crispy_forms.bootstrap import PrependedText, AppendedText
from multiselectfield import MultiSelectFormField
# imports from your apps
from .models import Student
......@@ -47,3 +48,11 @@ class UserSettingsForm(forms.ModelForm):
class Meta:
model = Student
class WelcomeNameForm(forms.Form):
first_name = forms.CharField(label='First Name')
last_name = forms.CharField(label='Last Name')
gender = MultiSelectFormField(choices=Student.GENDER_CHOICES, label='Gender Identity (please choose all that apply)')
......@@ -27,12 +27,12 @@
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title text-center">Name & Gender</h1>
<h1 class="panel-title text-center"><strong>Name & Gender</strong></h1>
</div>
<div class="panel-body">
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
{{ my_form.as_p }}
<input type="submit" value="Save" class="btn btn-primary"/>
</form>
</div>
......
......@@ -118,11 +118,32 @@ class WelcomeName(LoginRequiredMixin, FormView):
form_class = WelcomeNameForm
login_url = 'login'
def get_context_data(self, **kwargs):
context = super(WelcomeName, self).get_context_data(**kwargs)
me = Student.objects.get(user=self.request.user)
form = WelcomeNameForm(initial={'first_name': me.user.first_name,
'last_name': me.user.last_name,
'gender': me.gender, })
context['my_form'] = form
return context
def form_valid(self, form):
self.obj = self.get_object()
me = Student.objects.get(user=self.request.user)
self.obj.completedName = True
self.obj.save()
me.user.first_name = form.data['first_name']
me.user.last_name = form.data['last_name']
#for identity in form.data['gender']
me.gender = form.data.getlist('gender')
me.completedName = True
me.user.save()
me.save()
return super(WelcomeName, self).form_valid(form)
......
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