Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
9eb4253f
Commit
9eb4253f
authored
Jun 02, 2016
by
Ehtesham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding warning message if more than one inputtypes in one question
parent
0cfa3ff9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
4 deletions
+67
-4
cms/templates/js/xblock-validation-messages.underscore
+5
-2
common/lib/xmodule/xmodule/capa_module.py
+53
-0
common/lib/xmodule/xmodule/validation.py
+9
-2
No files found.
cms/templates/js/xblock-validation-messages.underscore
View file @
9eb4253f
<%
var summaryMessage = validation.get("summary");
var aggregateMessageType = summaryMessage.type;
var aggregateValidationClass = aggregateMessageType === "error"? "has-errors" : "has-warnings";
var aggregateValidationClass = aggregateMessageType === "error"
? "has-errors" : "has-warnings";
%>
<div class="xblock-message validation <%= aggregateValidationClass %> <%= additionalClasses %>">
<p class="<%= aggregateMessageType %>"><i class="icon fa <%= getIcon(aggregateMessageType) %>"></i>
<%- summaryMessage.text %>
<% if (summaryMessage.action_class) { %>
<a href="
#
" class="button action-button <%- summaryMessage.action_class %>">
<a href="
<%= summaryMessage.action_link ? summaryMessage.action_link : '#' %>
" class="button action-button <%- summaryMessage.action_class %>">
<span class="action-button-text"><%- summaryMessage.action_label %></span>
<% if (summaryMessage.action_class === 'external-link') { %>
<i class="fa fa-external-link-square" aria-hidden="true"></i>
<% } %>
</a>
<% } else if (summaryMessage.action_runtime_event) {%>
<a href="#" class="button action-button notification-action-button" data-notification-action="<%- summaryMessage.action_runtime_event %>">
...
...
common/lib/xmodule/xmodule/capa_module.py
View file @
9eb4253f
...
...
@@ -8,6 +8,8 @@ from lxml import etree
from
pkg_resources
import
resource_string
import
dogstats_wrapper
as
dog_stats_api
from
xmodule.validation
import
StudioValidation
,
StudioValidationMessage
from
.capa_base
import
CapaMixin
,
CapaFields
,
ComplexEncoder
from
capa
import
responsetypes
from
.progress
import
Progress
...
...
@@ -128,6 +130,15 @@ class CapaModule(CapaMixin, XModule):
return
json
.
dumps
(
result
,
cls
=
ComplexEncoder
)
def
validate
(
self
):
"""
Message for either error or warning validation message/s.
Returns message and type. Priority given to error type message.
"""
return
self
.
descriptor
.
validate
()
class
CapaDescriptor
(
CapaFields
,
RawDescriptor
):
"""
...
...
@@ -256,6 +267,48 @@ class CapaDescriptor(CapaFields, RawDescriptor):
)
return
False
def
validate
(
self
):
"""
Validates the xml for correct question separation. There must be only one inputtype in every <question>.
This is the override of the general XBlock method.
"""
validation
=
super
(
CapaDescriptor
,
self
)
.
validate
()
validation
=
StudioValidation
.
copy
(
validation
)
# validate xml to check questions are correctly separated
is_valid
=
self
.
validate_xml
()
if
not
is_valid
:
validation
.
set_summary
(
StudioValidationMessage
(
StudioValidationMessage
.
WARNING
,
u'Incorrect problem format detected!'
,
action_label
=
u"Please see docs."
,
action_class
=
u"external-link"
,
action_link
=
u"http://docs.edx.org/"
)
)
return
validation
def
validate_xml
(
self
):
input_tags
=
[
'choiceresponse'
,
'optionresponse'
,
'multiplechoiceresponse'
,
'stringresponse'
,
'numericalresponse'
,
'schematicresponse'
,
'imageresponse'
,
'formularesponse'
]
xmltree
=
etree
.
fromstring
(
self
.
data
)
questions
=
xmltree
.
findall
(
".//question"
)
for
question
in
questions
:
for
tag
in
input_tags
:
tag_elements
=
question
.
findall
(
".//"
+
tag
)
if
len
(
tag_elements
)
>
1
:
print
(
"more choices"
)
return
False
return
True
# Proxy to CapaModule for access to any of its attributes
answer_available
=
module_attr
(
'answer_available'
)
check_button_name
=
module_attr
(
'check_button_name'
)
...
...
common/lib/xmodule/xmodule/validation.py
View file @
9eb4253f
...
...
@@ -15,12 +15,13 @@ class StudioValidationMessage(ValidationMessage):
TYPES
=
[
ValidationMessage
.
WARNING
,
ValidationMessage
.
ERROR
,
NOT_CONFIGURED
]
def
__init__
(
self
,
message_type
,
message_text
,
action_label
=
None
,
action_class
=
None
,
action_runtime_event
=
None
):
def
__init__
(
self
,
message_type
,
message_text
,
action_label
=
None
,
action_class
=
None
,
action_runtime_event
=
None
,
action_link
=
None
):
"""
Create a new message.
Args:
message_type (str): The type associated with this message. M
o
st be `WARNING` or `ERROR`.
message_type (str): The type associated with this message. M
u
st be `WARNING` or `ERROR`.
message_text (unicode): The textual message.
action_label (unicode): Text to show on a "fix-up" action (optional). If present, either `action_class`
or `action_runtime_event` should be specified.
...
...
@@ -43,6 +44,10 @@ class StudioValidationMessage(ValidationMessage):
if
not
isinstance
(
action_runtime_event
,
basestring
):
raise
TypeError
(
"Action runtime event must be a string."
)
self
.
action_runtime_event
=
action_runtime_event
if
action_link
is
not
None
:
if
not
isinstance
(
action_link
,
basestring
):
raise
TypeError
(
"Action link must be a string."
)
self
.
action_link
=
action_link
def
to_json
(
self
):
"""
...
...
@@ -58,6 +63,8 @@ class StudioValidationMessage(ValidationMessage):
serialized
[
"action_class"
]
=
self
.
action_class
if
hasattr
(
self
,
"action_runtime_event"
):
serialized
[
"action_runtime_event"
]
=
self
.
action_runtime_event
if
hasattr
(
self
,
"action_link"
):
serialized
[
"action_link"
]
=
self
.
action_link
return
serialized
...
...
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