From 89ea8b31c6f248b45e991c4c7ad0ca8a4afb9ad9 Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Tue, 26 May 2015 23:20:39 -0400 Subject: [PATCH] MA-725 responsive_ui indication on responsive xBlocks. --- common/lib/capa/capa/capa_problem.py | 7 +++++++ common/lib/capa/capa/responsetypes.py | 10 ++++++++++ common/lib/xmodule/xmodule/capa_module.py | 7 +++++++ common/lib/xmodule/xmodule/html_module.py | 1 + 4 files changed, 25 insertions(+) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 48b07bd876..707232cc79 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -527,6 +527,13 @@ class LoncapaProblem(object): log.warning("Could not find matching input for id: %s", input_id) return {} + @property + def has_responsive_ui(self): + """ + Returns whether this capa problem has support for responsive UI. + """ + return all(responder.has_responsive_ui for responder in self.responders.values()) + # ======= Private Methods Below ======== def _process_includes(self): diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index ec23d4ba9c..54fe52af26 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -138,6 +138,11 @@ class LoncapaResponse(object): allowed_inputfields = [] required_attributes = [] + # Overridable field that specifies whether this capa response type has support for + # responsive UI, for rendering on devices of different sizes and shapes. + # By default, we set this to False, allowing subclasses to override as appropriate. + has_responsive_ui = False + def __init__(self, xml, inputfields, context, system): """ Init is passed the following arguments: @@ -692,6 +697,7 @@ class ChoiceResponse(LoncapaResponse): max_inputfields = 1 allowed_inputfields = ['checkboxgroup', 'radiogroup'] correct_choices = None + has_responsive_ui = True def setup_response(self): @@ -763,6 +769,7 @@ class MultipleChoiceResponse(LoncapaResponse): max_inputfields = 1 allowed_inputfields = ['choicegroup'] correct_choices = None + has_responsive_ui = True def setup_response(self): # call secondary setup for MultipleChoice questions, to set name @@ -1084,6 +1091,7 @@ class OptionResponse(LoncapaResponse): hint_tag = 'optionhint' allowed_inputfields = ['optioninput'] answer_fields = None + has_responsive_ui = True def setup_response(self): self.answer_fields = self.inputfields @@ -1136,6 +1144,7 @@ class NumericalResponse(LoncapaResponse): allowed_inputfields = ['textline', 'formulaequationinput'] required_attributes = ['answer'] max_inputfields = 1 + has_responsive_ui = True def __init__(self, *args, **kwargs): self.correct_answer = '' @@ -1338,6 +1347,7 @@ class StringResponse(LoncapaResponse): required_attributes = ['answer'] max_inputfields = 1 correct_answer = [] + has_responsive_ui = True def setup_response_backward(self): self.correct_answer = [ diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index d647aa8c0d..92459e91cb 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -187,6 +187,13 @@ class CapaDescriptor(CapaFields, RawDescriptor): registered_tags = responsetypes.registry.registered_tags() return set([node.tag for node in tree.iter() if node.tag in registered_tags]) + @property + def has_responsive_ui(self): + """ + Returns whether this module has support for responsive UI. + """ + return self.lcp.has_responsive_ui + def index_dictionary(self): """ Return dictionary prepared with module content and type for indexing. diff --git a/common/lib/xmodule/xmodule/html_module.py b/common/lib/xmodule/xmodule/html_module.py index 81b92f5fb6..8dcedfcc52 100644 --- a/common/lib/xmodule/xmodule/html_module.py +++ b/common/lib/xmodule/xmodule/html_module.py @@ -95,6 +95,7 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor): # pylint: d module_class = HtmlModule filename_extension = "xml" template_dir_name = "html" + has_responsive_ui = True js = {'coffee': [resource_string(__name__, 'js/src/html/edit.coffee')]} js_module_name = "HTMLEditingDescriptor"