コード例 #1
0
    def student_view(self, context=None):
        """
        The primary view of VideoQuiz, shown to students.
        """

        # load contents of quiz if any, otherwise this is just a YouTube video player
        if self.quiz_content != "":
            self.load_quiz()

        print("Loading Student View")
        print("====================")
        print(">> Parameters: ")
        print(self.quiz_content)
        print(self.vid_url)
        # print(self.width)
        # print(self.height)
        print(">> Filled data")
        print("Quiz entries: " + str(self.quiz))
        print("Quiz cue times: " + str(self.quiz_cuetimes))
        print("Answers: " + str(self.answers))
        print("Results: " + str(self.results))

        fragment = Fragment()
        fragment.add_content(render_template('templates/html/vidquiz.html', {'self': self}))
        fragment.add_css(load_resource('static/css/vidquiz.css'))
        fragment.add_javascript(load_resource('static/js/vidquiz.js'))
        fragment.initialize_js('VideoQuiz')

        return fragment
コード例 #2
0
ファイル: seq_module.py プロジェクト: caesar2164/edx-platform
    def _student_view(self, context, banner_text=None):
        """
        Returns the rendered student view of the content of this
        sequential.  If banner_text is given, it is added to the
        content.
        """
        display_items = self.get_display_items()
        self._update_position(context, len(display_items))

        fragment = Fragment()
        params = {
            'items': self._render_student_view_for_items(context, display_items, fragment),
            'element_id': self.location.html_id(),
            'item_id': self.location.to_deprecated_string(),
            'position': self.position,
            'tag': self.location.category,
            'ajax_url': self.system.ajax_url,
            'next_url': context.get('next_url'),
            'prev_url': context.get('prev_url'),
            'banner_text': banner_text,
        }
        fragment.add_content(self.system.render_template("seq_module.html", params))

        self._capture_full_seq_item_metrics(display_items)
        self._capture_current_unit_metrics(display_items)

        return fragment
コード例 #3
0
ファイル: runtime.py プロジェクト: cpennington/xblock-sdk
    def wrap_child(self, block, view, frag, context):  # pylint: disable=W0613
        wrapped = Fragment()
        wrapped.add_javascript_url(self.resource_url("js/vendor/jquery.min.js"))
        wrapped.add_javascript_url(self.resource_url("js/vendor/jquery.cookie.js"))

        data = {}
        if frag.js_init_fn:
            wrapped.add_javascript_url(self.resource_url("js/runtime/%s.js" % frag.js_init_version))
            data['init'] = frag.js_init_fn
            data['runtime-version'] = frag.js_init_version
            data['usage'] = block.scope_ids.usage_id
            data['block-type'] = block.scope_ids.block_type

        if block.name:
            data['name'] = block.name

        json_init = ""
        # TODO/Note: We eventually want to remove: hasattr(frag, 'json_init_args')
        # However, I'd like to maintain backwards-compatibility with older XBlock
        # for at least a little while so as not to adversely effect developers.
        # pmitros/Jun 28, 2014.
        if hasattr(frag, 'json_init_args') and frag.json_init_args is not None:
            json_init = u'<script type="json/xblock-args" class="xblock_json_init_args">' + \
                u'{data}</script>'.format(data=json.dumps(frag.json_init_args))

        html = u"<div class='xblock'{properties}>{body}{js}</div>".format(
            properties="".join(" data-%s='%s'" % item for item in data.items()),
            body=frag.body_html(),
            js=json_init)

        wrapped.add_content(html)
        wrapped.add_frag_resources(frag)
        return wrapped
コード例 #4
0
 def get_url_name_fragment(self, caption):
     fragment = Fragment()
     fragment.add_content(loader.render_template(
         "templates/html/url_name.html",
         {'url_name': self.url_name, 'caption': caption}
     ))
     return fragment
コード例 #5
0
 def studio_view(self, context=None):
     fragment = Fragment()
     fragment.add_content(Util.render_template("static/html/uc_rtc_studio.html"))
     fragment.add_css(Util.load_resource("static/css/uc_rtc.css"))
     fragment.add_javascript(Util.load_resource("static/js/src/uc_rtc_edit.js"))
     fragment.initialize_js("UcRtcXBlock")
     return fragment
コード例 #6
0
    def student_view(self, context=None):
        """
        The primary view of the AssessmentFactoryXBlock, shown to students
        when viewing courses.
        """
        self.runtime.publish(self, 'edx.assessment_factory.problem.loaded', {})

        if not self.problem_active:
            self.problem_active = True
            self.retry_count = self.set_retry_count

        context = {
            'display_name': self.display_name,
            'studio_assignment': self.studio_assignment,
            'item_state': self.item_state,
            'retry_count': self.retry_count,
            'is_graded': self.is_graded,
            'has_score': self.has_score,
            'allow_reset': self.allow_reset,
            'allow_check': self.allow_check
        }
        frag = Fragment()
        frag.add_content(loader.render_template('/public/html/assessment_factory.html', context))
        frag.add_css(self.resource_string("public/css/vendors/jquery-ui.css"))
        frag.add_css(self.resource_string("public/css/vendors/font-awesome.min.css"))
        frag.add_css(self.resource_string("public/css/src/assessment_factory.css"))
        frag.add_javascript(self.resource_string("public/js/vendors/jquery-ui.min.js"))
        frag.add_javascript(self.resource_string("public/js/vendors/underscore.string.js"))
        frag.add_javascript(self.resource_string("public/js/src/assessment_factory.js"))
        frag.initialize_js('AssessmentFactoryBlock', context)

        return frag
コード例 #7
0
    def student_view(self, context):
        """
        Renders the student view of the block in the LMS.
        """
        fragment = Fragment()
        contents = []

        child_context = {} if not context else copy(context)
        child_context['child_of_vertical'] = True

        # pylint: disable=no-member
        for child in self.get_display_items():
            rendered_child = child.render(STUDENT_VIEW, child_context)
            fragment.add_frag_resources(rendered_child)

            contents.append({
                'id': child.location.to_deprecated_string(),
                'content': rendered_child.content
            })

        fragment.add_content(self.system.render_template('vert_module.html', {
            'items': contents,
            'xblock_context': context,
            'show_bookmark_button': True,
            'bookmarked': child_context['bookmarked'],
            'bookmark_id': "{},{}".format(child_context['username'], unicode(self.location))
        }))

        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vertical_student_view.js'))
        fragment.initialize_js('VerticalStudentView')

        return fragment
コード例 #8
0
    def studio_view(self, context=None):
        """
        The staff's view of RichReviewXBlock. Staffs can upload discussion topic PDF or view the students'
        discussion activities
        """
        frag = Fragment()
        frag.add_css(load_resource("static/css/richreview.css"))
        frag.add_javascript(load_resource("static/js/src/richreview_studio.js"))
        frag.add_content(render_template(
                "templates/richreview_studio.html",
                {
                    'xblock_id': self.xblock_id,
                    'student_id': self.anonymous_student_id,
                    'user_is_staff': str(self.user_is_staff),
                    'students_of_group': str(self.students_of_group),
                    'group_of_student': str(self.group_of_student),
                    'discussion_docid': self.discussion_docid,

                    'is_pdf_ready': self.is_pdf_ready,
                    'is_debug': False,
                    'pdf_url': self.fs.get_url(self.pdf_path, RESOURCE_EXPIRATION_TIME),
                    'pdfjs_url': self.fs.get_url(self.pdfjs_path, RESOURCE_EXPIRATION_TIME),

                    'loader_gif_url': self.runtime.local_resource_url(self, "public/ajax-loader.gif")
                }
            ))
        frag.initialize_js('RichReviewXBlockStudio', "abcd")
        return frag
コード例 #9
0
    def studio_view(self, context):
        """
        Editing view in Studio
        """

        js_templates = load_resource('/templates/html/js_templates.html')
        context = {
            'js_templates': js_templates,
            'self': self,
            'data': urllib.quote(json.dumps(self.data)),
        }

        fragment = Fragment()
        fragment.add_content(render_template('/templates/html/drag_and_drop_edit.html', context))
        fragment.add_css_url(self.runtime.local_resource_url(self,
            'public/css/vendor/jquery-ui-1.10.4.custom.min.css'))
        fragment.add_css_url(self.runtime.local_resource_url(self,
            'public/css/drag_and_drop_edit.css'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/vendor/jquery-ui-1.10.4.custom.min.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/vendor/jquery.html5-placeholder-shim.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/vendor/handlebars-v1.1.2.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/drag_and_drop_edit.js'))

        fragment.initialize_js('DragAndDropEditBlock')

        return fragment
コード例 #10
0
ファイル: carousel.py プロジェクト: METIT-BU/xblock-carousel
    def student_view(self, context):
        """
        Lab view, displayed to the student
        """

	root = ET.fromstring(self.data)
        items = []
        for child in root:
            if child.tag == 'doc': child.text = urllib.quote(child.text, '')
            width = child.attrib.get('width', '100%')
            height = child.attrib.get('height', '625')
            items.append((child.tag, child.text, width, height))

        fragment = Fragment()

        context = {
            'items': items,
        }

        fragment.add_content(render_template('/templates/html/carousel.html', context))
        fragment.add_javascript(load_resource('public/js/jquery-ui-1.10.4.custom.js'))
        fragment.add_css(load_resource('public/css/responsive-carousel.css'))
        fragment.add_css(load_resource('public/css/responsive-carousel.slide.css'))
        fragment.add_javascript(load_resource('public/js/responsive-carousel.js'))
        fragment.add_javascript(load_resource('public/js/responsive-carousel.loop.js'))
        fragment.add_css_url("https://vjs.zencdn.net/4.5.1/video-js.css")
        fragment.add_javascript_url("https://vjs.zencdn.net/4.5.1/video.js")
        fragment.add_javascript(load_resource('public/js/youtube.js'))
        fragment.add_javascript('function CarouselBlock(runtime, element) {$(".carousel").carousel();console.log("OK");}')
        fragment.initialize_js('CarouselBlock')

        return fragment
コード例 #11
0
    def author_view(self, context):
        """
        Renders the Studio views.
        Normal studio view: If block is properly configured, displays library status summary
        Studio container view: displays a preview of all possible children.
        """
        fragment = Fragment()
        root_xblock = context.get('root_xblock')
        is_root = root_xblock and root_xblock.location == self.location

        if is_root:
            # User has clicked the "View" link. Show a preview of all possible children:
            if self.children:  # pylint: disable=no-member
                fragment.add_content(self.system.render_template("library-block-author-preview-header.html", {
                    'max_count': self.max_count,
                    'display_name': self.display_name or self.url_name,
                }))
                context['can_edit_visibility'] = False
                self.render_children(context, fragment, can_reorder=False, can_add=False)
        # else: When shown on a unit page, don't show any sort of preview -
        # just the status of this block in the validation area.

        # The following JS is used to make the "Update now" button work on the unit page and the container view:
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/library_content_edit.js'))
        fragment.initialize_js('LibraryContentAuthorView')
        return fragment
コード例 #12
0
    def student_view(self, context):
        """
        Player view, displayed to the student
        """

        max_score_string = '({0} Point{1} Possible)'.format(int(self.weight),
            's' if self.weight > 1 else '') if self.weight else ''
        js_templates = load_resource('/templates/html/js_templates.html')

        context = {
            'js_templates': js_templates,
            'title': self.display_name,
            'question_text': self.question_text,
            'max_score_string': max_score_string
        }

        fragment = Fragment()
        fragment.add_content(render_template('/templates/html/drag_and_drop.html', context))
        fragment.add_css_url(self.runtime.local_resource_url(self,
            'public/css/vendor/jquery-ui-1.10.4.custom.min.css'))
        fragment.add_css_url(self.runtime.local_resource_url(self,
            'public/css/drag_and_drop.css'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/vendor/jquery-ui-1.10.4.custom.min.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/vendor/jquery.html5-placeholder-shim.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/vendor/handlebars-v1.1.2.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self,
            'public/js/drag_and_drop.js'))

        fragment.initialize_js('DragAndDropBlock')

        return fragment
コード例 #13
0
    def _staff_view(self, context):
        """
        Render the staff view for a split test module.
        """
        fragment = Fragment()
        contents = []

        for group_id in self.group_id_to_child:
            child_location = self.group_id_to_child[group_id]
            child_descriptor = self.get_child_descriptor_by_location(child_location)
            child = self.system.get_module(child_descriptor)
            rendered_child = child.render(STUDENT_VIEW, context)
            fragment.add_frag_resources(rendered_child)

            contents.append({
                'group_id': group_id,
                'id': child.location.to_deprecated_string(),
                'content': rendered_child.content
            })

        # Use the new template
        fragment.add_content(self.system.render_template('split_test_staff_view.html', {
            'items': contents,
        }))
        fragment.add_css('.split-test-child { display: none; }')
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_staff.js'))
        fragment.initialize_js('ABTestSelector')
        return fragment
コード例 #14
0
    def author_view(self, context):
        """
        Renders the Studio preview by rendering each child so that they can all be seen and edited.
        """
        fragment = Fragment()
        root_xblock = context.get('root_xblock')
        is_configured = not self.user_partition_id == SplitTestFields.no_partition_selected['value']
        is_root = root_xblock and root_xblock.location == self.location
        active_groups_preview = None
        inactive_groups_preview = None

        if is_root:
            [active_children, inactive_children] = self.descriptor.active_and_inactive_children()
            active_groups_preview = self.studio_render_children(
                fragment, active_children, context
            )
            inactive_groups_preview = self.studio_render_children(
                fragment, inactive_children, context
            )

        fragment.add_content(self.system.render_template('split_test_author_view.html', {
            'split_test': self,
            'is_root': is_root,
            'is_configured': is_configured,
            'active_groups_preview': active_groups_preview,
            'inactive_groups_preview': inactive_groups_preview,
            'group_configuration_url': self.descriptor.group_configuration_url,
        }))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_author_view.js'))
        fragment.initialize_js('SplitTestAuthorView')

        return fragment
コード例 #15
0
ファイル: content.py プロジェクト: mfseddik/OpenDSAX
 def student_view(self, context=None):
     """
     The primary view of the ContentXBlock, shown to students
     when viewing courses.
     """
     if self.contnet_type == "content":
         result = Fragment()
         url = "public/html/"+self.short_name+".html"
         fragment = Fragment(self.resource_string(url))
         html_template = Template(self.resource_string("templates/student_view.html"))
         html_context = Context({"fragment": fragment}) 
         html_str = html_template.render(html_context)
         result.add_content(html_str)
         return result
     elif self.contnet_type == "topnav":
         html_context = Context({"source_link": self.source_link, 
                                 "prev_link": self.prev_link, 
                                 "prev_name": self.prev_name, 
                                 "toc_link": self.toc_link, 
                                 "next_link": self.next_link, 
                                 "next_name": self.next_name, 
                                 })
         html_template = Template(self.resource_string("templates/student_view_topnav.html"))
         fragment = Fragment(html_template.render(html_context))
         return fragment
     elif self.contnet_type == "header":
         return
     elif self.contnet_type == "footer":
         return
コード例 #16
0
    def student_view(self, context=None):
        """
        The primary view of the LaunchContainerXBlock, shown to students
        when viewing courses.
        """

        user_email = None
        # workbench runtime won't supply system property
        if getattr(self, 'system', None):
            if self.system.anonymous_student_id:
                if getattr(self.system, 'get_real_user', None):
                    anon_id = self.system.anonymous_student_id
                    user = self.system.get_real_user(anon_id)
                    if user and user.is_authenticated():
                        user_email = user.email
                elif self.system.user_is_staff:  # Studio preview
                    from django.contrib.auth.models import User
                    user = User.objects.get(id=self.system.user_id)
                    user_email = user.email

        context = {
            'project': self.project,
            'project_friendly': self.project_friendly,
            'user_email' : user_email,
            'API_url': self.api_url
        }
        frag = Fragment()
        frag.add_content(
            render_template('static/html/launchcontainer.html', context)
        )
        frag.add_javascript(render_template("static/js/src/launchcontainer.js",
                                            context))
        frag.initialize_js('LaunchContainerXBlock')
        return frag
コード例 #17
0
ファイル: runtime.py プロジェクト: Jianbinma/XBlock
    def _wrap_ele(self, block, frag, extra_data=None):
        """
        Does the guts of the wrapping the same way for both xblocks and asides. Their
        wrappers provide other info in extra_data which gets put into the dom data- attrs.
        """
        wrapped = Fragment()
        data = {
            'usage': block.scope_ids.usage_id,
            'block-type': block.scope_ids.block_type,
        }
        data.update(extra_data)

        if frag.js_init_fn:
            data['init'] = frag.js_init_fn
            data['runtime-version'] = frag.js_init_version

        json_init = ""
        # TODO/Note: We eventually want to remove: hasattr(frag, 'json_init_args')
        # However, I'd like to maintain backwards-compatibility with older XBlock
        # for at least a little while so as not to adversely effect developers.
        # pmitros/Jun 28, 2014.
        if hasattr(frag, 'json_init_args') and frag.json_init_args is not None:
            json_init = u'<script type="json/xblock-args" class="xblock_json_init_args">' + \
                u'{data}</script>'.format(data=json.dumps(frag.json_init_args))

        html = u"<div class='{}'{properties}>{body}{js}</div>".format(
            block.entry_point.replace('.', '-'),
            properties="".join(" data-%s='%s'" % item for item in data.items()),
            body=frag.body_html(),
            js=json_init)

        wrapped.add_content(html)
        wrapped.add_frag_resources(frag)
        return wrapped
コード例 #18
0
ファイル: slider.py プロジェクト: mjrulesamrat/slider
    def studio_view(self, context=None):
        """
        The studio view
        """
        banner_url1 = self.runtime.local_resource_url(self,
                                                     'public/img/banner01.jpg')
        banner_url2 = self.runtime.local_resource_url(self,
                                                     'public/img/banner02.jpg')
        banner_url3 = self.runtime.local_resource_url(self,
                                                     'public/img/banner03.jpg')

        fragment = Fragment()
        content = {
            'self': self,
           'banner1': banner_url1,
           'banner2': banner_url2,
           'banner3': banner_url3,
        }
        # Load Studio View
        fragment.add_content(render_template('static/html/slider_edit.html', content))
        fragment.add_css(load_resource('static/css/slider_edit.css'))
        fragment.add_javascript(unicode(render_template('static/js/src/jquery.MultiFile.js', content)))
        fragment.add_javascript(unicode(render_template('static/js/src/slider_edit.js', content)))
        fragment.initialize_js('SliderXBlockStudio')

        return fragment
コード例 #19
0
    def author_view(self, context):
        """
        Renders the Studio preview by rendering each child so that they can all be seen and edited.
        """
        fragment = Fragment()
        root_xblock = context.get("root_xblock")
        is_root = root_xblock and root_xblock.location == self.location
        active_groups_preview = None
        inactive_groups_preview = None

        if is_root:
            [active_children, inactive_children] = self.descriptor.active_and_inactive_children()
            active_groups_preview = self.studio_render_children(fragment, active_children, context)
            inactive_groups_preview = self.studio_render_children(fragment, inactive_children, context)

        fragment.add_content(
            self.system.render_template(
                "split_test_author_view.html",
                {
                    "split_test": self,
                    "is_root": is_root,
                    "is_configured": self.is_configured,
                    "active_groups_preview": active_groups_preview,
                    "inactive_groups_preview": inactive_groups_preview,
                    "group_configuration_url": self.descriptor.group_configuration_url,
                },
            )
        )
        fragment.add_javascript_url(self.runtime.local_resource_url(self, "public/js/split_test_author_view.js"))
        fragment.initialize_js("SplitTestAuthorView")

        return fragment
コード例 #20
0
    def student_view(self, context):
        """
        Player view, displayed to the student
        """

        fragment = Fragment()
        fragment.add_content(loader.render_template('/templates/html/drag_and_drop.html'))
        css_urls = (
            'public/css/vendor/jquery-ui-1.10.4.custom.min.css',
            'public/css/vendor/bootstrap.min.css',
            'public/css/drag_and_drop.css'
        )
        js_urls = (
            'public/js/vendor/jquery-ui-1.10.4.custom.min.js',
            'public/js/vendor/jquery-ui-touch-punch-0.2.3.min.js',  # Makes it work on touch devices
            'public/js/vendor/virtual-dom-1.3.0.min.js',
            'public/js/drag_and_drop.js',
        )
        for css_url in css_urls:
            fragment.add_css_url(self.runtime.local_resource_url(self, css_url))
        for js_url in js_urls:
            fragment.add_javascript_url(self.runtime.local_resource_url(self, js_url))

        self.include_theme_files(fragment)
        fragment.initialize_js('DragAndDropBlock', self.get_configuration())

        return fragment
コード例 #21
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
コード例 #22
0
    def student_view(self, context=None):
        """
        The primary view of the RichReviewXBlock, shown to students
        when viewing courses.
        """
        frag = Fragment()
        frag.add_css(load_resource("static/css/richreview.css"))
        frag.add_javascript(load_resource("static/js/src/richreview_student.js"))
        frag.add_content(render_template(
                "templates/richreview_student.html",
                {
                    'xblock_id': self.xblock_id,
                    'student_id': self.anonymous_student_id,
                    'user_is_staff': str(self.user_is_staff),
                    'students_of_group': str(self.students_of_group),
                    'group_of_student': str(self.group_of_student),
                    'discussion_docid': self.discussion_docid,

                    'is_debug': False,
                    'is_pdf_ready': self.is_pdf_ready
                }
            ))

        frag.initialize_js('RichReviewXBlock')
        return frag
コード例 #23
0
    def studio_view(self, context):
        """
        Отображение блока в студии.

        :param context:
        :return:
        """

        template_context = {
            'metadata': json.dumps({
                'display_name': self.display_name,
                'course_id': self.ant_course_id,
                'unit_id': self.ant_unit_id,
                'content': self.content,
                'time_limit': self.ant_time_limit,
                'attempts_limit': self.ant_attempts_limit,
                'attempts_url': self.attempts_url,
                'lab_url': self.lab_url,
                'weight': self.weight,
            }),
        }

        fragment = Fragment()
        fragment.add_content(self._render_template('static/templates/studio_view.html', template_context))
        fragment.add_javascript(self._get_resource('static/js/studio_view.js'))
        fragment.initialize_js('AntXBlockEdit')
        return fragment
コード例 #24
0
ファイル: mfu.py プロジェクト: CDOT-EDX/edx_mfu
	def studio_view(self, context=None):
		try:
			cls = type(self)

			def none_to_empty(x):
				return x if x is not None else ''
			edit_fields = (
				(field, none_to_empty(getattr(self, field.name)), validator)
				for field, validator in (
					(cls.display_name, 'string'),
					(cls.points, 'number'),
					(cls.weight, 'number'))
			)

			context = {
				'fields': edit_fields
			}
			fragment = Fragment()
			fragment.add_content(
				render_template(
					'templates/multiple_file_upload/edit.html',
					context
				)
			)
			fragment.add_javascript(_resource("static/js/src/studio.js"))
			fragment.initialize_js('MultipleFileUploadXBlock')
			return fragment
		except:  # pragma: NO COVER
			log.error("Don't swallow my exceptions", exc_info=True)
			raise
コード例 #25
0
    def studio_view(self, context=None):
        """
        This is the Studio settings page.
        The neat way of autogenerating it is from Staff Graded Assignment block.
        (Why isn't this the default anyway?)
        """
        cls = type(self)

        def none_to_empty(x):
            return x if x is not None else ''

        edit_fields = (
            (field, none_to_empty(getattr(self, field.name)), validator)
            for field, validator in (
                (cls.display_name, 'string'),
                (cls.capacity, 'number'),
                (cls.approval_required, 'boolean'),
                (cls.last_day, 'date_string'),
            ))

        html = self.resource_string('static/html/masterclass_studio.html')
        fragment = Fragment()
        fragment.add_content(self.render_template_from_string(html, fields=edit_fields))
        fragment.add_javascript(self.resource_string("static/js/src/masterclass_studio.js"))
        fragment.add_css(self.resource_string("static/css/masterclass.css"))
        fragment.initialize_js('MasterclassXBlockStudio')
        return fragment
コード例 #26
0
ファイル: iframe.py プロジェクト: jgrynber/iframe-id-xblock
    def student_view(self, context=None):
        """
        The primary view of the IframeWithAnonymousIDXBlock, shown to students
        when viewing courses.
        """

        student_id = self.xmodule_runtime.anonymous_student_id
        # student_id will be "student" if called from the Studio

        new_iframe_url = "{0}/{1}".format(self.iframe_url, student_id)

        self.display_name = new_iframe_url

        context = {
            'self': self,
            'iframe_url': new_iframe_url,
            'is_in_studio': student_id == 'student'
        }

        frag = Fragment()
        frag.add_content(render_template('/templates/html/iframe.html', context))
        frag.add_css(self.resource_string("static/css/iframe.css"))
        frag.add_javascript(self.resource_string("static/js/src/iframe.js"))
        frag.initialize_js('IframeWithAnonymousIDXBlock')
        return frag
コード例 #27
0
ファイル: sga.py プロジェクト: eduStack/edx-sga
    def student_view(self, context=None):
        # pylint: disable=no-member
        """
        The primary view of the StaffGradedAssignmentXBlock, shown to students
        when viewing courses.
        """
        context = {
            "student_state": json.dumps(self.student_state()),
            "id": self.location.name.replace('.', '_'),
            "max_file_size": getattr(
                settings, "STUDENT_FILEUPLOAD_MAX_SIZE",
                self.STUDENT_FILEUPLOAD_MAX_SIZE
            )
        }
        if self.show_staff_grading_interface():
            context['is_course_staff'] = True
            self.update_staff_debug_context(context)

        fragment = Fragment()
        fragment.add_content(
            render_template(
                'templates/staff_graded_assignment/show.html',
                context
            )
        )
        fragment.add_css(_resource("static/css/edx_sga.css"))
        fragment.add_javascript(_resource("static/js/src/edx_sga.js"))
        fragment.add_javascript(_resource("static/js/src/jquery.tablesorter.min.js"))
        fragment.initialize_js('StaffGradedAssignmentXBlock')
        return fragment
コード例 #28
0
    def student_view(self, context):
        """
        Renders the student view of the block in the LMS.
        """
        fragment = Fragment()
        contents = []

        child_context = {} if not context else copy(context)
        child_context['child_of_vertical'] = True

        # pylint: disable=no-member
        for child in self.get_display_items():
            rendered_child = child.render(STUDENT_VIEW, child_context)
            fragment.add_frag_resources(rendered_child)

            contents.append({
                'id': child.location.to_deprecated_string(),
                'content': rendered_child.content
            })

        fragment.add_content(self.system.render_template('vert_module.html', {
            'items': contents,
            'xblock_context': context,
        }))
        return fragment
コード例 #29
0
    def dashboard_view(self, context):
        """
        Renders stage content for dashboard view.
        :param dict context:
        :rtype: Fragment
        """
        fragment = Fragment()

        target_workgroups = context.get(Constants.TARGET_WORKGROUPS)
        target_students = context.get(Constants.TARGET_STUDENTS)
        filtered_students = context.get(Constants.FILTERED_STUDENTS)

        students_to_display = [student for student in target_students if student.id not in filtered_students]

        state, stats = self.get_dashboard_stage_state(target_workgroups, students_to_display)
        human_stats = OrderedDict([
            (StageState.get_human_name(StageState.NOT_STARTED), stats[StageState.NOT_STARTED]*100),
            (StageState.get_human_name(StageState.INCOMPLETE), stats[StageState.INCOMPLETE]*100),
            (StageState.get_human_name(StageState.COMPLETED), stats[StageState.COMPLETED]*100),
        ])
        render_context = {
            'stage': self, 'stats': human_stats, 'stage_state': state, 'ta_graded': self.activity.is_ta_graded
        }
        render_context.update(context)
        fragment.add_content(self.render_template('dashboard_view', render_context))
        return fragment
コード例 #30
0
    def author_view(self, context):
        if self.question:
            return self.student_view(context)

        fragment = Fragment()
        fragment.add_content(messages.QUESTION_NOT_SELECTED)
        return fragment
コード例 #31
0
ファイル: preview.py プロジェクト: gopinath81/vmss
    def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
        position_for_asides = '<!-- footer for xblock_aside -->'
        result = Fragment()
        result.add_frag_resources(frag)

        for aside, aside_fn in aside_frag_fns:
            aside_frag = aside_fn(block, context)
            if aside_frag.content != u'':
                aside_frag_wrapped = self.wrap_aside(block, aside, view_name, aside_frag, context)
                aside.save()
                result.add_frag_resources(aside_frag_wrapped)
                replacement = position_for_asides + aside_frag_wrapped.content
                frag.content = frag.content.replace(position_for_asides, replacement)

        result.add_content(frag.content)
        return result
コード例 #32
0
 def student_view(self, context=None):
     """
     The primary view of the InfoSecureXBlock, shown to students
     when viewing courses.
     """
     context = {
         "display_name": self.display_name,
     }
     fragment = Fragment()
     fragment.add_content(
         render_template("static/html/infosecurexblock.html", context))
     js_urls = ("static/js/src/infosecurexblock.js", )
     css_urls = ("static/css/infosecurexblock.css", )
     load_resources(js_urls, css_urls, fragment)
     fragment.initialize_js('InfoSecureXBlock')
     return fragment
コード例 #33
0
    def studio_view(self, context):
        """
        Studio edit view
        """

        fragment = Fragment()
        fragment.add_content(
            render_template('templates/html/carousel_edit.html', {
                'self': self,
            }))
        fragment.add_javascript(
            load_resource('public/js/jquery-ui-1.10.4.custom.js'))
        fragment.add_javascript(load_resource('public/js/carousel_edit.js'))
        fragment.initialize_js('CarouselEditBlock')

        return fragment
コード例 #34
0
ファイル: mentoring.py プロジェクト: naeem91/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_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.initialize_js(
            'MentoringWithStepsBlock', {
                'show_extended_feedback': self.show_extended_feedback(),
            })

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

        children_context = self._sanitize_context(context)
        self._add_students_and_workgroups_to_context(children_context)

        activity_fragments = self._render_children('dashboard_view', children_context, self.activities)
        activity_contents = [frag.content for frag in activity_fragments]
        fragment.add_frags_resources(activity_fragments)

        render_context = {'project': self, 'activity_contents': activity_contents}
        fragment.add_content(self.render_template('dashboard_view', render_context))
        add_resource(self, 'css', 'public/css/group_project_common.css', fragment)
        add_resource(self, 'css', 'public/css/group_project_dashboard.css', fragment)
        add_resource(self, 'css', 'public/css/vendor/font-awesome/font-awesome.css', fragment, via_url=True)

        return fragment
コード例 #36
0
    def react_view(self, context):
        """
        Student view using React.js
        """
        fragment = Fragment()
        fragment.add_content(render_template('/templates/index.html'))
        js_urls = (
            'public/js/drag_and_drop_react.js', 'public/js/bundle.js'
            # the order of these js files is important so that functions are defined by the time they're called
        )

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

        fragment.initialize_js('DragAndDropReact')
        return fragment
コード例 #37
0
    def student_view(self, context):  # pylint: disable=unused-argument
        """
        Player view, displayed to the student
        """
        fragment = Fragment()

        fragment.add_content(RESOURCE_LOADER.render_template(CALENDAR_TEMPLATE, {
            "mode": self.views[self.default_view][1],
            "src": self.calendar_id,
            "title": self.display_name,
        }))
        fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_calendar.css'))
        fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_calendar.js'))

        fragment.initialize_js('GoogleCalendarBlock')

        return fragment
コード例 #38
0
    def studio_view(self, context):  # pylint: disable=unused-argument
        """
        Editing view in Studio
        """
        fragment = Fragment()
        # Need to access protected members of fields to get their default value
        fragment.add_content(RESOURCE_LOADER.render_template(CALENDAR_EDIT_TEMPLATE, {
            'self': self,
            'defaultName': self.fields['display_name']._default,  # pylint: disable=protected-access
            'defaultID': self.fields['calendar_id']._default  # pylint: disable=protected-access
        }))
        fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_calendar_edit.js'))
        fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_edit.css'))

        fragment.initialize_js('GoogleCalendarEditBlock')

        return fragment
コード例 #39
0
    def mobi_student_view(self, context):
        fragment = Fragment()
        contents = []

        for child in self.get_display_items():
            rendered_child = child.render('mobi_student_view', context)
            fragment.add_frag_resources(rendered_child)

            contents.append({
                'id': child.id,
                'content': rendered_child.content
            })

        fragment.add_content(
            self.system.render_template('vert_module.html',
                                        {'items': contents}))
        return fragment
コード例 #40
0
    def student_view(self, context=None):
        """
        The primary view of the StudioInputXBlock, shown to students
        when viewing courses.
        """
        context = {
            'inputs': self.content,
        }

        frag = Fragment()
        template = env.get_template("studioinput.html")
        frag.add_content(template.render(**context))
        frag.add_css(self.resource_string("static/css/studioinput.css"))
        frag.add_javascript(
            self.resource_string("static/js/src/studioinput.js"))
        frag.initialize_js('StudioInputXBlock')
        return frag
コード例 #41
0
    def studio_view(self, context):
        """
        Editing view in Studio
        """
        fragment = Fragment()
        fragment.add_content(
            render_template('/templates/html/group_project_edit.html', {
                'self': self,
            }))
        fragment.add_css(load_resource('public/css/group_project_edit.css'))

        fragment.add_javascript(
            load_resource('public/js/group_project_edit.js'))

        fragment.initialize_js('GroupProjectEditBlock')

        return fragment
コード例 #42
0
    def studio_view(self, context):
        """
        Editing view in Studio
        """
        fragment = Fragment()
        fragment.add_content(
            loader.render_django_template(
                '/templates/html/image_explorer_edit.html',
                context={'self': self},
                i18n_service=self.runtime.service(self, 'i18n')))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(
                self, 'public/js/image_explorer_edit.js'))

        fragment.initialize_js('ImageExplorerEditBlock')

        return fragment
コード例 #43
0
    def student_view(self, context=None):
        """
        The primary view of the JennystartXBlock, shown to students
        when viewing courses.
        """

        student_id=self.runtime.anonymous_student_id
        base_path="/edx/var/edxapp/staticfiles/ucore/"
	real_user = self.runtime.get_real_user(student_id)
	username = real_user.username
        
        conn = pymongo.Connection('localhost', 27017)
        db = conn.test
        codeview = db.codeview
        result = codeview.find_one({"username":username})
        conn.disconnect()
        
	self.logger.info(username + " start edit")
        if result:
            relative_path = result["view_file"]
	    self.lab = result["lab"]
            self.file_path = base_path + student_id + relative_path
	    self.logger.info("file " + relative_path)
	    output=open(self.file_path)
            self.codeData =output.read()
            output.close()
        else:
            relative_path = "please enter file path"
	    self.file_path = relative_path       
        
        context_dict={"file":relative_path,"codeData":self.codeData}

        fragment = Fragment()
        fragment.add_content(Util.render_template("static/html/jennystart.html",context_dict) )
        fragment.add_css(Util.load_resource("static/css/jennystart.css"))
        fragment.add_css(Util.load_resource("static/css/codemirror.css"))
        fragment.add_css(Util.load_resource("static/css/fullscreen.css"))
      
        fragment.add_javascript(Util.load_resource("static/js/src/jennystart.js"))
        fragment.add_javascript(Util.load_resource("static/js/src/codemirror.js"))
        fragment.add_javascript(Util.load_resource("static/js/src/active-line.js"))
        fragment.add_javascript(Util.load_resource("static/js/src/clike.js"))
        fragment.add_javascript(Util.load_resource("static/js/src/matchbrackets.js"))
        fragment.add_javascript(Util.load_resource("static/js/src/fullscreen.js"))
        fragment.initialize_js('JennystartXBlock')
        return fragment
コード例 #44
0
    def studio_view(self, context):
        """
        Editing view in Studio
        """
        fragment = Fragment()
        fragment.add_content(loader.render_template('templates/html/mentoring_edit.html', {
            'self': self,
            'xml_content': self.xml_content,
        }))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self, 'public/js/mentoring_edit.js'))
        fragment.add_css_url(
            self.runtime.local_resource_url(self, 'public/css/mentoring_edit.css'))

        fragment.initialize_js('MentoringEditBlock')

        return fragment
