Commit f4d68d77 by Diana Huang

Add Javascript for new button and fix Python backend issues

parent 8649d67b
......@@ -548,14 +548,11 @@ class LoncapaProblem(object):
if self.student_answers and problemid in self.student_answers:
value = self.student_answers[problemid]
if input_id not in self.input_state:
self.input_state[input_id] = {}
# do the rendering
state = {'value': value,
'status': status,
'id': input_id,
'input_state': self.input_state[input_id],
'input_state': self.input_state,
'feedback': {'message': msg,
'hint': hint,
'hintmode': hintmode, }}
......
......@@ -162,7 +162,7 @@ class InputTypeBase(object):
self.msg = feedback.get('message', '')
self.hint = feedback.get('hint', '')
self.hintmode = feedback.get('hintmode', None)
self.input_state = state.get('input_state', {})
self.input_state_dict = state.get('input_state', {})
# put hint above msg if it should be displayed
if self.hintmode == 'always':
......@@ -635,6 +635,11 @@ class MatlabInput(CodeInput):
'''
Handle matlab-specific parsing
'''
# if we don't have state for this input type yet, make one
if self.id not in self.input_state_dict:
self.input_state_dict[self.id] = {}
self.input_state = self.input_state_dict[self.id]
xml = self.xml
self.plot_payload = xml.findtext('./plot_payload')
# if no student input yet, then use the default input given by the
......@@ -647,10 +652,13 @@ class MatlabInput(CodeInput):
self.queuename = 'matlab'
# Flag indicating that the problem has been queued, 'msg' is length of
self.queue_msg = None
if 'queue_msg' in self.input_state:
self.queue_msg = self.input_state['queue_msg']
if 'queued' in self.input_state and self.input_state['queuestate'] is not None:
self.status = 'queued'
self.queue_len = 1
# queue
if self.status == 'incomplete':
if 'queue_msg' in self.input_state:
self.queue_msg = self.input_state['queue_msg']
self.status = 'queued'
self.queue_len = self.msg
self.msg = self.submitted_msg
......@@ -667,10 +675,11 @@ class MatlabInput(CodeInput):
# check the queuekey against the saved queuekey
if('queuestate' in self.input_state and self.input_state['queuestate'] == 'queued'
and self.input_state['queuekey'] == queuekey):
msg = _parse_message(queue_msg)
msg = self._parse_data(queue_msg)
# save the queue message so that it can be rendered later
self.input_state['queue_msg'] = msg
self.input_state['queued'] = 'dequeued'
self.input_state['queuestate'] = None
self.input_state['queuekey'] = None
def _extra_context(self):
''' Set up additional context variables'''
......@@ -733,8 +742,9 @@ class MatlabInput(CodeInput):
(error, msg) = qinterface.send_to_queue(header=xheader,
body = json.dumps(contents))
return json.dumps({'success': error != 0, 'message': msg})
return json.dumps({'success': False, 'message': 'Cannot connect to the queue'})
return {'success': error == 0, 'message': msg}
return {'success': False, 'message': 'Cannot connect to the queue'}
registry.register(MatlabInput)
......
......@@ -34,7 +34,7 @@
</div>
<div class="plot-button">
<input type="button" name="plot-button" value="Plot" />
<input type="button" class="save" name="plot-button" id="plot_${id}" value="Plot" />
</div>
<script>
......@@ -57,7 +57,50 @@
},
smartIndent: false
});
$("#textbox_${id}").find('.CodeMirror-scroll').height(${int(13.5*eval(rows))});
// hook up the plot button
var plot = function(event) {
url = $(this).closest('.problems-wrapper').data('url');
input_id = "${id}";
// save the codemirror text to the textarea
cm.save();
var input = $("#input_${id}");
// pull out the coded text
submission = input.val();
answer = input.serialize();
// setup callback for
var plot_callback = function(response) {
if(response.success) {
window.location.reload();
}
else {
// TODO: show message
}
}
var save_callback = function(response) {
if(response.success) {
Problem.inputAjax(url, input_id, 'plot',
{'submission': submission}, plot_callback);
}
else {
// TODO: show any messages
}
}
// save the answer
$.postWithPrefix(url + '/problem_save', answer, save_callback);
}
$('#plot_${id}').click(plot);
});
</script>
</section>
......@@ -20,7 +20,7 @@ def calledback_url(dispatch = 'score_update'):
return dispatch
xqueue_interface = MagicMock()
xqueue_interface.send_to_queue.return_value = (1, 'Success!')
xqueue_interface.send_to_queue.return_value = (0, 'Success!')
test_system = Mock(
ajax_url='courses/course_id/modx/a_location',
......
......@@ -357,7 +357,7 @@ class MatlabTest(unittest.TestCase):
def test_rendering_with_state(self):
state = {'value': 'print "good evening"',
'status': 'incomplete',
'input_state': {'queue_msg': 'message'},
'input_state': {'prob_1_2': {'queue_msg': 'message'}},
'feedback': {'message': '3'}, }
elt = etree.fromstring(self.xml)
......@@ -383,7 +383,7 @@ class MatlabTest(unittest.TestCase):
def test_plot_data(self):
get = {'submission': 'x = 1234;'}
response = json.loads(self.the_input.handle_ajax("plot", get))
response = self.the_input.handle_ajax("plot", get)
test_system.xqueue['interface'].send_to_queue.assert_called_with(header=ANY, body=ANY)
......
......@@ -460,6 +460,7 @@ class CapaModule(CapaFields, XModule):
'progress_changed': after != before,
'progress_status': Progress.to_js_status_str(after),
})
self.set_state_from_lcp()
return json.dumps(d, cls=ComplexEncoder)
def is_past_due(self):
......@@ -549,8 +550,8 @@ class CapaModule(CapaFields, XModule):
score_msg = get['xqueue_body']
# pass along the xqueue message to the problem
self.lcp.ungraded_response(score_msg, queuekey)
self.set_state_from_lcp()
return dict()
def get_answer(self, get):
'''
......
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