From ea3b1f93b021af9c0d9d3db383face5d37753dda Mon Sep 17 00:00:00 2001 From: Alexander Kryklia Date: Fri, 21 Dec 2012 12:24:54 +0200 Subject: [PATCH] updated drag and drop files --- common/lib/capa/capa/inputtypes.py | 30 ++++++++++++- .../capa/templates/drag_and_drop_input.html | 6 ++- common/lib/capa/capa/tests/test_inputtypes.py | 42 ++++++++++++++++++- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 73056bc09e..3f01ed58a7 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -13,6 +13,9 @@ Module containing the problem elements which render into input objects - imageinput (for clickable image) - optioninput (for option list) - filesubmission (upload a file) +- crystallography +- vsepr_input +- drag_and_drop These are matched by *.html files templates/*.html which are mako templates with the actual html. @@ -782,4 +785,29 @@ class OpenEndedInput(InputTypeBase): registry.register(OpenEndedInput) -#----------------------------------------------------------------------------- +# ------------------------------------------------------------------------- + + +class DragAndDropInput(InputTypeBase): + """ + Input for molecular geometry--show possible structures, let student + pick structure and label positions with atoms or electron pairs. + """ + + template = 'drag_and_drop.html' + tags = ['drag_and_drop_input'] + + @classmethod + def get_attributes(cls): + """ + Note: height, width are required. + """ + return [Attribute('height'), + Attribute('width'), + Attribute('template'), + Attribute('images'), + ] + +registry.register(DragAndDropInput) + +#-------------------------------------------------------------------------------------------------------------------- diff --git a/common/lib/capa/capa/templates/drag_and_drop_input.html b/common/lib/capa/capa/templates/drag_and_drop_input.html index 8613c97479..00752ea748 100644 --- a/common/lib/capa/capa/templates/drag_and_drop_input.html +++ b/common/lib/capa/capa/templates/drag_and_drop_input.html @@ -1,6 +1,7 @@
+ style="width:${width};height:${height}" + data-template="${template}" data-images="${images}">
@@ -15,7 +16,8 @@ % endif - +

% if status == 'unsubmitted': diff --git a/common/lib/capa/capa/tests/test_inputtypes.py b/common/lib/capa/capa/tests/test_inputtypes.py index dafd31bdc7..743ac7a548 100644 --- a/common/lib/capa/capa/tests/test_inputtypes.py +++ b/common/lib/capa/capa/tests/test_inputtypes.py @@ -9,7 +9,7 @@ TODO: - check rendering -- e.g. msg should appear in the rendered output. If possible, test that templates are escaping things properly. - + - test unicode in values, parameters, etc. - test various html escapes - test funny xml chars -- should never get xml parse error if things are escaped properly. @@ -501,3 +501,43 @@ class ChemicalEquationTest(unittest.TestCase): } self.assertEqual(context, expected) + +class DragAndDropTest(unittest.TestCase): + ''' + Check that drag and drop inputs work + ''' + + def test_rendering(self): + height = '12' + width = '33' + template = "path to template" + images = "path to images" + + xml_str = """""".format(h=height, w=width, t=template, i=images) + + element = etree.fromstring(xml_str) + + value = 'abc' + state = {'value': value, + 'status': 'unsubmitted'} + + the_input = lookup_tag('drag_and_drop')(test_system, element, state) + + context = the_input._get_render_context() + + expected = {'id': 'prob_1_2', + 'value': value, + 'status': 'unsubmitted', + 'msg': '', + 'width': width, + 'height': height, + 'template': template, + 'images': images, + } + + self.assertEqual(context, expected)