コード例 #45
0
    def _view_render(self, context, view='student_view'):
        stage_fragment = self.get_stage_content_fragment(context, view)

        fragment = Fragment()
        fragment.add_frag_resources(stage_fragment)
        render_context = {
            'stage': self,
            'stage_content': stage_fragment.content,
            "ta_graded": self.activity.group_reviews_required_count
        }
        fragment.add_content(
            loader.render_template(self.STAGE_WRAPPER_TEMPLATE,
                                   render_context))
        if stage_fragment.js_init_fn:
            fragment.initialize_js(stage_fragment.js_init_fn)

        return fragment
コード例 #46
0
 def studio_view(self, context=None):
     """
     The primary view of the TestXBlock, shown to students
     when viewing courses.
     """
     context = {
         'eassy_title': self.eassy_title
         # 'eassy_text': self.eassy_text,
     }
     frag = Fragment()
     template = env.get_template('testxblock_edit.html')
     frag.add_content(template.render(**context))
     frag.add_css(self.resource_string("static/css/testxblock_edit.css"))
     frag.add_javascript(
         self.resource_string("static/js/src/testxblock_edit.js"))
     frag.initialize_js('TestXBlockEdit')
     return frag
コード例 #47
0
 def student_view(self, context):
     fragment = Fragment()
     render_context = {
         'selector': self,
         'review_subjects': self.get_review_subject_repr()
     }
     render_context.update(context)
     add_resource(self, 'css',
                  "public/css/components/review_subject_selector.css",
                  fragment)
     add_resource(self, 'javascript',
                  "public/js/components/review_subject_selector.js",
                  fragment)
     fragment.add_content(
         loader.render_template(self.STUDENT_TEMPLATE, render_context))
     fragment.initialize_js('ReviewSubjectSelectorXBlock')
     return fragment
