Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
roomlist
Commits
f9a93d2d
Commit
f9a93d2d
authored
Nov 09, 2015
by
Daniel W Bond
Browse files
began implementation of separate room select widget
parent
131743f0
Changes
4
Hide whitespace changes
Inline
Side-by-side
roomlist/accounts/forms.py
View file @
f9a93d2d
...
...
@@ -2,14 +2,36 @@
from
__future__
import
absolute_import
,
print_function
# core django imports
from
django
import
forms
from
django.utils.safestring
import
mark_safe
from
django.template.loader
import
render_to_string
# third party imports
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
,
Room
,
Major
from
housing.models
import
Building
from
.models
import
Student
,
Major
from
housing.models
import
Building
,
Floor
,
Room
class
SelectRoomWidget
(
forms
.
widgets
.
Select
):
template_name
=
'room_select_widget.html'
def
__init__
(
self
,
rooms
=
Room
.
objects
.
all
(),
floors
=
Floor
.
objects
.
all
(),
buildings
=
Building
.
objects
.
all
(),
neighborhoods
=
Building
.
NEIGHBOURHOOD_CHOICES
):
# should probably type check the other fields too
if
not
all
(
isinstance
(
thing
,
Room
)
for
thing
in
rooms
):
raise
TypeError
(
"Rooms in a SelectRoomWidget must all be Rooms!"
)
def
render
(
self
,
rooms
,
floors
,
buildings
,
neighborhoods
):
context
=
{
'neighborhoods'
:
neighborhoods
,
'buildings'
:
buildings
,
'floors'
:
floors
,
'rooms'
:
rooms
,
}
return
mark_safe
(
render_to_string
(
self
.
template_name
,
context
))
class
StudentUpdateForm
(
forms
.
Form
):
...
...
@@ -19,10 +41,7 @@ class StudentUpdateForm(forms.Form):
gender
=
MultiSelectFormField
(
choices
=
Student
.
GENDER_CHOICES
,
label
=
'Gender Identity (please choose all that apply)'
)
#neighborhood = forms.ChoiceField(choices=Building.NEIGHBOURHOOD_CHOICES)
#building = forms.ModelChoiceField(queryset=Building.objects.filter(neighbourhood=neighborhood)
#floor = forms.ModelChoiceField(queryset=Floor.objects.filter(building=building)
#room = forms.ModelChoiceField(queryset=Room.objects.filter(floor=floor))
room
=
forms
.
ModelChoiceField
(
widget
=
SelectRoomWidget
())
privacy
=
forms
.
ChoiceField
(
choices
=
Student
.
PRIVACY_CHOICES
)
major
=
forms
.
ModelChoiceField
(
queryset
=
Major
.
objects
.
all
())
...
...
@@ -33,7 +52,8 @@ 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)'
)
gender
=
MultiSelectFormField
(
choices
=
Student
.
GENDER_CHOICES
,
label
=
'Gender Identity (please choose all that apply)'
)
class
WelcomePrivacyForm
(
forms
.
ModelForm
):
...
...
roomlist/accounts/templates/room_select_widget.html
0 → 100644
View file @
f9a93d2d
{% 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 %}
<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>
roomlist/accounts/templates/updateStudent.html
View file @
f9a93d2d
...
...
@@ -80,8 +80,6 @@
</div>
</div>
{% load humanize %}
<div
class=
"col-md-8"
>
<div
class=
"panel panel-default"
>
...
...
@@ -93,35 +91,6 @@
<form
class=
"form-horizontal"
action=
""
method=
"post"
>
{% csrf_token %}
{{ my_form.as_p }}
<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 %}
<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"
>
<option
value=
""
>
---
</option>
{% for room in rooms %}
<option
value=
"{{ room.number }}"
class=
"{{ room.floor.slug }}"
>
{{ room.number }}
</option>
{% endfor %}
</select>
</div>
<input
type=
"submit"
value=
"Save"
class=
"btn btn-primary"
/>
</form>
...
...
roomlist/accounts/views.py
View file @
f9a93d2d
...
...
@@ -225,10 +225,6 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
context
[
'my_form'
]
=
form
context
[
'neighborhoods'
]
=
Building
.
NEIGHBOURHOOD_CHOICES
context
[
'buildings'
]
=
Building
.
objects
.
all
()
context
[
'floors'
]
=
Floor
.
objects
.
all
()
context
[
'rooms'
]
=
Room
.
objects
.
all
()
return
context
def
form_valid
(
self
,
form
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment