Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
9b5586c3
Commit
9b5586c3
authored
Mar 04, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation for MCQs
parent
8c4d0dc5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
mentoring/mcq.py
+28
-0
No files found.
mentoring/mcq.py
View file @
9b5586c3
...
...
@@ -27,6 +27,7 @@ import logging
from
xblock.fields
import
Scope
,
String
,
List
from
xblock.fragment
import
Fragment
from
xblock.validation
import
ValidationMessage
from
xblockutils.resources
import
ResourceLoader
from
.questionnaire
import
QuestionnaireAbstractBlock
...
...
@@ -101,6 +102,33 @@ class MCQBlock(QuestionnaireAbstractBlock):
fragment
.
add_css_url
(
self
.
runtime
.
local_resource_url
(
self
,
'public/css/questionnaire-edit.css'
))
return
fragment
def
validate_field_data
(
self
,
validation
,
data
):
"""
Validate this block's field data.
"""
super
(
MCQBlock
,
self
)
.
validate_field_data
(
validation
,
data
)
def
add_error
(
msg
):
validation
.
add
(
ValidationMessage
(
ValidationMessage
.
ERROR
,
msg
))
def
choice_name
(
choice_value
):
for
choice
in
self
.
human_readable_choices
:
if
choice
[
"value"
]
==
choice_value
:
return
choice
[
"display_name"
]
return
choice_value
all_values
=
set
(
self
.
all_choice_values
)
correct
=
set
(
data
.
correct_choices
)
if
not
all_values
:
add_error
(
u"No choices set yet."
)
elif
not
correct
:
add_error
(
u"You must indicate the correct answer[s], or the student will always get this question wrong."
)
if
len
(
correct
)
<
len
(
data
.
correct_choices
):
add_error
(
u"Duplicate correct choices set"
)
for
val
in
(
correct
-
all_values
):
add_error
(
u"A choice value listed as correct does not exist: {}"
.
format
(
choice_name
(
val
)))
class
RatingBlock
(
MCQBlock
):
"""
...
...
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