コード例 #48
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
コード例 #49
0
    def mobi_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('mobi_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('wechat/mobi_seq_module.html', params))

        return fragment
コード例 #50
0
    def student_view(self, context=None):
        """
        The primary view of the CohortXBlock, shown to students
        when viewing courses.
        """

        user = User.objects.get(id=self.scope_ids.user_id)

        context.update({"self": self, "user": user})
        fragment = Fragment()
        fragment.add_content(
            loader.render_template("static/html/cohortxblock.html", context))
        fragment.add_javascript(
            loader.render_template("static/js/src/cohortxblock.js", context))
        fragment.add_css(self.resource_string("static/css/cohortxblock.css"))
        fragment.initialize_js('CohortXBlock')
        return fragment
コード例 #51
0
    def student_view(self, context=None):
        """
        View shown to students.
        """
        context = self.student_view_data(context=context)
        context.update(self._get_user_state())

        fragment = Fragment()
        fragment.add_content(
            loader.render_template("templates/eoc_journal.html", context))
        fragment.add_css_url(
            self.runtime.local_resource_url(self,
                                            "public/css/eoc_journal.css"))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self, "public/js/eoc_journal.js"))
        fragment.initialize_js("EOCJournalXBlock")
        return fragment
コード例 #52
0
    def navigation_view(self, context):
        fragment = Fragment()

        children_context = {}
        children_context.update(context)

        stage_fragments = self._render_children('navigation_view',
                                                children_context,
                                                self.available_stages)
        stage_contents = [frag.content for frag in stage_fragments]
        fragment.add_frags_resources(stage_fragments)

        render_context = {'activity': self, 'stage_contents': stage_contents}
        fragment.add_content(
            self.render_template('navigation_view', render_context))

        return fragment
