Commit ea3b1f93 by Alexander Kryklia

updated drag and drop files

parent 5200534a
...@@ -13,6 +13,9 @@ Module containing the problem elements which render into input objects ...@@ -13,6 +13,9 @@ Module containing the problem elements which render into input objects
- imageinput (for clickable image) - imageinput (for clickable image)
- optioninput (for option list) - optioninput (for option list)
- filesubmission (upload a file) - filesubmission (upload a file)
- crystallography
- vsepr_input
- drag_and_drop
These are matched by *.html files templates/*.html which are mako templates with the These are matched by *.html files templates/*.html which are mako templates with the
actual html. actual html.
...@@ -782,4 +785,29 @@ class OpenEndedInput(InputTypeBase): ...@@ -782,4 +785,29 @@ class OpenEndedInput(InputTypeBase):
registry.register(OpenEndedInput) 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)
#--------------------------------------------------------------------------------------------------------------------
<section id="inputtype_${id}" class="capa_inputtype" > <section id="inputtype_${id}" class="capa_inputtype" >
<div class="drag_and_drop_problem" id="drag_and_drop_div_${id}" <div class="drag_and_drop_problem" id="drag_and_drop_div_${id}"
style="width:${width};height:${height}"></div> style="width:${width};height:${height}"
data-template="${template}" data-images="${images}"></div>
<div class="script_placeholder" data-src="/static/js/raphael.js"></div> <div class="script_placeholder" data-src="/static/js/raphael.js"></div>
...@@ -15,7 +16,8 @@ ...@@ -15,7 +16,8 @@
% endif % endif
<input type="text" name="input_${id}" id="input_${id}" value="${value|h}" style="display:none;"/> <input type="text" name="input_${id}" id="input_${id}" value="${value|h}"
style="display:none;"/>
<p class="status"> <p class="status">
% if status == 'unsubmitted': % if status == 'unsubmitted':
......
...@@ -501,3 +501,43 @@ class ChemicalEquationTest(unittest.TestCase): ...@@ -501,3 +501,43 @@ class ChemicalEquationTest(unittest.TestCase):
} }
self.assertEqual(context, expected) 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 = """<drag_and_drop id="prob_1_2"
height="{h}"
width="{w}"
template="{t}"
images="{i}"
/>""".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)
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