Commit 8805bbba authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added user to widget, widget to welcome_privacy

parent 6aa8bb1f
......@@ -20,14 +20,14 @@ class SelectRoomWidget(forms.widgets.Select):
template_name = 'room_select_widget.html'
def __init__(self, attrs=None, choices=None, floors=None, buildings=None, neighborhoods=None):
def __init__(self, user=None, attrs=None, rooms=None, floors=None, buildings=None, neighborhoods=None):
super(SelectRoomWidget, self).__init__(attrs)
# attrs to be implemented later (allows specifying css class, for example)
if attrs:
print("Sorry about that, but we're currently ignoring your fancy attrs.")
# should probably type check the other fields too
if choices is None:
self.choices = Room.objects.all()
if rooms is None:
self.rooms = Room.objects.all()
else:
if not all(isinstance(thing, Room) for thing in rooms):
raise TypeError("Rooms in a SelectRoomWidget must all be Rooms!")
......@@ -43,44 +43,41 @@ class SelectRoomWidget(forms.widgets.Select):
'neighborhoods': self.neighborhoods,
'buildings': self.buildings,
'floors': self.floors,
'rooms': self.choices,
'rooms': self.rooms,
}
if self.user is not None:
context['user'] = self.user
return mark_safe(render_to_string(self.template_name, context))
class SelectRoomField(forms.models.ModelChoiceField):
widget = SelectRoomWidget
# should raise error if user hasn't actually selected room, made it to end of selectors
# def clean(self, value):
class StudentUpdateForm(forms.Form):
first_name = forms.CharField(label='First Name')
last_name = forms.CharField(label='Last Name')
first_name = forms.CharField(label='First Name', required=False)
last_name = forms.CharField(label='Last Name', required=False)
gender = MultiSelectFormField(choices=Student.GENDER_CHOICES,
label='Gender Identity (please choose all that apply)')
label='Gender Identity (please choose all that apply)',
required=False)
room = SelectRoomField(queryset=Room.objects.all(), label='')
room = SelectRoomField(queryset=Room.objects.all(), label='', required=False)
privacy = forms.ChoiceField(choices=Student.PRIVACY_CHOICES)
major = forms.ModelChoiceField(queryset=Major.objects.all())
major = forms.ModelChoiceField(queryset=Major.objects.all(), required=False)
graduating_year = forms.IntegerField(label='Graduating Year')
def errors(self):
print("In errors.")
errors = super(StudentUpdateForm, self).errors()
print(errors)
return errors
def full_clean(self):
full_clean = super(StudentUpdateForm, self).full_clean()
print(full_clean)
return full_clean
def is_valid(self):
print("In is_valid.")
# errors are not printed in form.as_p?
#print("In is_valid.")
#print(self.is_bound, 'is bound')
#print(self.errors, type(self.errors), 'errors')
valid = super(StudentUpdateForm, self).is_valid()
print(valid)
#print(valid)
return valid
class WelcomeNameForm(forms.Form):
......@@ -97,6 +94,9 @@ class WelcomePrivacyForm(forms.ModelForm):
super(WelcomePrivacyForm, self).__init__(*args, **kwargs)
if self.instance.recent_changes() >= 2:
self.fields['room'].widget = forms.widgets.HiddenInput()
else:
self.fields['room'] = SelectRoomField(queryset=Room.objects.all(),
label='', required=False)
class Meta:
model = Student
......
{% load humanize %}
<div class="form-group">
<label>Neighborhood</label>
<select id="neighborhood" name="neighborhood">
{% for neighborhood in neighborhoods %}
<option value="{{ neighborhood.0 }}">{{ neighborhood.1 }}</option>
{% endfor %}
</select>
<label>Building</label>
<select id="building" name="building">
<option value="">---</option>
{% for building in buildings %}
<label>Neighborhood</label>
<select id="neighborhood" name="neighborhood">
{% for neighborhood in neighborhoods %}
{% if user.student.get_building.neighbourhood == neighborhood.0 %}
<option value="{{ neighborhood.0 }}" selected="selected">{{ neighborhood.1 }}</option>
{% else %}
<option value="{{ neighborhood.0 }}">{{ neighborhood.1 }}</option>
{% endif %}
{% endfor %}
</select>
<label>Building</label>
<select id="building" name="building">
<option value="">---</option>
{% for building in buildings %}
{% if user.student.get_building == building %}
<option value="{{ building.name }}" class="{{ building.neighbourhood }}" selected="selected">{{ building.name }}</option>
{% else %}
<option value="{{ building.name }}" class="{{ building.neighbourhood }}">{{ building.name }}</option>
{% endfor %}
</select>
<label>Floor</label>
<select id="floor" name="floor">
<option value="">---</option>
{% for floor in floors %}
<option value="{{ floor.slug }}" class="{{ floor.building.name }}">{{ floor.number|ordinal }}</option>
{% endfor %}
</select>
<label>Room</label>
<select id="room" name="room" class="roompicker">
<option value="">---</option>
{% for room in rooms %}
<option value="{{ room.number }}" class="{{ room.floor.slug }}">{{ room.number }}</option>
{% endfor %}
</select>
</div>
{% endif %}
{% endfor %}
</select>
<label>Floor</label>
<select id="floor" name="floor">
<option value="">---</option>
{% for floor in floors %}
{% if user.student.get_floor.pk == floor.pk %}
<option value="{{ floor.pk }}" class="{{ floor.building.name }}" selected="selected">{{ floor.number|ordinal }}</option>
{% else %}
<option value="{{ floor.pk }}" class="{{ floor.building.name }}">{{ floor.number|ordinal }}</option>
{% endif %}
{% endfor %}
</select>
<label>Room</label>
<select id="room" name="room" class="roompicker">
<option value="">---</option>
{% for room in rooms %}
{% if user.student.room.pk == room.pk %}
<option value="{{ room.pk }}" class="{{ room.floor.pk }}" selected="selected">{{ room.number }}</option>
{% else %}
<option value="{{ room.pk }}" class="{{ room.floor.pk }}">{{ room.number }}</option>
{% endif %}
{% endfor %}
</select>
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