コード例 #1
0
    def student_view(self, context):
        fragment = Fragment()
        children_contents = []

        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            if child is None:  # child should not be None but it can happen due to bugs or permission issues
                child_content = u"<p>[{}]</p>".format(self._(u"Error: Unable to load child component."))
            elif not isinstance(child, MentoringMessageBlock):
                child_fragment = self._render_child_fragment(child, context, view='mentoring_view')
                fragment.add_frag_resources(child_fragment)
                child_content = child_fragment.content
            children_contents.append(child_content)

        fragment.add_content(loader.render_template('templates/html/mentoring_with_steps.html', {
            'self': self,
            'title': self.display_name,
            'show_title': self.show_title,
            'children_contents': children_contents,
        }))
        fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/problem-builder.css'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/underscore-min.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring_with_steps.js'))

        fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.html'), "text/html")
        fragment.add_resource(loader.load_unicode('templates/html/mentoring_review_templates.html'), "text/html")

        self.include_theme_files(fragment)

        fragment.initialize_js('MentoringWithStepsBlock')

        return fragment
コード例 #2
0
ファイル: problem.py プロジェクト: renzo-orsini/XBlock
    def problem_view(self, context=None):
        """Renders the problem view.

        The view is specific to whether or not this problem was attempted, and, if so,
        if it was answered correctly.

        """
        correct = self.left == self.right

        # TODO: I originally named this class="data", but that conflicted with
        # the CSS on the page! :(  We might have to do something to namespace
        # things.
        # TODO: Should we have a way to spit out JSON islands full of data?
        # Note the horror of mixed Python-Javascript data below...
        content = string.Template(self.content).substitute(**context)
        result = Fragment(u"""
            <span class="mydata" data-attempted='{self.attempted}' data-correct='{correct}'>
                {content}
                <span class='indicator'></span>
            </span>
            """.format(self=self, content=content, correct=correct)
        )
        # TODO: This is a runtime-specific URL.  But if each XBlock ships their
        # own copy of underscore.js, we won't be able to uniquify them.
        # Perhaps runtimes can offer a palette of popular libraries so that
        # XBlocks can refer to them in XBlock-standard ways?
        result.add_javascript_url("/static/js/vendor/underscore-min.js")

        # TODO: The image tag here needs a magic URL, not a hard-coded one.
        result.add_resource(u"""
            <script type="text/template" id="xblock-equality-template">
                <% if (attempted !== "True") { %>
                    (Not attempted)
                <% } else { %>
                    <img src="/resource/workbench/images/<%= (correct === "True") ? "correct" : "incorrect" %>-icon.png">
                <% } %>
            </script>
            """, "text/html")

        result.add_javascript("""
            function EqualityCheckerBlock(runtime, element) {
                var template = _.template($("#xblock-equality-template").html());
                function render() {
                    var data = $("span.mydata", element).data();
                    $("span.indicator", element).html(template(data));
                }
                render();
                return {
                    handle_check: function(result) {
                        $("span.mydata", element)
                              .data("correct", result ? "True" : "False")
                              .data("attempted", "True");
                        render();
                    }
                }
            }
            """)

        result.initialize_js('EqualityCheckerBlock')
        return result
コード例 #3
0
ファイル: mentoring.py プロジェクト: shahdnet/problem-builder
    def student_view(self, context):
        fragment = Fragment()
        children_contents = []

        context = context or {}
        context['hide_prev_answer'] = True  # For Step Builder, we don't show the users' old answers when they try again
        context['score_summary'] = self.get_score_summary()
        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            if child is None:  # child should not be None but it can happen due to bugs or permission issues
                child_content = u"<p>[{}]</p>".format(self._(u"Error: Unable to load child component."))
            else:
                child_fragment = self._render_child_fragment(child, context, view='mentoring_view')
                fragment.add_frag_resources(child_fragment)
                child_content = child_fragment.content
            children_contents.append(child_content)

        fragment.add_content(loader.render_template('templates/html/mentoring_with_steps.html', {
            'self': self,
            'title': self.display_name,
            'show_title': self.show_title,
            'children_contents': children_contents,
        }))
        fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/problem-builder.css'))
        fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/lms.css'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/underscore-min.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/step_util.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring_with_steps.js'))

        fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.underscore'), "text/html")
        fragment.initialize_js('MentoringWithStepsBlock', {
            'show_extended_feedback': self.show_extended_feedback(),
        })

        return fragment
