Commit 9b640aa0 by Diana Huang

Add more documentation and fix naming.

parent 385a62d7
...@@ -335,16 +335,16 @@ class LoncapaProblem(object): ...@@ -335,16 +335,16 @@ class LoncapaProblem(object):
def handle_input_ajax(self, get): def handle_input_ajax(self, get):
''' '''
This passes any specialized input ajax onto the input class InputTypes can support specialized AJAX calls. Find the correct input and pass along the correct data
It also parses out the dispatch from the get so that it can be passed onto the input type nicely Also, parse out the dispatch from the get so that it can be passed onto the input type nicely
''' '''
# pull out the id # pull out the id
problem_id = get['problem_id'] input_id = get['input_id']
if self.inputs[problem_id]: if self.inputs[input_id]:
dispatch = get['dispatch'] dispatch = get['dispatch']
return self.inputs[problem_id].handle_ajax(dispatch, get) return self.inputs[input_id].handle_ajax(dispatch, get)
else: else:
log.warning("Could not find matching input for id: %s" % problem_id) log.warning("Could not find matching input for id: %s" % problem_id)
return {} return {}
...@@ -512,8 +512,9 @@ class LoncapaProblem(object): ...@@ -512,8 +512,9 @@ class LoncapaProblem(object):
msg = '' msg = ''
hint = '' hint = ''
hintmode = None hintmode = None
input_id = problemtree.get('id')
if problemid in self.correct_map: if problemid in self.correct_map:
pid = problemtree.get('id') pid = input_id
status = self.correct_map.get_correctness(pid) status = self.correct_map.get_correctness(pid)
msg = self.correct_map.get_msg(pid) msg = self.correct_map.get_msg(pid)
hint = self.correct_map.get_hint(pid) hint = self.correct_map.get_hint(pid)
...@@ -524,18 +525,17 @@ class LoncapaProblem(object): ...@@ -524,18 +525,17 @@ class LoncapaProblem(object):
value = self.student_answers[problemid] value = self.student_answers[problemid]
# do the rendering # do the rendering
state = {'value': value, state = {'value': value,
'status': status, 'status': status,
'id': problemtree.get('id'), 'id': input_id,
'feedback': {'message': msg, 'feedback': {'message': msg,
'hint': hint, 'hint': hint,
'hintmode': hintmode, }} 'hintmode': hintmode, }}
input_type_cls = inputtypes.registry.get_class_for_tag(problemtree.tag) input_type_cls = inputtypes.registry.get_class_for_tag(problemtree.tag)
# save the input type so that we can make ajax calls on it if we need to # save the input type so that we can make ajax calls on it if we need to
self.inputs[problemid] = input_type_cls(self.system, problemtree, state) self.inputs[input_id] = input_type_cls(self.system, problemtree, state)
return self.inputs[problemid].get_html() return self.inputs[input_id].get_html()
# let each Response render itself # let each Response render itself
if problemtree in self.responders: if problemtree in self.responders:
......
...@@ -224,7 +224,7 @@ class InputTypeBase(object): ...@@ -224,7 +224,7 @@ class InputTypeBase(object):
get: a dictionary containing the data that was sent with the ajax call get: a dictionary containing the data that was sent with the ajax call
Output: Output:
a dictionary object that will then get sent back to the Javascript a dictionary object that can be serialized into JSON. This will be sent back to the Javascript.
""" """
pass pass
......
...@@ -79,9 +79,18 @@ class @Problem ...@@ -79,9 +79,18 @@ class @Problem
# Use this if you want to make an ajax call on the input type object # Use this if you want to make an ajax call on the input type object
# static method so you don't have to instantiate a Problem in order to use it # static method so you don't have to instantiate a Problem in order to use it
@inputAjax: (url, problem_id, dispatch, data, callback) -> # Input:
# url: the AJAX url of the problem
# input_id: the input_id of the input you would like to make the call on
# NOTE: the id is the ${id} part of "input_${id}" during rendering
# If this function is passed the entire prefixed id, the backend may have trouble
# finding the correct input
# dispatch: string that indicates how this data should be handled by the inputtype
# callback: the function that will be called once the AJAX call has been completed.
# It will be passed a response object
@inputAjax: (url, input_id, dispatch, data, callback) ->
data['dispatch'] = dispatch data['dispatch'] = dispatch
data['problem_id'] = problem_id data['input_id'] = input_id
$.postWithPrefix "#{url}/input_ajax", data, callback $.postWithPrefix "#{url}/input_ajax", data, callback
......
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