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

created Field to display booleans as radios; removed labels from...

created Field to display booleans as radios; removed labels from updatestudent; changed existing booleanfields to radioboolean; added on_campus to updatestudent and welceomprivacy
parent 323e99bf
...@@ -57,22 +57,33 @@ class SelectRoomField(forms.models.ModelChoiceField): ...@@ -57,22 +57,33 @@ class SelectRoomField(forms.models.ModelChoiceField):
# should raise error if user hasn't actually selected room, made it to end of selectors # should raise error if user hasn't actually selected room, made it to end of selectors
# def clean(self, value): # def clean(self, value):
class BooleanRadioField(forms.TypedChoiceField):
def __init__(self, *args, **kwargs):
boolean_choices = ((True, 'Yes'), (False, 'No'))
kwargs['widget'] = forms.RadioSelect
kwargs['choices'] = boolean_choices
kwargs['coerce'] = bool
kwargs['required'] = True
super(BooleanRadioField, self).__init__(*args, **kwargs)
class StudentUpdateForm(forms.Form): class StudentUpdateForm(forms.Form):
first_name = forms.CharField(label='First Name', required=False) first_name = forms.CharField(required=False)
last_name = forms.CharField(label='Last Name', required=False) last_name = forms.CharField(required=False)
gender = MultiSelectFormField(choices=Student.GENDER_CHOICES, gender = MultiSelectFormField(choices=Student.GENDER_CHOICES,
label='Gender Identity (please choose all that apply)',
required=False) required=False)
show_gender = forms.BooleanField(label='Show your gender on your profile?', show_gender = BooleanRadioField()
required=False)
room = SelectRoomField(queryset=Room.objects.all(), label='', required=False) on_campus = BooleanRadioField()
room = SelectRoomField(queryset=Room.objects.all(), required=False)
privacy = forms.ChoiceField(choices=Student.PRIVACY_CHOICES) privacy = forms.TypedChoiceField(choices=Student.PRIVACY_CHOICES)
major = forms.ModelChoiceField(queryset=Major.objects.all(), required=False, major = forms.ModelChoiceField(queryset=Major.objects.all(), required=False)
label='Major (select one)',) graduating_year = forms.IntegerField()
graduating_year = forms.IntegerField(label='Graduating Year')
def clean(self): def clean(self):
...@@ -94,6 +105,7 @@ class StudentUpdateForm(forms.Form): ...@@ -94,6 +105,7 @@ class StudentUpdateForm(forms.Form):
#print(valid) #print(valid)
return valid return valid
class WelcomeNameForm(forms.Form): class WelcomeNameForm(forms.Form):
first_name = forms.CharField(label='First Name', required=False) first_name = forms.CharField(label='First Name', required=False)
...@@ -101,8 +113,7 @@ class WelcomeNameForm(forms.Form): ...@@ -101,8 +113,7 @@ class WelcomeNameForm(forms.Form):
gender = MultiSelectFormField(choices=Student.GENDER_CHOICES, gender = MultiSelectFormField(choices=Student.GENDER_CHOICES,
label='Gender Identity (please choose all that apply)', label='Gender Identity (please choose all that apply)',
required=False) required=False)
show_gender = forms.BooleanField(label='Show your gender on your profile?', show_gender = BooleanRadioField(label='Show your gender on your profile?')
required=False)
class WelcomePrivacyForm(forms.ModelForm): class WelcomePrivacyForm(forms.ModelForm):
...@@ -112,8 +123,9 @@ class WelcomePrivacyForm(forms.ModelForm): ...@@ -112,8 +123,9 @@ class WelcomePrivacyForm(forms.ModelForm):
if self.instance.recent_changes() > 2: if self.instance.recent_changes() > 2:
self.fields['room'].widget = forms.widgets.HiddenInput() self.fields['room'].widget = forms.widgets.HiddenInput()
else: else:
self.fields['room'] = SelectRoomField(queryset=Room.objects.all(), self.fields['room'] = SelectRoomField(queryset=Room.objects.all(), required=False)
label='', required=False)
on_campus = BooleanRadioField()
def clean(self): def clean(self):
cleaned_data = super(WelcomePrivacyForm, self).clean() cleaned_data = super(WelcomePrivacyForm, self).clean()
...@@ -127,8 +139,7 @@ class WelcomePrivacyForm(forms.ModelForm): ...@@ -127,8 +139,7 @@ class WelcomePrivacyForm(forms.ModelForm):
class Meta: class Meta:
model = Student model = Student
fields = ('room', 'privacy', ) fields = ('room', 'privacy', 'on_campus')
class WelcomeSocialForm(forms.ModelForm): class WelcomeSocialForm(forms.ModelForm):
......
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