コード例 #4
0
    def student_view(self, context):
        fragment = Fragment()
        children_contents = []

        context = context or {}
        context['hide_prev_answer'] = True  # For Step Builder, we don't show the users' old answers when they try again
        context['score_summary'] = self.get_score_summary()
        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            if child is None:  # child should not be None but it can happen due to bugs or permission issues
                child_content = u"<p>[{}]</p>".format(self._(u"Error: Unable to load child component."))
            else:
                child_fragment = self._render_child_fragment(child, context, view='mentoring_view')
                fragment.add_frag_resources(child_fragment)
                child_content = child_fragment.content
            children_contents.append(child_content)

        fragment.add_content(loader.render_django_template('templates/html/mentoring_with_steps.html', {
            'self': self,
            'title': self.display_name,
            'show_title': self.show_title,
            'children_contents': children_contents,
        }, i18n_service=self.i18n_service))
        fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/problem-builder.css'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/underscore-min.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/step_util.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring_with_steps.js'))

        fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.underscore'), "text/html")
        fragment.initialize_js('MentoringWithStepsBlock', {
            'show_extended_feedback': self.show_extended_feedback(),
        })

        return fragment
コード例 #5
0
    def student_view(self, context):
        fragment = Fragment()

        # Check if the student view of a step child has been requested
        context_step_name = context.get('step', None) if context else None
        context_step_child_name = context.get('child',
                                              None) if context else None
        if (context_step_name and context_step_name == self.current_step_name
                and context_step_child_name):
            step = self._get_step_by_name(context_step_name)
            for child in step.get_children_objects():
                if child.name == context_step_child_name:
                    # 3play api key from setting
                    if not child.api_key_3play:
                        child.api_key_3play = self.api_key_3play_from_default_setting(
                        )
                    return child.student_view(context)

        # First access, set the current_step to the beginning of the adventure
        if not self.current_step_name and self.has_steps:
            self.current_step_name = 'first'

        info_fragment = None
        if self.info:
            info_fragment = self.info.render(context={'as_template': False})

        fragment.add_content(
            loader.render_template('templates/html/adventure.html', {
                'self': self,
                'info_fragment': info_fragment,
            }))

        for css_url in self.CSS_URLS:
            fragment.add_css_url(self.runtime.local_resource_url(
                self, css_url))

        for js_url in self.JS_URLS:
            fragment.add_javascript_url(
                self.runtime.local_resource_url(self, js_url))

        context = {}
        for template in self.JS_TEMPLATES:
            fragment.add_resource(
                loader.render_js_template(template[1],
                                          element_id=template[0],
                                          context=context), "text/html")

        fragment.initialize_js('AdventureBlock')

        return fragment
コード例 #6
0
    def student_view(self, context):
        fragment = Fragment()

        # Check if the student view of a step child has been requested
        context_step_name = context.get('step', None) if context else None
        context_step_child_name = context.get('child', None) if context else None
        if (context_step_name and
                context_step_name == self.current_step_name and
                context_step_child_name):
            step = self._get_step_by_name(context_step_name)
            for child in step.get_children_objects():
                if child.name == context_step_child_name:
                    # 3play api key from setting
                    if not child.api_key_3play:
                        child.api_key_3play = self.api_key_3play_from_default_setting()
                    return child.student_view(context)

        # First access, set the current_step to the beginning of the adventure
        if not self.current_step_name and self.has_steps:
            self.current_step_name = 'first'

        info_fragment = None
        if self.info:
            info_fragment = self.info.render(context={'as_template': False})

        fragment.add_content(loader.render_template(
            'templates/html/adventure.html', {
                'self': self,
                'info_fragment': info_fragment,
            }))

        for css_url in self.CSS_URLS:
            fragment.add_css_url(self.runtime.local_resource_url(self, css_url))

        for js_url in self.JS_URLS:
            fragment.add_javascript_url(self.runtime.local_resource_url(self, js_url))

        context = {}
        for template in self.JS_TEMPLATES:
            fragment.add_resource(
                loader.render_js_template(template[1], element_id=template[0], context=context),
                "text/html"
            )

        fragment.initialize_js('AdventureBlock')

        return fragment