コード例 #53
0
ファイル: plot.py プロジェクト: ovnicraft/problem-builder
 def student_view(self, context=None):
     """ Student View """
     context = context.copy() if context else {}
     context['hide_header'] = True
     context['self'] = self
     fragment = Fragment()
     fragment.add_content(
         loader.render_template('templates/html/plot.html', context))
     fragment.add_css_url(
         self.runtime.local_resource_url(self, 'public/css/plot.css'))
     fragment.add_javascript_url(
         self.runtime.local_resource_url(self,
                                         'public/js/vendor/d3.min.js'))
     fragment.add_javascript_url(
         self.runtime.local_resource_url(self, 'public/js/plot.js'))
     fragment.initialize_js('PlotBlock')
     return fragment
コード例 #54
0
    def studio_view(self, context):
        """
        Editing view in Studio
        """

        js_templates = loader.load_unicode('/templates/html/js_templates.html')
        help_texts = {
            field_name: self._(field.help)
            for field_name, field in self.fields.viewitems()
            if hasattr(field, "help")
        }
        context = {
            'js_templates': js_templates,
            'help_texts': help_texts,
            'self': self,
            'data': urllib.quote(json.dumps(self.data)),
        }

        fragment = Fragment()
        fragment.add_content(
            loader.render_template('/templates/html/drag_and_drop_edit.html',
                                   context))

        css_urls = ('public/css/vendor/jquery-ui-1.10.4.custom.min.css',
                    'public/css/drag_and_drop_edit.css')
        js_urls = (
            'public/js/vendor/jquery-ui-1.10.4.custom.min.js',
            'public/js/vendor/handlebars-v1.1.2.js',
            'public/js/drag_and_drop_edit.js',
        )
        for css_url in css_urls:
            fragment.add_css_url(self.runtime.local_resource_url(
                self, css_url))
        for js_url in js_urls:
            fragment.add_javascript_url(
                self.runtime.local_resource_url(self, js_url))

        fragment.initialize_js(
            'DragAndDropEditBlock', {
                'data': self.data,
                'target_img_expanded_url': self.target_img_expanded_url,
                'default_background_image_url':
                self.default_background_image_url,
            })

        return fragment
