def test_to_js_status(self): '''Test the Progress.to_js_status_str() method''' self.assertEqual(Progress.to_js_status_str(self.not_started), "none") self.assertEqual(Progress.to_js_status_str(self.half_done), "in_progress") self.assertEqual(Progress.to_js_status_str(self.done), "done") self.assertEqual(Progress.to_js_status_str(None), "0")
def handle_ajax(self, dispatch, data, system): ''' This is called by courseware.module_render, to handle an AJAX call. "data" is request.POST. Returns a json dictionary: { 'progress_changed' : True/False, 'progress' : 'none'/'in_progress'/'done', <other request-specific values here > } ''' handlers = { 'save_answer': self.save_answer, 'score_update': self.update_score, 'save_post_assessment': self.message_post, 'skip_post_assessment': self.skip_post_assessment, 'check_for_score': self.check_for_score, 'store_answer': self.store_answer, } _ = self.system.service(self, "i18n").ugettext if dispatch not in handlers: # This is a dev_facing_error log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch)) # This is a dev_facing_error return json.dumps( {'error': _('Error handling action. Please try again.'), 'success': False} ) before = self.get_progress() d = handlers[dispatch](data, system) after = self.get_progress() d.update({ 'progress_changed': after != before, 'progress_status': Progress.to_js_status_str(after), }) return json.dumps(d, cls=ComplexEncoder)
def handle_ajax(self, dispatch, data, system): ''' This is called by courseware.module_render, to handle an AJAX call. "data" is request.POST. Returns a json dictionary: { 'progress_changed' : True/False, 'progress' : 'none'/'in_progress'/'done', <other request-specific values here > } ''' handlers = { 'save_answer': self.save_answer, 'score_update': self.update_score, 'save_post_assessment': self.message_post, 'skip_post_assessment': self.skip_post_assessment, 'check_for_score': self.check_for_score, } if dispatch not in handlers: # This is a dev_facing_error log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch)) # This is a dev_facing_error return json.dumps({'error': 'Error handling action. Please try again.', 'success': False}) before = self.get_progress() d = handlers[dispatch](data, system) after = self.get_progress() d.update({ 'progress_changed': after != before, 'progress_status': Progress.to_js_status_str(after), }) return json.dumps(d, cls=ComplexEncoder)
def handle_ajax(self, dispatch, data, system): """ This is called by courseware.module_render, to handle an AJAX call. "data" is request.POST. Returns a json dictionary: { 'progress_changed' : True/False, 'progress' : 'none'/'in_progress'/'done', <other request-specific values here > } """ handlers = { "save_answer": self.save_answer, "score_update": self.update_score, "save_post_assessment": self.message_post, "skip_post_assessment": self.skip_post_assessment, "check_for_score": self.check_for_score, } if dispatch not in handlers: # This is a dev_facing_error log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch)) # This is a dev_facing_error return json.dumps({"error": "Error handling action. Please try again.", "success": False}) before = self.get_progress() d = handlers[dispatch](data, system) after = self.get_progress() d.update({"progress_changed": after != before, "progress_status": Progress.to_js_status_str(after)}) return json.dumps(d, cls=ComplexEncoder)
def handle_ajax(self, dispatch, data, system): """ This is called by courseware.module_render, to handle an AJAX call. "data" is request.POST. Returns a json dictionary: { 'progress_changed' : True/False, 'progress': 'none'/'in_progress'/'done', <other request-specific values here > } """ handlers = { 'save_answer': self.save_answer, 'save_text': self.save_text, 'save_assessment': self.save_assessment, 'save_post_assessment': self.save_hint, 'remove_file': self.remove_file } if dispatch not in handlers: # This is a dev_facing_error log.error("Cannot find {0} in handlers in handle_ajax function for open_ended_module.py".format(dispatch)) # This is a dev_facing_error return json.dumps({'error': 'Error handling action. Please try again.', 'success': False}) before = self.get_progress() d = handlers[dispatch](data, system) after = self.get_progress() d.update({ 'progress_changed': after != before, 'progress_status': Progress.to_js_status_str(after), }) return json.dumps(d, cls=ComplexEncoder)
def student_view(self, context): # If we're rendering this sequence, but no position is set yet, # default the position to the first element if self.position is None: self.position = 1 ## Returns a set of all types of all sub-children contents = [] fragment = Fragment() for child in self.get_display_items(): progress = child.get_progress() rendered_child = child.render('student_view', context) fragment.add_frag_resources(rendered_child) childinfo = { 'content': rendered_child.content, 'title': "\n".join(grand_child.display_name for grand_child in child.get_children() if grand_child.display_name is not None), 'progress_status': Progress.to_js_status_str(progress), 'progress_detail': Progress.to_js_detail_str(progress), 'type': child.get_icon_class(), 'id': child.id, } if childinfo['title'] == '': childinfo['title'] = child.display_name_with_default contents.append(childinfo) params = { 'items': contents, 'element_id': self.location.html_id(), 'item_id': self.id, 'position': self.position, 'tag': self.location.category, 'ajax_url': self.system.ajax_url, } fragment.add_content( self.system.render_template('seq_module.html', params)) return fragment
def student_view(self, context): # If we're rendering this sequence, but no position is set yet, # default the position to the first element if self.position is None: self.position = 1 ## Returns a set of all types of all sub-children contents = [] fragment = Fragment() for child in self.get_display_items(): progress = child.get_progress() rendered_child = child.render("student_view", context) fragment.add_frag_resources(rendered_child) childinfo = { "content": rendered_child.content, "title": "\n".join( grand_child.display_name for grand_child in child.get_children() if grand_child.display_name is not None ), "progress_status": Progress.to_js_status_str(progress), "progress_detail": Progress.to_js_detail_str(progress), "type": child.get_icon_class(), "id": child.id, } if childinfo["title"] == "": childinfo["title"] = child.display_name_with_default contents.append(childinfo) params = { "items": contents, "element_id": self.location.html_id(), "item_id": self.id, "position": self.position, "tag": self.location.category, "ajax_url": self.system.ajax_url, } fragment.add_content(self.system.render_template("seq_module.html", params)) return fragment
def student_view(self, context): # If we're rendering this sequence, but no position is set yet, # default the position to the first element if self.position is None: self.position = 1 ## Returns a set of all types of all sub-children contents = [] fragment = Fragment() for child in self.get_display_items(): progress = child.get_progress() rendered_child = child.render('student_view', context) fragment.add_frag_resources(rendered_child) childinfo = { 'content': rendered_child.content, 'title': "\n".join( grand_child.display_name for grand_child in child.get_children() if grand_child.display_name is not None ), 'progress_status': Progress.to_js_status_str(progress), 'progress_detail': Progress.to_js_detail_str(progress), 'type': child.get_icon_class(), 'id': child.id, } if childinfo['title'] == '': childinfo['title'] = child.display_name_with_default contents.append(childinfo) params = {'items': contents, 'element_id': self.location.html_id(), 'item_id': self.id, 'position': self.position, 'tag': self.location.category, 'ajax_url': self.system.ajax_url, } fragment.add_content(self.system.render_template('seq_module.html', params)) return fragment
def render(self): # If we're rendering this sequence, but no position is set yet, # default the position to the first element if self.position is None: self.position = 1 if self.rendered: return ## Returns a set of all types of all sub-children contents = [] for child in self.get_display_items(): progress = child.get_progress() childinfo = { 'content': self.runtime.render_child(child, None, 'student_view').content, 'title': "\n".join(grand_child.display_name for grand_child in child.get_children() if grand_child.display_name is not None), 'progress_status': Progress.to_js_status_str(progress), 'progress_detail': Progress.to_js_detail_str(progress), 'type': child.get_icon_class(), 'id': child.id, } if childinfo['title'] == '': childinfo['title'] = child.display_name_with_default contents.append(childinfo) params = { 'items': contents, 'element_id': self.location.html_id(), 'item_id': self.id, 'position': self.position, 'tag': self.location.category } self.content = self.system.render_template('seq_module.html', params) self.rendered = True
def render(self): # If we're rendering this sequence, but no position is set yet, # default the position to the first element if self.position is None: self.position = 1 if self.rendered: return ## Returns a set of all types of all sub-children contents = [] for child in self.get_display_items(): progress = child.get_progress() childinfo = { 'content': child.get_html(), 'title': "\n".join( grand_child.display_name for grand_child in child.get_children() if grand_child.display_name is not None ), 'progress_status': Progress.to_js_status_str(progress), 'progress_detail': Progress.to_js_detail_str(progress), 'type': child.get_icon_class(), 'id': child.id, 'direct_term': child.direct_term_with_default } if childinfo['title'] == '': childinfo['title'] = child.display_name_with_default contents.append(childinfo) params = {'items': contents, 'element_id': self.location.html_id(), 'item_id': self.id, 'position': self.position, 'tag': self.location.category } self.content = self.system.render_template('seq_module.html', params) self.rendered = True
def render(self): # If we're rendering this sequence, but no position is set yet, # default the position to the first element if self.position is None: self.position = 1 if self.rendered: return ## Returns a set of all types of all sub-children contents = [] for child in self.get_display_items(): progress = child.get_progress() childinfo = { "content": child.get_html(), "title": "\n".join( grand_child.display_name for grand_child in child.get_children() if grand_child.display_name is not None ), "progress_status": Progress.to_js_status_str(progress), "progress_detail": Progress.to_js_detail_str(progress), "type": child.get_icon_class(), "id": child.id, } if childinfo["title"] == "": childinfo["title"] = child.display_name_with_default contents.append(childinfo) params = { "items": contents, "element_id": self.location.html_id(), "item_id": self.id, "position": self.position, "tag": self.location.category, } self.content = self.system.render_template("seq_module.html", params) self.rendered = True