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
fe8a0067
Commit
fe8a0067
authored
Feb 01, 2016
by
Daniel W Bond
Browse files
moved relevant forms from accounts to welcome
parent
bc525836
Changes
2
Hide whitespace changes
Inline
Side-by-side
roomlist/accounts/forms.py
View file @
fe8a0067
...
...
@@ -4,13 +4,8 @@ from __future__ import absolute_import, print_function
from
django
import
forms
from
django.utils.safestring
import
mark_safe
from
django.template.loader
import
render_to_string
from
django.utils.encoding
import
force_text
from
django.core.exceptions
import
ValidationError
from
django.utils.translation
import
ugettext
as
_
# 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
,
Major
...
...
@@ -104,47 +99,3 @@ class StudentUpdateForm(forms.Form):
valid
=
super
(
StudentUpdateForm
,
self
).
is_valid
()
#print(valid)
return
valid
class
WelcomeNameForm
(
forms
.
Form
):
first_name
=
forms
.
CharField
(
required
=
False
)
last_name
=
forms
.
CharField
(
required
=
False
)
gender
=
MultiSelectFormField
(
choices
=
Student
.
GENDER_CHOICES
,
required
=
False
)
show_gender
=
BooleanRadioField
()
class
WelcomePrivacyForm
(
forms
.
ModelForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
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
(),
required
=
False
)
on_campus
=
BooleanRadioField
()
def
clean
(
self
):
cleaned_data
=
super
(
WelcomePrivacyForm
,
self
).
clean
()
form_room
=
cleaned_data
.
get
(
'room'
)
if
not
(
form_room
is
None
):
students_in_room
=
Student
.
objects
.
filter
(
room
=
form_room
).
count
()
#print(students_in_room)
# like in bookshare, I have no idea why the form errors don't display.
if
students_in_room
>
12
:
raise
ValidationError
(
_
(
'Too many students in room (%d).'
%
students_in_room
),
code
=
'invalid'
)
class
Meta
:
model
=
Student
fields
=
(
'room'
,
'privacy'
,
'on_campus'
)
class
WelcomeSocialForm
(
forms
.
ModelForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
WelcomeSocialForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'completedSocial'
].
widget
=
forms
.
widgets
.
HiddenInput
()
class
Meta
:
model
=
Student
fields
=
(
'completedSocial'
,
)
roomlist/welcome/forms.py
0 → 100644
View file @
fe8a0067
# standard library imports
from
__future__
import
absolute_import
,
print_function
# core django imports
from
django
import
forms
from
django.core.exceptions
import
ValidationError
# third party imports
from
multiselectfield
import
MultiSelectFormField
# imports from your apps
from
accounts.models
import
Student
,
Major
from
accounts.forms
import
SelectRoomField
,
BooleanRadioField
from
housing.models
import
Room
class
WelcomeNameForm
(
forms
.
Form
):
first_name
=
forms
.
CharField
(
required
=
False
)
last_name
=
forms
.
CharField
(
required
=
False
)
gender
=
MultiSelectFormField
(
choices
=
Student
.
GENDER_CHOICES
,
required
=
False
)
show_gender
=
BooleanRadioField
()
class
WelcomePrivacyForm
(
forms
.
ModelForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
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
(),
required
=
False
)
on_campus
=
BooleanRadioField
()
def
clean
(
self
):
cleaned_data
=
super
(
WelcomePrivacyForm
,
self
).
clean
()
form_room
=
cleaned_data
.
get
(
'room'
)
if
not
(
form_room
is
None
):
students_in_room
=
Student
.
objects
.
filter
(
room
=
form_room
).
count
()
#print(students_in_room)
# like in bookshare, I have no idea why the form errors don't display.
if
students_in_room
>
12
:
raise
ValidationError
(
_
(
'Too many students in room (%d).'
%
students_in_room
),
code
=
'invalid'
)
class
Meta
:
model
=
Student
fields
=
(
'room'
,
'privacy'
,
'on_campus'
)
class
WelcomeMajorForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Student
fields
=
(
'major'
,
'graduating_year'
,
)
class
WelcomeSocialForm
(
forms
.
ModelForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
WelcomeSocialForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'completedSocial'
].
widget
=
forms
.
widgets
.
HiddenInput
()
class
Meta
:
model
=
Student
fields
=
(
'completedSocial'
,
)
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