コード例 #55
0
 def selector_view(self, _context):
     """
     Selector view - this view is used by GroupProjectNavigatorXBlock to render selector buttons
     """
     fragment = Fragment()
     context = {
         'type': self.type,
         'display_name': self.display_name_with_default,
         'skip_content': self.skip_content
     }
     for attribute in ['icon', 'selector_text']:
         if getattr(self, attribute, None) is not None:
             context[attribute] = getattr(self, attribute)
         else:
             context[attribute] = ''
     fragment.add_content(loader.render_template('templates/html/project_navigator/view_selector.html', context))
     return fragment
コード例 #56
0
    def _staff_view(self, context):
        """
        Render the staff view for a split test module.
        """
        fragment = Fragment()
        active_contents = []
        inactive_contents = []

        for child_location in self.children:  # pylint: disable=no-member
            child_descriptor = self.get_child_descriptor_by_location(child_location)
            child = self.system.get_module(child_descriptor)
            rendered_child = child.render(STUDENT_VIEW, context)
            fragment.add_frag_resources(rendered_child)
            group_name, updated_group_id = self.get_data_for_vertical(child)

            if updated_group_id is None:  # inactive group
                group_name = child.display_name
                updated_group_id = [g_id for g_id, loc in self.group_id_to_child.items() if loc == child_location][0]
                inactive_contents.append({
                    'group_name': _(u'{group_name} (inactive)').format(group_name=group_name),
                    'id': child.location.to_deprecated_string(),
                    'content': rendered_child.content,
                    'group_id': updated_group_id,
                })
                continue

            active_contents.append({
                'group_name': group_name,
                'id': child.location.to_deprecated_string(),
                'content': rendered_child.content,
                'group_id': updated_group_id,
            })

        # Sort active and inactive contents by group name.
        sorted_active_contents = sorted(active_contents, key=itemgetter('group_name'))
        sorted_inactive_contents = sorted(inactive_contents, key=itemgetter('group_name'))

        # Use the new template
        fragment.add_content(self.system.render_template('split_test_staff_view.html', {
            'items': sorted_active_contents + sorted_inactive_contents,
        }))
        fragment.add_css('.split-test-child { display: none; }')
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_staff.js'))
        fragment.initialize_js('ABTestSelector')
        return fragment
