Commit 6471e275 by Ehtesham

getting inputtypes from registry

parent 9eb4253f
...@@ -2,22 +2,27 @@ ...@@ -2,22 +2,27 @@
var summaryMessage = validation.get("summary"); var summaryMessage = validation.get("summary");
var aggregateMessageType = summaryMessage.type; var aggregateMessageType = summaryMessage.type;
var aggregateValidationClass = aggregateMessageType === "error" ? "has-errors" : "has-warnings"; var aggregateValidationClass = aggregateMessageType === "error" ? "has-errors" : "has-warnings";
var actionLink = (summaryMessage.action_class === 'external-link' && summaryMessage.action_link) ?
summaryMessage.action_link : '#';
%> %>
<div class="xblock-message validation <%= aggregateValidationClass %> <%= additionalClasses %>"> <div class="xblock-message validation <%= aggregateValidationClass %> <%= additionalClasses %>">
<p class="<%= aggregateMessageType %>"><i class="icon fa <%= getIcon(aggregateMessageType) %>"></i> <p class="<%= aggregateMessageType %>"><i class="icon fa <%= getIcon(aggregateMessageType) %>"></i>
<%- summaryMessage.text %> <%- summaryMessage.text %>
<% if (summaryMessage.action_class) { %> <% if (summaryMessage.action_class && actionLink === '#') { %>
<a href="<%= summaryMessage.action_link ? summaryMessage.action_link : '#' %>" class="button action-button <%- summaryMessage.action_class %>"> <a href="#" class="button action-button <%- summaryMessage.action_class %>">
<span class="action-button-text"><%- summaryMessage.action_label %></span> <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> </a>
<% } else if (summaryMessage.action_runtime_event) {%> <% } else if (actionLink !== '#') { %>
<a href="#" class="button action-button notification-action-button" data-notification-action="<%- summaryMessage.action_runtime_event %>"> <a href="<%= actionLink %>" target="_blank" class="button action-button <%- summaryMessage.action_class %>">
<span class="action-button-text"><%- summaryMessage.action_label %></span> <span class="action-button-text"><%- summaryMessage.action_label %></span>
<i class="fa fa-external-link-square" aria-hidden="true"></i>
</a> </a>
<% } %> <% } else if (summaryMessage.action_runtime_event) { %>
<a href="#" class="button action-button notification-action-button"
data-notification-action="<%- summaryMessage.action_runtime_event %>">
<span class="action-button-text"><%- summaryMessage.action_label %></span>
</a>
<% } %>
</p> </p>
<% var detailedMessages = validation.get("messages"); %> <% var detailedMessages = validation.get("messages"); %>
<% if (detailedMessages.length > 0) { %> <% if (detailedMessages.length > 0) { %>
......
...@@ -11,7 +11,7 @@ import dogstats_wrapper as dog_stats_api ...@@ -11,7 +11,7 @@ import dogstats_wrapper as dog_stats_api
from xmodule.validation import StudioValidation, StudioValidationMessage from xmodule.validation import StudioValidation, StudioValidationMessage
from .capa_base import CapaMixin, CapaFields, ComplexEncoder from .capa_base import CapaMixin, CapaFields, ComplexEncoder
from capa import responsetypes from capa import responsetypes, inputtypes
from .progress import Progress from .progress import Progress
from xmodule.util.misc import escape_html_characters from xmodule.util.misc import escape_html_characters
from xmodule.x_module import XModule, module_attr, DEPRECATION_VSCOMPAT_EVENT from xmodule.x_module import XModule, module_attr, DEPRECATION_VSCOMPAT_EVENT
...@@ -277,9 +277,9 @@ class CapaDescriptor(CapaFields, RawDescriptor): ...@@ -277,9 +277,9 @@ class CapaDescriptor(CapaFields, RawDescriptor):
validation = StudioValidation.copy(validation) validation = StudioValidation.copy(validation)
# validate xml to check questions are correctly separated # validate xml to check questions are correctly separated
is_valid = self.validate_xml() is_valid_xml = self.validate_xml_for_inputtypes()
if not is_valid: if not is_valid_xml:
validation.set_summary( validation.set_summary(
StudioValidationMessage( StudioValidationMessage(
StudioValidationMessage.WARNING, StudioValidationMessage.WARNING,
...@@ -292,18 +292,21 @@ class CapaDescriptor(CapaFields, RawDescriptor): ...@@ -292,18 +292,21 @@ class CapaDescriptor(CapaFields, RawDescriptor):
return validation return validation
def validate_xml(self): def validate_xml_for_inputtypes(self):
input_tags = ['choiceresponse', 'optionresponse', 'multiplechoiceresponse', 'stringresponse', """
'numericalresponse', 'schematicresponse', 'imageresponse', 'formularesponse'] Looks for more than one occurrences of inputtypes inside each <question>
if found returns False
"""
input_types = inputtypes.registry.registered_tags()
from nose.tools import set_trace; set_trace()
xmltree = etree.fromstring(self.data) xmltree = etree.fromstring(self.data)
questions = xmltree.findall(".//question") questions = xmltree.findall(".//question")
for question in questions: for question in questions:
for tag in input_tags: for tag in input_types:
tag_elements = question.findall(".//" + tag) tag_elements = question.findall(".//" + tag)
if len(tag_elements) > 1: if len(tag_elements) > 1:
print("more choices")
return False return False
return True return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment