Example #1
0
    def student_view(self, context=None):
        """
        The primary view of the EdflexXBlock, shown to students
        when viewing courses.
        """
        if context is None:
            context = {}

        context.update({
            'svg_sprite':
            self.resource_string('public/images/sprite.svg'),
        })

        self.update_student_context(context)
        fragment = Fragment()
        fragment.content = loader.render_django_template(
            'static/html/edflex.html', context)
        fragment.add_css(self.resource_string("static/css/edflex.css"))

        if self.resource.get('type', '') == 'video':
            fragment.add_javascript_url('https://www.youtube.com/iframe_api')

        fragment.add_javascript(
            loader.load_unicode('static/js/src/parse_duration.js'))
        fragment.add_javascript(
            self.resource_string("static/js/src/edflex.js"))
        fragment.initialize_js('EdflexXBlock')
        return fragment
Example #2
0
    def student_view(self, context=None):
        """
        The primary view of the CodeSnippetXBlock, shown to students
        when viewing courses.
        """
        frag = Fragment()
        frag.content = loader.render_django_template(
            'templates/code_snippet.html', self._get_context())
        frag.add_css(self.resource_string("static/css/code_snippet.css"))
        frag.add_css_url(
            "//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/styles/agate.min.css"
        )

        logger.info("{}".format(self._get_context()))

        # Add i18n js
        statici18n_js_url = self._get_statici18n_js_url()
        if statici18n_js_url:
            frag.add_javascript_url(
                self.runtime.local_resource_url(self, statici18n_js_url))

        frag.add_javascript(
            self.resource_string("static/js/src/code_snippet.js"))
        frag.add_javascript_url(
            "//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/highlight.min.js"
        )
        frag.initialize_js('CodeSnippetXBlock', self._get_context())
        return frag
Example #3
0
 def studio_view(self, context):
     """
     Render a form for editing this XBlock
     """
     init_values = {
         'format': self.format,
         'category': self.category,
         'catalog': self.catalog,
         'language': self.language,
         'resource': self.resource,
     }
     context.update({
         'svg_sprite':
         self.resource_string('public/images/sprite.svg'),
     })
     self.update_studio_context(context)
     fragment = Fragment()
     fragment.content = loader.render_django_template(
         'static/html/studio_edit.html', context)
     fragment.add_css(self.resource_string("static/css/edflex.css"))
     fragment.add_css(self.resource_string("static/css/select2.css"))
     fragment.add_javascript(
         loader.load_unicode('static/js/src/parse_duration.js'))
     fragment.add_javascript(
         loader.load_unicode('static/js/src/studio_edit.js'))
     fragment.initialize_js('StudioEditableEdflexXBlock',
                            json_args={
                                'url_select2':
                                self.runtime.local_resource_url(
                                    self, 'public/js/select2.min'),
                                'init_values':
                                init_values
                            })
     return fragment
    def studio_view(self, context):
        """
        Render a form for editing this XBlock
        """
        fragment = Fragment()
        static_content = ResourceLoader(
            'common.djangoapps.pipeline_mako').load_unicode(
                'templates/static_content.html')
        render_react = MakoTemplate(static_content,
                                    default_filters=[]).get_def('renderReact')
        react_content = render_react.render(
            component="LibrarySourcedBlockPicker",
            id="library-sourced-block-picker",
            props={
                'selectedXblocks': self.source_block_ids,
            })
        fragment.content = loader.render_django_template(
            'templates/library-sourced-block-studio-view.html', {
                'react_content': react_content,
                'save_url': self.runtime.handler_url(self,
                                                     'submit_studio_edits'),
            })

        fragment.add_javascript_url(
            self.runtime.local_resource_url(
                self, 'public/js/library_source_block.js'))
        fragment.initialize_js('LibrarySourceBlockStudioView')

        return fragment
    def author_view(self, context=None):
        """
        Render a form for editing this XBlock
        """
        fragment = Fragment()

        parent_block = self.runtime.get_block(self.parent)
        video_options = self._get_options(parent_block, 'video')

        problem_options = self._get_options(parent_block, 'problem')

        # convert map of times to blocks, to one of blocks to times
        blocktimemap = {}
        saved_timemap = {}
        if self.timemap:
            saved_timemap = json.loads(self.timemap)
        if isinstance(saved_timemap, dict):
            for time, block_id in saved_timemap.iteritems():
                blocktimemap[block_id] = time

        processed_timemap = []
        for problem in problem_options:
            if blocktimemap.get(problem['block_id']):
                processed_timemap.append({
                    'time':
                    blocktimemap.get(problem['block_id'], ''),
                    'block_id':
                    problem['block_id'],
                    'label':
                    problem['label'],
                })

        self.debug_info['video_options'] = video_options
        self.debug_info['self.video_id'] = self.video_id
        self.debug_info['has_videos'] = bool(
            self.video_id) and len(video_options) > 0

        context = {
            'video_id': self.video_id,
            'video_options': video_options,
            'timemap': processed_timemap,
            'debug_info': self.debug_info,
            'has_videos': bool(self.video_id) and len(video_options) > 0,
            'has_problem_components': len(processed_timemap) > 0,
        }

        fragment.content = loader.render_template(
            'templates/studio_invideo_author.html', context)
        return fragment
    def studio_view(self, context):
        """
        Render a form for editing this XBlock
        """
        fragment = Fragment()

        parent_block = self.runtime.get_block(self.parent)
        video_options = self._get_options(parent_block, 'video')

        problem_options = self._get_options(parent_block, 'problem')

        # convert map of times to blocks, to one of blocks to times
        blocktimemap = {}
        saved_timemap = {}
        if self.timemap:
            saved_timemap = json.loads(self.timemap)
        if isinstance(saved_timemap, dict):
            for time, block_id in saved_timemap.iteritems():
                blocktimemap[block_id] = time
        # self.debug_info['self.timemap'] = self.timemap
        # self.debug_info['self.video_id'] = self.video_id

        processed_timemap = []
        for problem in problem_options:
            processed_timemap.append({
                'time':
                blocktimemap.get(problem['block_id'], ''),
                'block_id':
                problem['block_id'],
                'label':
                problem['label'],
            })

        context = {
            'video_id': self.video_id,
            'video_options': video_options,
            'timemap': processed_timemap,
            'debug_info': self.debug_info,
            'has_videos': len(video_options) > 0,
            'has_problem_components': len(processed_timemap) > 0,
        }

        fragment.content = loader.render_template(
            'templates/studio_invideo_edit.html', context)
        fragment.add_javascript(loader.load_unicode('public/studio_edit.js'))
        fragment.initialize_js('StudioEditableXBlockMixin')
        return fragment
Example #7
0
 def studio_view(self, context):
     """
     Render a form for editing this XBlock
     """
     fragment = Fragment()
     context = {'fields': []}
     # Build a list of all the fields that can be edited:
     for field_name in self.editable_fields:
         field = self.fields[field_name]
         assert field.scope in (Scope.content, Scope.settings), (
             "Only Scope.content or Scope.settings fields can be used with "
             "StudioEditableXBlockMixin. Other scopes are for user-specific data and are "
             "not generally created/configured by content authors in Studio."
         )
         field_info = self._make_field_info(field_name, field)
         if field_info is not None:
             context["fields"].append(field_info)
     fragment.content = loader.render_django_template(
         'templates/studio_edit.html', context)
     fragment.add_javascript(loader.load_unicode('public/studio_edit.js'))
     fragment.initialize_js('StudioEditableXBlockMixin')
     return fragment
Example #8
0
    def studio_view(self, context=None):
        """
        The primary view of the CodeSnippetXBlock, shown to students
        when viewing courses.
        """
        frag = Fragment()
        frag.content = loader.render_django_template(
            'templates/studio_view.html', self._get_context())

        frag.add_css(
            self.resource_string("static/css/code_snippet_studio.css"))

        # Add i18n js
        statici18n_js_url = self._get_statici18n_js_url()
        if statici18n_js_url:
            frag.add_javascript_url(
                self.runtime.local_resource_url(self, statici18n_js_url))

        frag.add_javascript(
            self.resource_string("static/js/src/code_snippet_studio.js"))
        frag.initialize_js('CodeSnippetStudioXBlock')

        return frag