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
Jean Michel Rouly
research-questions
Commits
c51c806c
Commit
c51c806c
authored
Mar 08, 2014
by
Jean Michel Rouly
Browse files
Added section field processing.
parent
e28c760d
Changes
1
Hide whitespace changes
Inline
Side-by-side
researchquestions/website/forms.py
View file @
c51c806c
...
...
@@ -2,18 +2,38 @@ from website.models import Question, Comment, Reply
from
django
import
forms
from
django.db
import
models
from
django.forms
import
ModelForm
,
Textarea
from
django.forms
import
ModelForm
,
Textarea
,
TextInput
class
QuestionForm
(
ModelForm
):
class
Meta
:
model
=
Question
fields
=
(
'text'
,)
fields
=
(
'text'
,
'section'
,
)
exclude
=
(
'user'
,
'date'
,
'rating'
)
localized_fields
=
(
'date'
,)
labels
=
{
'text'
:
'Question Text'
,
'section'
:
'Course Section'
,
}
widgets
=
{
'text'
:
Textarea
(
attrs
=
{
'class'
:
'form-control'
,}),
'text'
:
Textarea
(
attrs
=
{
'class'
:
'form-control'
,
'placeholder'
:
'Question Text'
,
}),
'section'
:
TextInput
(
attrs
=
{
'class'
:
'form-control'
,
'placeholder'
:
'Course Section'
,
'pattern'
:
'[a-zA-Z]+ {0,1}[0-9]*'
,
}),
}
# Parse out unneeded spaces from the section. This makes everything
# nice and sanitary and uniform.
def
clean_section
(
self
):
data
=
self
.
cleaned_data
.
get
(
'section'
)
if
data
is
not
None
:
data
=
data
.
upper
().
replace
(
" "
,
""
)
return
data
class
CommentForm
(
ModelForm
):
class
Meta
:
model
=
Comment
...
...
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