コード例 #7
0
    def student_view(self, context):
        fragment = Fragment()
        children_contents = []

        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            if child is None:  # child should not be None but it can happen due to bugs or permission issues
                child_content = u"<p>[{}]</p>".format(
                    self._(u"Error: Unable to load child component."))
            elif not isinstance(child, MentoringMessageBlock):
                child_fragment = self._render_child_fragment(
                    child, context, view='mentoring_view')
                fragment.add_frag_resources(child_fragment)
                child_content = child_fragment.content
            children_contents.append(child_content)

        fragment.add_content(
            loader.render_template(
                'templates/html/mentoring_with_steps.html', {
                    'self': self,
                    'title': self.display_name,
                    'show_title': self.show_title,
                    'children_contents': children_contents,
                }))
        fragment.add_css_url(
            self.runtime.local_resource_url(self,
                                            'public/css/problem-builder.css'))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(
                self, 'public/js/vendor/underscore-min.js'))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(
                self, 'public/js/mentoring_with_steps.js'))

        fragment.add_resource(
            loader.load_unicode('templates/html/mentoring_attempts.html'),
            "text/html")
        fragment.add_resource(
            loader.load_unicode(
                'templates/html/mentoring_review_templates.html'), "text/html")

        self.include_theme_files(fragment)

        fragment.initialize_js('MentoringWithStepsBlock')

        return fragment
コード例 #8
0
ファイル: mentoring.py プロジェクト: gibacache/xblock
    def student_view(self, context):
        from .questionnaire import QuestionnaireAbstractBlock  # Import here to avoid circular dependency

        # Migrate stored data if necessary
        self.migrate_fields()

        # Validate self.step:
        num_steps = len(self.steps)
        if self.step > num_steps:
            self.step = num_steps

        fragment = Fragment()
        child_content = u""

        mcq_hide_previous_answer = self.get_option(
            'pb_mcq_hide_previous_answer')

        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            if child is None:  # child should not be None but it can happen due to bugs or permission issues
                child_content += u"<p>[{}]</p>".format(
                    self._(u"Error: Unable to load child component."))
            elif not isinstance(child, MentoringMessageBlock):
                try:
                    if self.is_assessment and isinstance(child, QuestionMixin):
                        child_fragment = child.render('assessment_step_view',
                                                      context)
                    else:
                        if mcq_hide_previous_answer and isinstance(
                                child, QuestionnaireAbstractBlock):
                            context['hide_prev_answer'] = True
                        else:
                            context['hide_prev_answer'] = False
                        child_fragment = child.render('mentoring_view',
                                                      context)
                except NoSuchViewError:
                    if child.scope_ids.block_type == 'html' and getattr(
                            self.runtime, 'is_author_mode', False):
                        # html block doesn't support mentoring_view, and if we use student_view Studio will wrap
                        # it in HTML that we don't want in the preview. So just render its HTML directly:
                        child_fragment = Fragment(child.data)
                    else:
                        child_fragment = child.render('student_view', context)
                fragment.add_frag_resources(child_fragment)
                child_content += child_fragment.content

        fragment.add_content(
            loader.render_template(
                'templates/html/mentoring.html', {
                    'self':
                    self,
                    'title':
                    self.display_name,
                    'show_title':
                    self.show_title,
                    'child_content':
                    child_content,
                    'missing_dependency_url':
                    self.has_missing_dependency and self.next_step_url,
                }))
        fragment.add_css_url(
            self.runtime.local_resource_url(self,
                                            'public/css/problem-builder.css'))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(
                self, 'public/js/vendor/underscore-min.js'))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self, 'public/js/util.js'))
        js_file = 'public/js/mentoring_{}_view.js'.format(
            'assessment' if self.is_assessment else 'standard')
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self, js_file))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self, 'public/js/mentoring.js'))
        fragment.add_resource(
            loader.load_unicode('templates/html/mentoring_attempts.html'),
            "text/html")
        if self.is_assessment:
            fragment.add_resource(
                loader.load_unicode(
                    'templates/html/mentoring_assessment_templates.html'),
                "text/html")

        self.include_theme_files(fragment)
        # Workbench doesn't have font awesome, so add it:
        if WorkbenchRuntime and isinstance(self.runtime, WorkbenchRuntime):
            fragment.add_css_url(
                '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'
            )

        fragment.initialize_js('MentoringBlock')

        if not self.display_submit:
            self.runtime.publish(self, 'progress', {})

        return fragment