コード例 #57
0
    def student_view(self, context):
        """
        Student view
        """
        fragment = Fragment()
        children_items = []
        for view in self._sorted_child_views():
            item = {
                'id': str(view.scope_ids.usage_id).replace("/", ";_"),
                'type': view.type,
            }

            if not view.skip_content:
                child_fragment = view.render('student_view', context)
                item['content'] = child_fragment.content
                fragment.add_frag_resources(child_fragment)
            else:
                item['content'] = ''

            if not view.skip_selector:
                child_selector_fragment = view.render('selector_view', context)
                item['selector'] = child_selector_fragment.content
                fragment.add_frag_resources(child_selector_fragment)
            else:
                item['selector'] = ''

            children_items.append(item)

        activate_block_id = self.get_block_id_from_string(context.get('activate_block_id', None))

        js_parameters = {
            'selected_view': self._get_activated_view_type(activate_block_id)
        }

        fragment.add_content(
            loader.render_template(
                'templates/html/project_navigator/project_navigator.html',
                {'children': children_items}
            )
        )
        add_resource(self, 'css', 'public/css/project_navigator/project_navigator.css', fragment)
        add_resource(self, 'javascript', 'public/js/project_navigator/project_navigator.js', fragment)
        fragment.initialize_js("GroupProjectNavigatorBlock", js_parameters)

        return fragment
