def rollup_header_footer(self, context): """Include markdown css only when markdown tag is present.""" header = tags.html_string_to_element_tree( '<link href="{}css/markdown.css" rel="stylesheet">'.format( _STATIC_URL)) footer = tags.html_string_to_element_tree('') return (header, footer)
def rollup_header_footer(self, context): """Include markdown css only when markdown tag is present.""" header = tags.html_string_to_element_tree( '<link href="%s/markdown.css" rel="stylesheet" ' 'type="text/css">' % RESOURCE_FOLDER) footer = tags.html_string_to_element_tree('') return (header, footer)
def rollup_header_footer(self, context): """Include markdown css only when markdown tag is present.""" header = tags.html_string_to_element_tree( '<link href="%s/markdown.css" rel="stylesheet" ' 'type="text/css">' % RESOURCE_FOLDER) footer = tags.html_string_to_element_tree('') return (header, footer)
def rollup_header_footer(self, context): """Include markdown css only when markdown tag is present.""" header = tags.html_string_to_element_tree( '<link href="{}/css/markdown.css" rel="stylesheet">'.format( _STATIC_URL)) footer = tags.html_string_to_element_tree('') return (header, footer)
def rollup_header_footer(self, context): """Include MathJax library only when a math tag is present.""" header = tags.html_string_to_element_tree(""" <script src="%s/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>""" % MATHJAX_URI) footer = tags.html_string_to_element_tree('') return (header, footer)
def rollup_header_footer(self, context): """Include CodeMirror library only when a code tag is present.""" header = tags.html_string_to_element_tree( '<script src="%s/lib/codemirror.js"></script>' '<link rel="stylesheet" href="%s/lib/codemirror.css">' '<script src="%s/addon/mode/loadmode.js"></script>' '<link rel="stylesheet" href="%s/code_tags.css">' % ( CODEMIRROR_URI, CODEMIRROR_URI, CODEMIRROR_URI, CODETAGS_RESOURCES_URI)) footer = tags.html_string_to_element_tree( '<script src="%s/code_tags.js">' '</script>' % CODETAGS_RESOURCES_URI) return (header, footer)
def rollup_header_footer(self, context): """Include CodeMirror library only when a code tag is present.""" header = tags.html_string_to_element_tree( '<script src="%s/lib/codemirror.js"></script>' '<link rel="stylesheet" href="%s/lib/codemirror.css">' '<script src="%s/addon/mode/loadmode.js"></script>' '<link rel="stylesheet" href="%s/code_tags.css">' % (CODEMIRROR_URI, CODEMIRROR_URI, CODEMIRROR_URI, CODETAGS_RESOURCES_URI)) footer = tags.html_string_to_element_tree( '<script src="%s/code_tags.js">' '</script>' % CODETAGS_RESOURCES_URI) return (header, footer)
def render(self, node, handler): instanceid = node.attrib.get('instanceid') template_values = { 'RESOURCES_PATH': RESOURCES_PATH, 'exploration_id': node.attrib.get('exploration_id'), 'instanceid': instanceid, 'src': node.attrib.get('src'), } cpt_progress = None if (hasattr(handler, 'student') and not handler.student.is_transient and not handler.lesson_is_scored): cpt_progress = handler.get_course().get_progress_tracker( ).get_component_progress( handler.student, handler.unit_id, handler.lesson_id, instanceid) template_values['progress'] = cpt_progress locale = handler.app_context.get_environ()['course']['locale'] template = jinja_utils.get_template( 'templates/oppia_template.html', [os.path.dirname(__file__)], locale=locale) html_string = jinja2.utils.Markup(template.render(template_values)) return tags.html_string_to_element_tree(html_string)
def render(self, node, context): """Renders the submit button.""" xsrf_token = XsrfTokenManager.create_xsrf_token( QUESTIONNAIRE_XSRF_TOKEN_NAME) form_id = node.attrib.get('form-id') button_label = node.attrib.get('button-label') disabled = (node.attrib.get('disabled') == 'true') post_message = node.text user = context.handler.get_user() registered = False if user and models.Student.get_enrolled_student_by_user(user): registered = True template_vals = { 'xsrf_token': xsrf_token, 'form_id': form_id, 'button_label': button_label, 'disabled': disabled, 'registered': registered, 'post_message': post_message, } template = jinja_utils.get_template( 'questionnaire.html', [TEMPLATES_DIR]) button = template.render(template_vals) return tags.html_string_to_element_tree(button)
def get_assement_objects(html_string): """Get assessment objects.""" if not html_string: return None node_list = dict() def _process_object_tree(elt, used_instance_ids): if elt.tag == q_tags.QuestionTag.binding_name: return get_question_object(elt) elif elt.tag == q_tags.QuestionGroupTag.binding_name: return get_question_group_object(elt) return None def _parse_html_node(elt, used_instance_ids, node_list): for child in elt: _parse_html_node(child, used_instance_ids, node_list) if 'instanceid' not in elt.attrib: return instance_id = elt.attrib['instanceid'] if instance_id in used_instance_ids: return used_instance_ids.add(instance_id) node = _process_object_tree(elt, used_instance_ids) if node: node_list[instance_id] = node root = tags.html_string_to_element_tree(html_string) used_instance_ids = set([]) for elt in root: _parse_html_node(elt, used_instance_ids, node_list) return node_list
def render(self, node, handler): """Renders the custom tag.""" student = handler.personalize_page_and_get_enrolled( supports_transient_student=True) template = jinja_utils.get_template( 'templates/form.html', os.path.dirname(__file__), locale=handler.app_context.get_environ()['course']['locale'], ) already_submitted = False if not isinstance(student, models.TransientStudent): already_submitted = bool( db.get(student_work.Submission.get_key( handler.unit_id, student.get_key()))) handler.template_value['action'] = self._get_action( handler.app_context.get_slug()) handler.template_value['already_submitted'] = already_submitted handler.template_value['display_length'] = node.attrib.get( 'display_length') handler.template_value['form_xsrf_token'] = ( utils.XsrfTokenManager.create_xsrf_token( _XSRF_TOKEN_NAME)) handler.template_value['unit_id'] = handler.unit_id return tags.html_string_to_element_tree( jinja2.utils.Markup(template.render(handler.template_value)) )
def render(self, node, handler): instanceid = node.attrib.get('instanceid') template_values = { 'RESOURCES_PATH': RESOURCES_PATH, 'exploration_id': node.attrib.get('exploration_id'), 'instanceid': instanceid, 'src': node.attrib.get('src'), } cpt_progress = None if (hasattr(handler, 'student') and not handler.student.is_transient and not handler.lesson_is_scored): cpt_progress = handler.get_course().get_progress_tracker( ).get_component_progress(handler.student, handler.unit_id, handler.lesson_id, instanceid) template_values['progress'] = cpt_progress locale = handler.app_context.get_environ()['course']['locale'] template = jinja_utils.get_template('templates/oppia_template.html', [os.path.dirname(__file__)], locale=locale) html_string = jinja2.utils.Markup(template.render(template_values)) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): """Renders a question.""" locale = handler.app_context.get_environ()['course']['locale'] quid = node.attrib.get('quid') try: weight = float(node.attrib.get('weight')) except TypeError: weight = 1.0 instanceid = node.attrib.get('instanceid') progress = None if hasattr(handler, 'student') and not handler.student.is_transient: progress = handler.get_course().get_progress_tracker( ).get_component_progress(handler.student, handler.unit_id, handler.lesson_id, instanceid) html_string = render_question(quid, instanceid, locale, embedded=False, weight=weight, progress=progress) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): """Renders the custom tag.""" student = handler.personalize_page_and_get_enrolled( supports_transient_student=True) template = jinja_utils.get_template('templates/form.html', os.path.dirname(__file__)) already_submitted = False if not isinstance(student, models.TransientStudent): already_submitted = bool( db.get( student_work.Submission.get_key(handler.unit_id, student.get_key()))) handler.template_value['action'] = self._get_action( handler.app_context.get_slug()) handler.template_value['already_submitted'] = already_submitted handler.template_value['display_length'] = node.attrib.get( 'display_length') handler.template_value['form_xsrf_token'] = ( utils.XsrfTokenManager.create_xsrf_token(_XSRF_TOKEN_NAME)) handler.template_value['unit_id'] = handler.unit_id return tags.html_string_to_element_tree( jinja2.utils.Markup(template.render(handler.template_value)))
def render(self, node, handler): """Renders the custom tag.""" student = handler.personalize_page_and_get_enrolled( supports_transient_student=True) enabled = ( not isinstance(student, models.TransientStudent) and hasattr(handler, 'unit_id')) template_value = {} template_value['enabled'] = enabled template = jinja_utils.get_template( 'templates/form.html', os.path.dirname(__file__)) already_submitted = False if enabled: instance_id = node.attrib.get('instanceid') already_submitted = bool( student_work.Submission.get( handler.unit_id, student.get_key(), instance_id=instance_id)) template_value['unit_id'] = handler.unit_id template_value['instance_id'] = instance_id template_value['action'] = self._get_action( handler.app_context.get_slug()) template_value['already_submitted'] = already_submitted template_value['display_length'] = node.attrib.get( 'display_length') template_value['form_xsrf_token'] = ( utils.XsrfTokenManager.create_xsrf_token(_XSRF_TOKEN_NAME)) return tags.html_string_to_element_tree( jinja2.utils.Markup(template.render(template_value)) )
def render(self, node, context): # The markdown is "text" type in the schema and so is presented in the # tag's body. html = '' if node.text: html = markdown.markdown(node.text) return tags.html_string_to_element_tree( '<div class="gcb-markdown">%s</div>' % html)
def render(self, node, context): # The markdown is "text" type in the schema and so is presented in the # tag's body. html = '' if node.text: html = markdown.markdown(node.text) return tags.html_string_to_element_tree( '<div class="gcb-markdown">%s</div>' % html)
def render(self, node, context): # The markdown is "text" type in the schema and so is presented in the # tag's body. extension_list = node.attrib.get('extension', '').split() html = '' if node.text: html = markdown.markdown(node.text, extension_list) return tags.html_string_to_element_tree( '<div class="gcb-markdown">%s</div>' % html)
def render(self, node, context): # The markdown is "text" type in the schema and so is presented in the # tag's body. extension_list = node.attrib.get('extension', '').split() html = '' if node.text: html = markdown.markdown(node.text, extension_list) return tags.html_string_to_element_tree( '<div class="gcb-markdown">%s</div>' % html)
def render(self, node, handler): """Renders a question.""" locale = handler.app_context.get_environ()['course']['locale'] qgid = node.attrib.get('qgid') group_instanceid = node.attrib.get('instanceid') question_group_dto = m_models.QuestionGroupDAO.load(qgid) if not question_group_dto: return tags.html_string_to_element_tree('[Deleted question group]') template_values = question_group_dto.dict template_values['embedded'] = False template_values['instanceid'] = group_instanceid template_values['resources_path'] = RESOURCES_PATH if (hasattr(handler, 'student') and not handler.student.is_transient and not handler.lesson_is_scored): progress = handler.get_course().get_progress_tracker( ).get_component_progress(handler.student, handler.unit_id, handler.lesson_id, group_instanceid) template_values['progress'] = progress template_values['question_html_array'] = [] js_data = {} for ind, item in enumerate(question_group_dto.dict['items']): quid = item['question'] question_instanceid = '%s.%s.%s' % (group_instanceid, ind, quid) template_values['question_html_array'].append( render_question(quid, question_instanceid, locale, weight=item['weight'], embedded=True)) js_data[question_instanceid] = item template_values['js_data'] = transforms.dumps(js_data) template_file = 'templates/question_group.html' template = jinja_utils.get_template(template_file, [os.path.dirname(__file__)], locale=locale) html_string = template.render(template_values) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): """Renders a question.""" locale = handler.app_context.get_environ()['course']['locale'] qgid = node.attrib.get('qgid') group_instanceid = node.attrib.get('instanceid') question_group_dto = m_models.QuestionGroupDAO.load(qgid) if not question_group_dto: return tags.html_string_to_element_tree('[Deleted question group]') template_values = question_group_dto.dict template_values['embedded'] = False template_values['instanceid'] = group_instanceid template_values['resources_path'] = RESOURCES_PATH if (hasattr(handler, 'student') and not handler.student.is_transient and not handler.lesson_is_scored): progress = handler.get_course().get_progress_tracker( ).get_component_progress( handler.student, handler.unit_id, handler.lesson_id, group_instanceid) template_values['progress'] = progress template_values['question_html_array'] = [] js_data = {} for ind, item in enumerate(question_group_dto.dict['items']): quid = item['question'] question_instanceid = '%s.%s.%s' % (group_instanceid, ind, quid) template_values['question_html_array'].append(render_question( quid, question_instanceid, locale, weight=item['weight'], embedded=True )) js_data[question_instanceid] = item template_values['js_data'] = transforms.dumps(js_data) template_file = 'templates/question_group.html' template = jinja_utils.get_template( template_file, [os.path.dirname(__file__)], locale=locale) html_string = template.render(template_values) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): """Renders a question.""" locale = handler.app_context.get_environ()["course"]["locale"] qgid = node.attrib.get("qgid") group_instanceid = node.attrib.get("instanceid") question_group_dto = m_models.QuestionGroupDAO.load(qgid) if not question_group_dto: return tags.html_string_to_element_tree("[Deleted question group]") template_values = question_group_dto.dict template_values["embedded"] = False template_values["instanceid"] = group_instanceid template_values["resources_path"] = RESOURCES_PATH if hasattr(handler, "student") and not handler.student.is_transient and not handler.lesson_is_scored: progress = ( handler.get_course() .get_progress_tracker() .get_component_progress(handler.student, handler.unit_id, handler.lesson_id, group_instanceid) ) template_values["progress"] = progress template_values["question_html_array"] = [] js_data = {} for ind, item in enumerate(question_group_dto.dict["items"]): quid = item["question"] question_instanceid = "%s.%s.%s" % (group_instanceid, ind, quid) template_values["question_html_array"].append( render_question(quid, question_instanceid, locale, weight=item["weight"], embedded=True) ) js_data[question_instanceid] = item template_values["js_data"] = transforms.dumps(js_data) template_file = "templates/question_group.html" template = jinja_utils.get_template(template_file, [os.path.dirname(__file__)], locale=locale) html_string = template.render(template_values) return tags.html_string_to_element_tree(html_string)
def rollup_header_footer(self, context): """Include CodeMirror library only when a code tag is present.""" if oeditor.CAN_HIGHLIGHT_CODE.value: header = tags.html_string_to_element_tree( '<script src="%s/lib/codemirror.js"></script>' '<link rel="stylesheet" href="%s/lib/codemirror.css">' '<script src="%s/addon/mode/loadmode.js"></script>' '<link rel="stylesheet" href="%s/code_tags.css">' % ( CODEMIRROR_URI, CODEMIRROR_URI, CODEMIRROR_URI, CODETAGS_RESOURCES_URI)) footer = tags.html_string_to_element_tree( '<script src="%s/code_tags.js">' '</script>' % CODETAGS_RESOURCES_URI) else: header = cElementTree.Element('link') header.attrib['rel'] = 'stylesheet' header.attrib['href'] = '%s/code_tags_no_highlight.css' % ( CODETAGS_RESOURCES_URI) footer = cElementTree.Comment('Empty footer') return (header, footer)
def rollup_header_footer(self, context): """Include CodeMirror library only when a code tag is present.""" if oeditor.CAN_HIGHLIGHT_CODE.value: header = tags.html_string_to_element_tree( '<script src="%s/lib/codemirror.js"></script>' '<link rel="stylesheet" href="%s/lib/codemirror.css">' '<script src="%s/addon/mode/loadmode.js"></script>' '<link rel="stylesheet" href="%s/code_tags.css">' % (CODEMIRROR_URI, CODEMIRROR_URI, CODEMIRROR_URI, CODETAGS_RESOURCES_URI)) footer = tags.html_string_to_element_tree( '<script src="%s/code_tags.js">' '</script>' % CODETAGS_RESOURCES_URI) else: header = cElementTree.Element('link') header.attrib['rel'] = 'stylesheet' header.attrib['href'] = '%s/code_tags_no_highlight.css' % ( CODETAGS_RESOURCES_URI) footer = cElementTree.Comment('Empty footer') return (header, footer)
def render(self, node, handler): template_path = re.sub('^/+', '', node.attrib.get('path')) base_path = os.path.dirname(template_path) base_file = os.path.basename(template_path) handler.init_template_values(handler.app_context.get_environ()) handler.template_value['base_path'] = base_path html_text = handler.render_template_to_html( handler.template_value, base_file, additional_dirs=[ os.path.join(appengine_config.BUNDLE_ROOT, 'views'), appengine_config.BUNDLE_ROOT, os.path.join(appengine_config.BUNDLE_ROOT, base_path), ]) return tags.html_string_to_element_tree(html_text)
def render(self, node, handler): template_path = re.sub('^/+', '', node.attrib.get('path')) base_path = os.path.dirname(template_path) base_file = os.path.basename(template_path) handler.init_template_values(handler.app_context.get_environ()) handler.template_value['base_path'] = base_path html_text = handler.render_template_to_html( handler.template_value, base_file, additional_dirs=[ os.path.join(appengine_config.BUNDLE_ROOT, 'views'), appengine_config.BUNDLE_ROOT, os.path.join(appengine_config.BUNDLE_ROOT, base_path), ]) return tags.html_string_to_element_tree(html_text)
def render(self, node, handler): """Renders a question.""" locale = handler.app_context.get_environ()["course"]["locale"] quid = node.attrib.get("quid") weight = node.attrib.get("weight") instanceid = node.attrib.get("instanceid") progress = None if hasattr(handler, "student") and not handler.student.is_transient and not handler.lesson_is_scored: progress = ( handler.get_course() .get_progress_tracker() .get_component_progress(handler.student, handler.unit_id, handler.lesson_id, instanceid) ) html_string = render_question(quid, instanceid, locale, embedded=False, weight=weight, progress=progress) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): """Renders a question.""" quid = node.attrib.get('quid') weight = node.attrib.get('weight') instanceid = node.attrib.get('instanceid') progress = None if (hasattr(handler, 'student') and not handler.student.is_transient and not handler.lesson_is_scored): progress = handler.get_course().get_progress_tracker( ).get_component_progress( handler.student, handler.unit_id, handler.lesson_id, instanceid) html_string = render_question( quid, instanceid, embedded=False, weight=weight, progress=progress) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): """Renders a question.""" quid = node.attrib.get('quid') weight = node.attrib.get('weight') instanceid = node.attrib.get('instanceid') progress = None if (hasattr(handler, 'student') and not handler.student.is_transient and not handler.lesson_is_scored): progress = handler.get_course().get_progress_tracker( ).get_component_progress( handler.student, handler.unit_id, handler.lesson_id, instanceid) html_string = render_question( quid, instanceid, embedded=False, weight=weight, progress=progress) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): """Renders a question.""" locale = handler.app_context.get_environ()['course']['locale'] quid = node.attrib.get('quid') try: weight = float(node.attrib.get('weight')) except TypeError: weight = 1.0 instanceid = node.attrib.get('instanceid') progress = None if hasattr(handler, 'student') and not handler.student.is_transient: progress = handler.get_course().get_progress_tracker( ).get_component_progress( handler.student, handler.unit_id, handler.lesson_id, instanceid) html_string = render_question( quid, instanceid, locale, embedded=False, weight=weight, progress=progress) return tags.html_string_to_element_tree(html_string)
def render(self, node, handler): # Get the context and the Quizly question data student = handler.student unitid = handler.unit_id lessonid = handler.lesson_id quizname = node.attrib.get('quizname') instanceid = node.attrib.get('instanceid') preamble = node.attrib.get('preamble') preamble = urllib2.quote(preamble) id_iconholder = 'icon-holder-' + quizname # Div where icon goes in HTML doc if not student.is_transient: logging.info('RAM: *** QUIZLY render: student=%s unit=%s lesson=%s instance=%s quiz=%s', student.email,unitid, lessonid, instanceid, quizname) # Creates a record of quiz on window.quizlies. script = '' script += '<script>' script += 'if (!window.quizlies) {window.quizlies={};}' script += 'var quiz = {};' script += 'quiz.name="' + quizname + '";' script += 'quiz.id="' + instanceid + '";' script += 'window.quizlies["' + quizname + '"]= quiz;' # script += 'console.log("instanceid="' + instanceid + '"");' # syntax error here script += '</script>' # View attributes height = node.attrib.get('height') or '595' width = node.attrib.get('width') or '755' hasanswerbox = node.attrib.get('hasanswerbox') or 'false' isrepeatable = node.attrib.get('isrepeatable') or 'false' hashints = node.attrib.get('hints') or 'true' # Source of the iframe that will be loaded for this quiz src = 'assets/lib/quizly/gcb-index.html?backpack=hidden&selector=hidden&quizname=' + quizname if preamble: src += '&heading=' + preamble src += '&hints=' + hashints src += '&repeatable=' + isrepeatable # Has this question already been completed, in-progress, or not-started? progress_tracker = handler.get_course().get_progress_tracker() status = 0 if not student.is_transient: student_progress = progress_tracker.get_or_create_progress(student) status = progress_tracker.get_component_status(unitid, lessonid,instanceid,student) # Handler for the checkAnswer button. Quizly puts the quizName and result # on window.parent.quizlies and this script reads it from there. # NOTE: gcbAudit() is in activity-generic.js. For this to work, 'quizly' has to be # added to TRACKABLE_COMPONENTS in models/progress.py script += '<script>function updateQuizlyProgressIcon(id, score) { ' script += ' var qname = window.quizlies.quizname;' script += ' var iframes = document.getElementsByTagName(\'iframe\');' script += ' var iconholder = \'\';' script += ' var innerHtml = \'\';' script += ' if (score >= 1) ' script += ' innerHtml = \'<img alt="Completed" class="gcb-progress-icon" src="assets/img/completed.png" title="Completed">\';' script += ' else' script += ' innerHtml = \'<img alt="In_progress" class="gcb-progress-icon" src="assets/img/in_progress.png" title="In progress">\';' script += ' for (var i=0; i < iframes.length; i++) { ' script += ' var iframe = iframes[i];' script += ' if (iframe.src.indexOf(qname) != -1) { ' script += ' iconholder = iframe.previousSibling.previousSibling;' script += ' break;' script += ' }' script += ' }' script += ' if (iconholder != \'\') ' script += ' iconholder.innerHTML = innerHtml;' script += '}' script += '</script>' script += '<script> function checkAnswer(){ ' script += 'var quizName = window.quizlies["quizname"];' script += 'var instanceid = window.quizlies[quizName].id;' script += 'var result = window.quizlies[quizName].result;' script += 'var score = (result) ? 1 : 0;' script += 'console.log("RAM (quizly.py): That solution was " + result);' script += 'if (gcbCanRecordStudentEvents) {' script += 'console.log("RAM (quizly.py): POSTing to server");' script += 'console.log("RAM (quizly.py): instanceid=" + instanceid);' script += 'var auditDict = {' script += '\'instanceid\': instanceid,' script += '\'answer\': result,' script += '\'score\': score,' script += '\'type\': "SaQuestion",' script += '};' script += 'gcbAudit(gcbCanRecordStudentEvents, auditDict, "tag-assessment", true);' script += '}' script += ' updateQuizlyProgressIcon(instanceid, score);' script += '}' script += '</script>'; returnStr = '' returnStr += script # Add the box-surrounded iframe that will hold the quiz. Blockly will be a frame w/in this frame. returnStr += '<div style="border: 1px solid black; margin: 5px; padding: 5px;">' returnStr += '<div id="' + id_iconholder + '" class="gcb-progress-icon-holder gcb-pull-right">' pointsdiv = '<div class="qt-points"><em>1 point </em></div>' # returnStr += pointsdiv progress_img = '' if status == 0: progress_img += '<img src="assets/img/not_started.png" />' elif status == 1: progress_img += '<img src="assets/img/in_progress.png" />' else: progress_img += '<img src="assets/img/completed.png" />' returnStr += progress_img returnStr += '</div>' returnStr += pointsdiv returnStr += '<iframe style= "border: 0px; margin: 1px; padding: 1px;" src=' + src + ' width="' + width + '" height="' + height + '">' returnStr += '</iframe>' returnStr += '</div>' return tags.html_string_to_element_tree(returnStr)
def render(self, node, handler): # Get the context and the Quizly question data student = handler.student unitid = handler.unit_id lessonid = handler.lesson_id quizname = node.attrib.get('quizname') instanceid = node.attrib.get('instanceid') preamble = node.attrib.get('preamble') preamble = urllib2.quote(preamble) id_iconholder = 'icon-holder-' + quizname # Div where icon goes in HTML doc if not student.is_transient: logging.info( 'RAM: *** QUIZLY render: student=%s unit=%s lesson=%s instance=%s quiz=%s', student.email, unitid, lessonid, instanceid, quizname) # Creates a record of quiz on window.quizlies. script = '' script += '<script>' script += 'if (!window.quizlies) {window.quizlies={};}' script += 'var quiz = {};' script += 'quiz.name="' + quizname + '";' script += 'quiz.id="' + instanceid + '";' script += 'window.quizlies["' + quizname + '"]= quiz;' # script += 'console.log("instanceid="' + instanceid + '"");' # syntax error here script += '</script>' # View attributes height = node.attrib.get('height') or '595' width = node.attrib.get('width') or '755' hasanswerbox = node.attrib.get('hasanswerbox') or 'false' isrepeatable = node.attrib.get('isrepeatable') or 'false' hashints = node.attrib.get('hints') or 'true' # Source of the iframe that will be loaded for this quiz src = 'assets/lib/quizly/gcb-index.html?backpack=hidden&selector=hidden&quizname=' + quizname if preamble: src += '&heading=' + preamble src += '&hints=' + hashints src += '&repeatable=' + isrepeatable # Has this question already been completed, in-progress, or not-started? progress_tracker = handler.get_course().get_progress_tracker() status = 0 if not student.is_transient: student_progress = progress_tracker.get_or_create_progress(student) status = progress_tracker.get_component_status( unitid, lessonid, instanceid, student) # Handler for the checkAnswer button. Quizly puts the quizName and result # on window.parent.quizlies and this script reads it from there. # NOTE: gcbAudit() is in activity-generic.js. For this to work, 'quizly' has to be # added to TRACKABLE_COMPONENTS in models/progress.py script += '<script>function updateQuizlyProgressIcon(id, score) { ' script += ' var qname = window.quizlies.quizname;' script += ' var iframes = document.getElementsByTagName(\'iframe\');' script += ' var iconholder = \'\';' script += ' var innerHtml = \'\';' script += ' if (score >= 1) ' script += ' innerHtml = \'<img alt="Completed" class="gcb-progress-icon" src="assets/img/completed.png" title="Completed">\';' script += ' else' script += ' innerHtml = \'<img alt="In_progress" class="gcb-progress-icon" src="assets/img/in_progress.png" title="In progress">\';' script += ' for (var i=0; i < iframes.length; i++) { ' script += ' var iframe = iframes[i];' script += ' if (iframe.src.indexOf(qname) != -1) { ' script += ' iconholder = iframe.previousSibling.previousSibling;' script += ' break;' script += ' }' script += ' }' script += ' if (iconholder != \'\') ' script += ' iconholder.innerHTML = innerHtml;' script += '}' script += '</script>' script += '<script> function checkAnswer(){ ' script += 'var quizName = window.quizlies["quizname"];' script += 'var instanceid = window.quizlies[quizName].id;' script += 'var result = window.quizlies[quizName].result;' script += 'var score = (result) ? 1 : 0;' script += 'console.log("RAM (quizly.py): That solution was " + result);' script += 'if (gcbCanRecordStudentEvents) {' script += 'console.log("RAM (quizly.py): POSTing to server");' script += 'console.log("RAM (quizly.py): instanceid=" + instanceid);' script += 'var auditDict = {' script += '\'instanceid\': instanceid,' script += '\'answer\': result,' script += '\'score\': score,' script += '\'type\': "SaQuestion",' script += '};' script += 'gcbAudit(gcbCanRecordStudentEvents, auditDict, "tag-assessment", true);' script += '}' script += ' updateQuizlyProgressIcon(instanceid, score);' script += '}' script += '</script>' returnStr = '' returnStr += script # Add the box-surrounded iframe that will hold the quiz. Blockly will be a frame w/in this frame. returnStr += '<div style="border: 1px solid black; margin: 5px; padding: 5px;">' returnStr += '<div id="' + id_iconholder + '" class="gcb-progress-icon-holder gcb-pull-right">' pointsdiv = '<div class="qt-points"><em>1 point </em></div>' # returnStr += pointsdiv progress_img = '' if status == 0: progress_img += '<img src="assets/img/not_started.png" />' elif status == 1: progress_img += '<img src="assets/img/in_progress.png" />' else: progress_img += '<img src="assets/img/completed.png" />' returnStr += progress_img returnStr += '</div>' returnStr += pointsdiv returnStr += '<iframe style= "border: 0px; margin: 1px; padding: 1px;" src=' + src + ' width="' + width + '" height="' + height + '">' returnStr += '</iframe>' returnStr += '</div>' return tags.html_string_to_element_tree(returnStr)