コード例 #9
0
    def student_view(self, context):
        # Migrate stored data if necessary
        self.migrate_fields()

        # Validate self.step:
        num_steps = len(self.steps)
        if self.step > num_steps:
            self.step = num_steps

        fragment = Fragment()
        child_content = u""

        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            if child is None:  # child should not be None but it can happen due to bugs or permission issues
                child_content += u"<p>[{}]</p>".format(self._(u"Error: Unable to load child component."))
            elif not isinstance(child, MentoringMessageBlock):
                try:
                    if self.is_assessment and isinstance(child, QuestionMixin):
                        child_fragment = child.render('assessment_step_view', context)
                    else:
                        child_fragment = child.render('mentoring_view', context)
                except NoSuchViewError:
                    if child.scope_ids.block_type == 'html' and getattr(self.runtime, 'is_author_mode', False):
                        # html block doesn't support mentoring_view, and if we use student_view Studio will wrap
                        # it in HTML that we don't want in the preview. So just render its HTML directly:
                        child_fragment = Fragment(child.data)
                    else:
                        child_fragment = child.render('student_view', context)
                fragment.add_frag_resources(child_fragment)
                child_content += child_fragment.content

        fragment.add_content(loader.render_template('templates/html/mentoring.html', {
            'self': self,
            'title': self.display_name,
            'show_title': self.show_title,
            'child_content': child_content,
            'missing_dependency_url': self.has_missing_dependency and self.next_step_url,
        }))
        fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/problem-builder.css'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/underscore-min.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/util.js'))
        js_file = 'public/js/mentoring_{}_view.js'.format('assessment' if self.is_assessment else 'standard')
        fragment.add_javascript_url(self.runtime.local_resource_url(self, js_file))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/mentoring.js'))
        fragment.add_resource(loader.load_unicode('templates/html/mentoring_attempts.html'), "text/html")
        if self.is_assessment:
            fragment.add_resource(
                loader.load_unicode('templates/html/mentoring_assessment_templates.html'), "text/html"
            )

        self.include_theme_files(fragment)
        # Workbench doesn't have font awesome, so add it:
        if WorkbenchRuntime and isinstance(self.runtime, WorkbenchRuntime):
            fragment.add_css_url('//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css')

        fragment.initialize_js('MentoringBlock')

        if not self.display_submit:
            self.runtime.publish(self, 'progress', {})

        return fragment
コード例 #10
0
ファイル: problem.py プロジェクト: wkoha/xblock-sdk
    def problem_view(self, context=None):
        """Renders the problem view.

        The view is specific to whether or not this problem was attempted, and, if so,
        if it was answered correctly.

        """
        correct = self.left == self.right

        # TODO: I originally named this class="data", but that conflicted with
        # the CSS on the page! :(  We might have to do something to namespace
        # things.
        # TODO: Should we have a way to spit out JSON islands full of data?
        # Note the horror of mixed Python-Javascript data below...
        content = string.Template(self.content).substitute(**context)
        result = Fragment(u"""
            <span class="mydata" data-attempted='{self.attempted}' data-correct='{correct}'>
                {content}
                <span class='indicator'></span>
            </span>
            """.format(self=self, content=content, correct=correct))
        # TODO: This is a runtime-specific URL.  But if each XBlock ships their
        # own copy of underscore.js, we won't be able to uniquify them.
        # Perhaps runtimes can offer a palette of popular libraries so that
        # XBlocks can refer to them in XBlock-standard ways?
        result.add_javascript_url(
            self.runtime.resource_url("js/vendor/underscore-min.js"))

        # TODO: The image tag here needs a magic URL, not a hard-coded one.
        format_data = {
            'correct':
            self.runtime.local_resource_url(self,
                                            'public/images/correct-icon.png'),
            'incorrect':
            self.runtime.local_resource_url(
                self, 'public/images/incorrect-icon.png'),
        }
        result.add_resource(
            u"""
            <script type="text/template" id="xblock-equality-template">
                <% if (attempted !== "True") {{ %>
                    (Not attempted)
                <% }} else if (correct === "True") {{ %>
                    <img src="{correct}">
                <% }} else {{ %>
                    <img src="{incorrect}">
                <% }} %>
            </script>
            """.format(**format_data), "text/html")

        result.add_javascript("""
            function EqualityCheckerBlock(runtime, element) {
                var template = _.template($("#xblock-equality-template").html());
                function render() {
                    var data = $("span.mydata", element).data();
                    $("span.indicator", element).html(template(data));
                }
                render();
                return {
                    handleCheck: function(result) {
                        $("span.mydata", element)
                              .data("correct", result ? "True" : "False")
                              .data("attempted", "True");
                        render();
                    }
                }
            }
            """)

        result.initialize_js('EqualityCheckerBlock')
        return result