コード例 #58
0
ファイル: step.py プロジェクト: musmanmalik/problem-builder
    def _render_view(self, context, view):
        """ Actually renders a view """
        rendering_for_studio = False
        if context:  # Workbench does not provide context
            rendering_for_studio = context.get('author_preview_view')

        fragment = Fragment()
        child_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_contents.append(u"<p>[{}]</p>".format(
                    self._(u"Error: Unable to load child component.")))
            else:
                if rendering_for_studio and isinstance(child, PlotBlock):
                    # Don't use view to render plot blocks in Studio.
                    # This is necessary because:
                    # - student_view of plot block uses submissions API to retrieve results,
                    #   which causes "SubmissionRequestError" in Studio.
                    # - author_preview_view does not supply JS code for plot that JS code for step depends on
                    #   (step calls "update" on plot to get latest data during rendering).
                    child_contents.append(u"<p>{}</p>".format(
                        child.display_name))
                else:
                    child_fragment = self._render_child_fragment(
                        child, context, view)
                    fragment.add_frag_resources(child_fragment)
                    child_contents.append(child_fragment.content)

        fragment.add_content(
            loader.render_django_template('templates/html/step.html', {
                'self': self,
                'title': self.display_name,
                'show_title': self.show_title,
                'child_contents': child_contents,
            },
                                          i18n_service=self.i18n_service))

        fragment.add_javascript(self.get_translation_content())
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self, 'public/js/step.js'))
        fragment.initialize_js('MentoringStepBlock')

        return fragment
コード例 #59
0
 def submissions_view(self, context):
     fragment = Fragment()
     uploading_allowed = (
         self.stage.available_now
         and self.stage.is_group_member) or self.stage.is_admin_grader
     render_context = {
         'submission': self,
         'upload': self.upload,
         'disabled': not uploading_allowed
     }
     render_context.update(context)
     fragment.add_content(
         loader.render_template(self.PROJECT_NAVIGATOR_VIEW_TEMPLATE,
                                render_context))
     add_resource(self, 'javascript', 'public/js/components/submission.js',
                  fragment)
     fragment.initialize_js("GroupProjectSubmissionBlock")
     return fragment
コード例 #60
0
 def studio_view(self, context=None):
     """
     The editor view of the ReflectionAssistantXBlock, shown to course
     authors when editing courses in edX Studio.
     """
     frag = Fragment()
     frag.add_content(
         render_template(
             "/templates/html/reflection_prep_edit.html", {"self": self, })
     )
     frag.add_css(
         self.resource_string("static/css/reflection.css")
     )
     frag.add_javascript(
         self.resource_string("static/js/src/reflection_prep_edit.js")
     )
     frag.initialize_js('ReflectionAssistantPrepXBlock', self.get_config())
     return frag