Exemplo n.º 1
0
    def student_view_aside(self, block, context):  # pylint: disable=unused-argument
        """
        Display the tag selector with specific categories and allowed values,
        depending on the context.
        """
        if isinstance(block, CapaModule):
            tags = []
            for tag in self.get_available_tags():
                tag_available_values = tag.get_values()
                tag_current_values = self.saved_tags.get(tag.name, [])

                if isinstance(tag_current_values, basestring):
                    tag_current_values = [tag_current_values]

                tag_values_not_exists = [cur_val for cur_val in tag_current_values
                                         if cur_val not in tag_available_values]

                tag_values_available_to_choose = tag_available_values + tag_values_not_exists
                tag_values_available_to_choose.sort()

                tags.append({
                    'key': tag.name,
                    'title': tag.title,
                    'values': tag_values_available_to_choose,
                    'current_values': tag_current_values,
                })
            fragment = Fragment(render_to_string('structured_tags_block.html', {'tags': tags,
                                                                                'tags_count': len(tags),
                                                                                'block_location': block.location}))
            fragment.add_javascript_url(self._get_studio_resource_url('/js/xblock_asides/structured_tags.js'))
            fragment.initialize_js('StructuredTagsInit')
            return fragment
        else:
            return Fragment(u'')
    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
    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
                context['can_move'] = 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
Exemplo n.º 4
0
    def student_view(self, context):
        """
        Renders the student view of the block in the LMS.
        """
        fragment = Fragment()
        contents = []

        if context:
            child_context = copy(context)
        else:
            child_context = {}

        if 'bookmarked' not in child_context:
            bookmarks_service = self.runtime.service(self, 'bookmarks')
            child_context['bookmarked'] = bookmarks_service.is_bookmarked(usage_key=self.location),  # pylint: disable=no-member
        if 'username' not in child_context:
            user_service = self.runtime.service(self, 'user')
            child_context['username'] = user_service.get_current_user().opt_attrs['edx-platform.username']

        child_blocks = self.get_display_items()

        child_blocks_to_complete_on_view = set()
        completion_service = self.runtime.service(self, 'completion')
        if completion_service and completion_service.completion_tracking_enabled():
            child_blocks_to_complete_on_view = completion_service.blocks_to_mark_complete_on_view(child_blocks)
            complete_on_view_delay = completion_service.get_complete_on_view_delay_ms()

        child_context['child_of_vertical'] = True
        is_child_of_vertical = context.get('child_of_vertical', False)

        # pylint: disable=no-member
        for child in child_blocks:
            child_block_context = copy(child_context)
            if child in child_blocks_to_complete_on_view:
                child_block_context['wrap_xblock_data'] = {
                    'mark-completed-on-view-after-delay': complete_on_view_delay
                }
            rendered_child = child.render(STUDENT_VIEW, child_block_context)
            fragment.add_fragment_resources(rendered_child)

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

        fragment.add_content(self.system.render_template('vert_module.html', {
            'items': contents,
            'xblock_context': context,
            'unit_title': self.display_name_with_default if not is_child_of_vertical else None,
            'show_bookmark_button': child_context.get('show_bookmark_button', not is_child_of_vertical),
            'bookmarked': child_context['bookmarked'],
            'bookmark_id': u"{},{}".format(child_context['username'], unicode(self.location)),  # pylint: disable=no-member
        }))

        for tag in webpack_loader.utils.get_as_tags('VerticalStudentView'):
            fragment.add_resource(tag, mimetype='text/html', placement='head')
        fragment.initialize_js('VerticalStudentView')

        return fragment
Exemplo n.º 5
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_fragment_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_fragment_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_django_template(
                'templates/html/project_navigator/project_navigator.html',
                {'children': children_items},
                i18n_service=self.i18n_service,
            ))
        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.add_javascript(self.get_translation_content())
        fragment.initialize_js("GroupProjectNavigatorBlock", js_parameters)

        return fragment
    def _create_fragment(
        self,
        template,
        context_dict,
        initialize_js_func,
        additional_css=None,
        additional_js=None,
        additional_js_context=None
    ):
        """
        Creates a fragment for display.

        """
        fragment = Fragment(template.render(context_dict))

        if additional_css is None:
            additional_css = []
        if additional_js is None:
            additional_js = []

        i18n_service = self.runtime.service(self, 'i18n')
        if hasattr(i18n_service, 'get_language_bidi') and i18n_service.get_language_bidi():
            css_url = LoadStatic.get_url("openassessment-rtl.css")
        else:
            css_url = LoadStatic.get_url("openassessment-ltr.css")

        # TODO: load CSS and JavaScript as URLs once they can be served by the CDN
        for css in additional_css:
            fragment.add_css_url(css)
        fragment.add_css_url(css_url)

        # minified additional_js should be already included in 'make javascript'
        fragment.add_javascript_url(LoadStatic.get_url("openassessment-lms.js"))

        js_context_dict = {
            "ALLOWED_IMAGE_MIME_TYPES": self.ALLOWED_IMAGE_MIME_TYPES,
            "ALLOWED_FILE_MIME_TYPES": self.ALLOWED_FILE_MIME_TYPES,
            "FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST,
            "FILE_TYPE_WHITE_LIST": self.white_listed_file_types,
            "MAXIMUM_FILE_UPLOAD_COUNT": self.MAX_FILES_COUNT,
            "TEAM_ASSIGNMENT": self.is_team_assignment(),
            "AVAILABLE_EDITORS": AVAILABLE_EDITORS,
            "TEXT_RESPONSE_EDITOR": self.text_response_editor,
        }
        # If there's any additional data to be passed down to JS
        # include it in the context dict
        if additional_js_context:
            js_context_dict.update({"CONTEXT": additional_js_context})

        fragment.initialize_js(initialize_js_func, js_context_dict)
        return fragment
Exemplo n.º 7
0
 def author_view(self, _context):
     if not is_course_cohorted(
             self.course_id) or PROFS_COHORT not in super().get_cohorts():
         return Fragment(
             "Turmas têm que estar ativas e tem que existir uma turma chamada \"professores\""
         )
     data = {'xblock_id': self._get_xblock_loc()}
     html = loader.render_django_template('templates/author_view.html',
                                          data)
     frag = Fragment(html)
     frag.add_css(resource_string("static/css/profs_assignment.css"))
     frag.add_javascript(resource_string("static/js/turmas_assignment.js"))
     frag.initialize_js('PensamentoComputacionalXBlock', data)
     return frag
Exemplo n.º 8
0
    def student_view(self, context):
        """
        Renders the student view of the block in the LMS.
        """
        fragment = Fragment()
        contents = []

        if context:
            child_context = copy(context)
        else:
            child_context = {}

        if 'bookmarked' not in child_context:
            bookmarks_service = self.runtime.service(self, 'bookmarks')
            child_context['bookmarked'] = bookmarks_service.is_bookmarked(usage_key=self.location),  # pylint: disable=no-member
        if 'username' not in child_context:
            user_service = self.runtime.service(self, 'user')
            child_context['username'] = user_service.get_current_user().opt_attrs['edx-platform.username']

        completion_service = self.runtime.service(self, 'completion')

        child_context['child_of_vertical'] = True
        is_child_of_vertical = context.get('child_of_vertical', False)

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

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

        fragment.add_content(self.system.render_template('vert_module.html', {
            'items': contents,
            'xblock_context': context,
            'unit_title': self.display_name_with_default if not is_child_of_vertical else None,
            'show_bookmark_button': child_context.get('show_bookmark_button', not is_child_of_vertical),
            'bookmarked': child_context['bookmarked'],
            'bookmark_id': u"{},{}".format(child_context['username'], unicode(self.location)),  # pylint: disable=no-member
            'watched_completable_blocks': self.get_completable_by_viewing(completion_service),
            'completion_delay_ms': self.get_completion_delay_ms(completion_service),
        }))

        for tag in webpack_loader.utils.get_as_tags('VerticalStudentView'):
            fragment.add_resource(tag, mimetype='text/html', placement='head')
        fragment.initialize_js('VerticalStudentView')

        return fragment
Exemplo n.º 9
0
    def studio_view(self, context):
        """
        Create a fragment used to display the edit view in the Studio.
        """

        
        html = self.resource_string("static/html/studio_dcxblock.html")

        frag = Fragment(html.format(dc_cdn=self.dc_cdn, dc_grade=self.dc_grade, dc_code=self.dc_code, dc_student_tries=self.dc_student_tries, dc_id=self.dc_id))

        frag.add_javascript(self.resource_string("static/js/src/studio_dcxblock.js"))
        frag.initialize_js('DcXBlock')

        return frag
Exemplo n.º 10
0
 def student_view(self, context=None):
     """
     This view renders the hint view to the students. The HTML has the hints templated
     in, and most of the remaining functionality is in the JavaScript.
     """
     html = self.resource_string("static/html/crowdsourcehinter.html")
     frag = Fragment(html)
     frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js')
     frag.add_css(self.resource_string("static/css/crowdsourcehinter.css"))
     frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter.js"))
     frag.initialize_js('CrowdsourceHinter',
                        {'target_problem': self.target_problem,
                         'isStaff': self.get_user_is_staff()})
     return frag
Exemplo n.º 11
0
    def studio_view(self, context=None):

        # self.input_data = base64.b64encode(self.the_data.encode('ascii'))

        html = self.resource_string("static/html/studio_view.html")
        frag = Fragment(html.format(self=self))

        frag.add_javascript(
            self.resource_string("static/js/src/studio_view.js"))
        frag.add_javascript(
            self.resource_string("static/js/src/studio_view_ignition.js"))

        frag.initialize_js('CrespXBlockSetup')
        return frag
    def student_view(self, context=None):  # pylint: disable=W0613
        """
        Create a fragment used to display the XBlock to a student.
        `context` is a dictionary used to configure the display (unused)

        Returns a `Fragment` object specifying the HTML, CSS, and JavaScript
        to display.
        """

        # Load the HTML fragment from within the package and fill in the template
        html_str = pkg_resources.resource_string(
            __name__, "static/html/thumbs.html").decode('utf-8')
        frag = Fragment(str(html_str))

        if not self.fs.exists(u"thumbsvotes.json"):
            with self.fs.open(u'thumbsvotes.json', 'wb') as file_output:
                file_output.write(json.dumps({'up': 0, 'down': 0}).encode())
                file_output.close()

        votes = json.load(self.fs.open(u"thumbsvotes.json"))
        self.upvotes = votes['up']
        self.downvotes = votes['down']

        # Load the CSS and JavaScript fragments from within the package
        css_str = pkg_resources.resource_string(
            __name__, "static/css/thumbs.css").decode('utf-8')
        frag.add_css(str(css_str))

        js_str = pkg_resources.resource_string(
            __name__, "static/js/src/thumbs.js").decode('utf-8')
        frag.add_javascript(str(js_str))

        with self.fs.open(u'uparrow.png', 'wb') as file_output:
            png.Writer(len(ARROW[0]), len(ARROW), greyscale=True,
                       bitdepth=1).write(file_output, ARROW)

        with self.fs.open(u'downarrow.png', 'wb') as file_output:
            png.Writer(len(ARROW[0]), len(ARROW), greyscale=True,
                       bitdepth=1).write(file_output, ARROW[::-1])

        frag.initialize_js(
            'FileThumbsBlock', {
                'up': self.upvotes,
                'down': self.downvotes,
                'voted': self.voted,
                'uparrow': self.fs.get_url('uparrow.png'),
                'downarrow': self.fs.get_url('downarrow.png')
            })
        return frag
Exemplo n.º 13
0
    def student_view(self, context):
        """
        LMS and CMS view for configurable_lti_consumer.
        Will make a post request to lti_launch_handler view with
        LTI parameters and open response in an iframe or a new window
        depending on the xblock instance configuration.
        Arguments:
            context (dict): XBlock context
        Returns:
            web_fragment.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        configurable_lti_consumer_loader = ResourceLoader(__name__)
        lti_consumer_loader = ResourceLoader(
            "lti_consumer")  # ressource loader of inherited lti_consumer
        context.update(self._get_context_for_template())
        fragment.add_css(
            lti_consumer_loader.load_unicode("static/css/student.css"))
        fragment.add_javascript(
            lti_consumer_loader.load_unicode(
                "static/js/xblock_lti_consumer.js"))

        configuration = self.get_configuration(self.launch_url)

        # Automatic resizing
        if configuration.get("automatic_resizing"):
            context["automatic_resizing"] = configuration["automatic_resizing"]
            fragment.add_javascript(
                configurable_lti_consumer_loader.load_unicode(
                    "static/js/vendor/iframeResizer.min.js"))
        else:
            context["automatic_resizing"] = None

        # Inline ratio
        context["inline_ratio"] = configuration.get("inline_ratio", None)

        fragment.add_javascript(
            configurable_lti_consumer_loader.load_unicode(
                "static/js/configurable_xblock_lti_consumer.js"))

        json_args = {"element_id": context["element_id"]}
        fragment.initialize_js(
            "configurableLTIConsumerXblockIframeResizerInit",
            json_args=json_args)

        fragment.add_content(
            configurable_lti_consumer_loader.render_mako_template(
                "/templates/html/student.html", context))
        return fragment
Exemplo n.º 14
0
    def student_view(self, context):
        """
        Renders the student view of the block in the LMS.
        """
        fragment = Fragment()
        contents = []

        if context:
            child_context = copy(context)
        else:
            child_context = {}

        if 'bookmarked' not in child_context:
            bookmarks_service = self.runtime.service(self, 'bookmarks')
            child_context['bookmarked'] = bookmarks_service.is_bookmarked(usage_key=self.location),  # pylint: disable=no-member
        if 'username' not in child_context:
            user_service = self.runtime.service(self, 'user')
            child_context['username'] = user_service.get_current_user().opt_attrs['edx-platform.username']

        completion_service = self.runtime.service(self, 'completion')

        child_context['child_of_vertical'] = True
        is_child_of_vertical = context.get('child_of_vertical', False)

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

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

        fragment.add_content(self.system.render_template('vert_module.html', {
            'items': contents,
            'xblock_context': context,
            'unit_title': self.display_name_with_default if not is_child_of_vertical else None,
            'show_bookmark_button': child_context.get('show_bookmark_button', not is_child_of_vertical),
            'bookmarked': child_context['bookmarked'],
            'bookmark_id': u"{},{}".format(child_context['username'], unicode(self.location)),  # pylint: disable=no-member
            'watched_completable_blocks': self.get_completable_by_viewing(completion_service),
            'completion_delay_ms': self.get_completion_delay_ms(completion_service),
        }))

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

        return fragment
Exemplo n.º 15
0
    def student_view(self, context=None):
        """
        The primary view of the ELabXBlock, shown to students
        when viewing courses.
        """
        context_html = {
            'title':
            self.title,
            'description':
            self.description,
            'programing_language':
            self.available_languages[self.programing_language],
            'student_content':
            self.student_contents,
            'student_inputs':
            self.student_inputs,
            'input_list':
            self.input_list,
            'grading_results':
            self.grading_results,
            'elabxblock_id':
            str(self.elabxblock_id)
        }
        template = loader.render_django_template('static/html/student.html',
                                                 context=context_html)

        frag = Fragment(template)
        frag.add_css(resource_string("static/css/elabxblock.css"))
        frag.add_javascript(resource_string("static/js/src/student.js"))
        frag.initialize_js(
            'Student', {
                'title':
                self.title,
                'description':
                self.description,
                'programing_language':
                self.available_languages[self.programing_language],
                'student_content':
                self.student_contents,
                'student_inputs':
                self.student_inputs,
                'input_list':
                self.input_list,
                'grading_results':
                self.grading_results,
                'elabxblock_id':
                str(self.elabxblock_id)
            })
        return frag
Exemplo n.º 16
0
 def student_view(self, context):
     fragment = Fragment()
     lti_loader = ResourceLoader('lti_consumer')
     loader = ResourceLoader(__name__)
     context = self._get_context_for_template()
     fragment.add_content(
         loader.render_mako_template('/templates/student.html', context))
     fragment.add_css(loader.load_unicode('static/css/student.css'))
     fragment.add_javascript(
         lti_loader.load_unicode('static/js/xblock_lti_consumer.js'))
     fragment.initialize_js('LtiConsumerXBlock')
     from .models import LaunchLog
     LaunchLog.update(self.runtime.user_id, self.location,
                      self.launch_settings['managed'])
     return fragment
Exemplo n.º 17
0
 def studio_view_aside(self, block, context=None):  # pylint: disable=unused-argument
     """
     Renders the aside contents for the studio view
     """
     fragment = Fragment('')
     fragment.add_content(
         render_template(
             "static/html/rapid_studio.html",
             {'is_enabled': self.enabled}
         )
     )
     fragment.add_css(get_resource_bytes("static/css/rapid.css"))
     fragment.add_javascript(get_resource_bytes("static/js/src/rapid_studio.js"))
     fragment.initialize_js("RapidResponseAsideStudioInit")
     return fragment
Exemplo n.º 18
0
 def student_view(self, context=None):
     student_context = {
         "index_page_url": self.index_page_url,
         "completion_status": self.get_completion_status(),
         "grade": self.get_grade(),
         "scorm_xblock": self,
     }
     student_context.update(context or {})
     template = self.render_template("static/html/scormxblock.html", student_context)
     frag = Fragment(template)
     frag.add_css(self.resource_string("static/css/scormxblock.css"))
     frag.add_javascript(self.resource_string("static/js/src/scormxblock.js"))
     frag.initialize_js(
         "ScormXBlock", json_args={"scorm_version": self.scorm_version}
     )
     return frag
Exemplo n.º 19
0
 def student_view_aside(self, block, context=None):  # pylint: disable=unused-argument
     """
     Renders the aside contents for the student view
     """
     fragment = Fragment('')
     if not self.is_staff() or not self.enabled:
         return fragment
     fragment.add_content(
         render_template("static/html/rapid.html",
                         {'is_open': self.has_open_run}))
     fragment.add_css(get_resource_bytes("static/css/rapid.css"))
     fragment.add_javascript(get_resource_bytes("static/js/src/rapid.js"))
     fragment.add_javascript(
         get_resource_bytes("static/js/lib/d3.v4.min.js"))
     fragment.initialize_js("RapidResponseAsideInit")
     return fragment
Exemplo n.º 20
0
    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
Exemplo n.º 21
0
    def _create_fragment(self, template, context_dict, initialize_js_func, additional_css=None, additional_js=None):
        """
        Creates a fragment for display.

        """
        fragment = Fragment(template.render(context_dict))

        if additional_css is None:
            additional_css = []
        if additional_js is None:
            additional_js = []

        i18n_service = self.runtime.service(self, 'i18n')
        if hasattr(i18n_service, 'get_language_bidi') and i18n_service.get_language_bidi():
            css_url = "static/css/openassessment-rtl.css"
        else:
            css_url = "static/css/openassessment-ltr.css"

        if settings.DEBUG:
            for css in additional_css:
                fragment.add_css_url(self.runtime.local_resource_url(self, css))
            fragment.add_css_url(self.runtime.local_resource_url(self, css_url))

            for js in additional_js:  # pylint: disable=invalid-name
                self.add_javascript_files(fragment, js)
            self.add_javascript_files(fragment, "static/js/src/oa_shared.js")
            self.add_javascript_files(fragment, "static/js/src/oa_server.js")
            self.add_javascript_files(fragment, "static/js/src/lms")
        else:
            # TODO: load CSS and JavaScript as URLs once they can be served by the CDN
            for css in additional_css:
                fragment.add_css(load(css))
            fragment.add_css(load(css_url))

            # minified additional_js should be already included in 'make javascript'
            fragment.add_javascript(load("static/js/openassessment-lms.min.js"))
        js_context_dict = {
            "ALLOWED_IMAGE_MIME_TYPES": self.ALLOWED_IMAGE_MIME_TYPES,
            "ALLOWED_FILE_MIME_TYPES": self.ALLOWED_FILE_MIME_TYPES,
            "FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST,
            "FILE_TYPE_WHITE_LIST": self.white_listed_file_types,
            "MAXIMUM_FILE_UPLOAD_COUNT": self.MAX_FILES_COUNT,
            "TEAM_ASSIGNMENT": self.is_team_assignment()
        }
        fragment.initialize_js(initialize_js_func, js_context_dict)
        return fragment
Exemplo n.º 22
0
    def student_view(self, context=None):
        """
        The primary view of the GradeXBlock, 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/gradexblock.html",context))
        fragment.add_javascript(self.resource_string("static/js/src/gradexblock.js"))
        fragment.initialize_js('GradeXBlock')
        return fragment
Exemplo n.º 23
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 = f'<p>[{self._("Error: Unable to load child component.")}]</p>'
            else:
                child_fragment = self._render_child_fragment(
                    child, context, view='mentoring_view')
                fragment.add_fragment_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
Exemplo n.º 24
0
    def studio_view(self, context=None):
        """
        The studio view
        """

        # load blooms config
        blooms = json.loads(loader.load_unicode("static/blooms_catalog.json"))
        content = {
            'self': self,
            'blooms_catalog': json.dumps(blooms),
            'objs': json.dumps(self.learning_objs or []),
        }

        fragment = Fragment()

        # Load fragment template
        fragment.add_content(
            loader.render_django_template('templates/learning_objs-cms.html',
                                          content))

        # add static files for styling, and template initialization
        fragment.add_css(loader.load_unicode('static/css/jquery-ui.min.css'))
        fragment.add_css(loader.load_unicode('static/css/jquery.steps.css'))
        fragment.add_css(loader.load_unicode('static/css/cms-styling.css'))
        fragment.add_css(loader.load_unicode('static/css/modal-styling.css'))
        fragment.add_css(
            loader.load_unicode('static/css/LO_listing_styling.css'))

        fragment.add_javascript(
            loader.load_unicode('static/js/js-str-format.js'))
        fragment.add_javascript(
            loader.load_unicode('static/js/jquery-ui.min.js'))
        fragment.add_javascript(
            loader.load_unicode('static/js/jquery.steps.js'))
        fragment.add_javascript(loader.load_unicode('static/js/LO_catalog.js'))
        fragment.add_javascript(
            loader.load_unicode('static/js/hl_learning_objs-cms.js'))

        fragment.initialize_js('LO_catalog')
        fragment.initialize_js(
            'HL_LO_XBlockStudio', {
                'blooms_catalog': json.dumps(blooms),
                'objs': json.dumps(self.learning_objs or []),
            })

        return fragment
Exemplo n.º 25
0
 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_django_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
 def visibility_view(self, _context=None):
     """
     Render the view to manage an xblock's visibility settings in Studio.
     Args:
         _context: Not actively used for this view.
     Returns:
         (Fragment): An HTML fragment for editing the visibility of this XBlock.
     """
     fragment = Fragment()
     from cms.djangoapps.contentstore.utils import reverse_course_url
     fragment.add_content(self.system.render_template('visibility_editor.html', {
         'xblock': self,
         'manage_groups_url': reverse_course_url('group_configurations_list_handler', self.location.course_key),
     }))
     fragment.add_javascript_url(self._get_studio_resource_url('/js/xblock/authoring.js'))
     fragment.initialize_js('VisibilityEditorInit')
     return fragment
Exemplo n.º 27
0
 def visibility_view(self, _context=None):
     """
     Render the view to manage an xblock's visibility settings in Studio.
     Args:
         _context: Not actively used for this view.
     Returns:
         (Fragment): An HTML fragment for editing the visibility of this XBlock.
     """
     fragment = Fragment()
     from contentstore.utils import reverse_course_url
     fragment.add_content(self.system.render_template('visibility_editor.html', {
         'xblock': self,
         'manage_groups_url': reverse_course_url('group_configurations_list_handler', self.location.course_key),
     }))
     fragment.add_javascript_url(self._get_studio_resource_url('/js/xblock/authoring.js'))
     fragment.initialize_js('VisibilityEditorInit')
     return fragment
Exemplo n.º 28
0
    def student_view(self, context=None):
        """
        The primary view of the DcXBlock, shown to students
        when viewing courses.
        """
        # self.has_score = True
        user_service = self.runtime.service(self, 'user')
        xb_user = user_service.get_current_user()
        # my_exp = xb_user.full_name
        my_exp = "hha"
        html = self.resource_string("static/html/dcxblock.html")
        frag = Fragment(html.format(self=self, my_exp=my_exp))
        frag.add_css(self.resource_string("static/css/dcxblock.css"))
        frag.add_javascript(self.resource_string("static/js/src/dcxblock.js"))
        frag.initialize_js('DcXBlock')

        return frag
Exemplo n.º 29
0
    def student_view(self, context=None):
        """
        Renders student view for LMS.
        """
        fragment = Fragment()

        self.add_resource_urls(fragment)

        login_msg = ''

        if not self.django_user.is_authenticated():
            qs = urllib.urlencode({
                'course_id': self.course_key,
                'enrollment_action': 'enroll',
                'email_opt_in': False,
            })
            login_msg = Text(_("You are not signed in. To view the discussion content, {sign_in_link} or "
                               "{register_link}, and enroll in this course.")).format(
                sign_in_link=HTML('<a href="{url}">{sign_in_label}</a>').format(
                    sign_in_label=_('sign in'),
                    url='{}?{}'.format(reverse('signin_user'), qs),
                ),
                register_link=HTML('<a href="/{url}">{register_label}</a>').format(
                    register_label=_('register'),
                    url='{}?{}'.format(reverse('register_user'), qs),
                ),
            )

        context = {
            'discussion_id': self.discussion_id,
            'display_name': self.display_name if self.display_name else _("Discussion"),
            'user': self.django_user,
            'course_id': self.course_key,
            'discussion_category': self.discussion_category,
            'discussion_target': self.discussion_target,
            'can_create_thread': self.has_permission("create_thread"),
            'can_create_comment': self.has_permission("create_comment"),
            'can_create_subcomment': self.has_permission("create_sub_comment"),
            'login_msg': login_msg,
        }

        fragment.add_content(self.runtime.render_template('discussion/_discussion_inline.html', context))
        fragment.initialize_js('DiscussionInlineBlock')

        return fragment
Exemplo n.º 30
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_fragment_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': _('{group_name} (inactive)').format(group_name=group_name),
                    'id': str(child.location),
                    'content': rendered_child.content,
                    'group_id': updated_group_id,
                })
                continue

            active_contents.append({
                'group_name': group_name,
                'id': str(child.location),
                '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.runtime.service(self, 'mako').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
Exemplo n.º 31
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_fragment_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': text_type(child.location),
                    'content': rendered_child.content,
                    'group_id': updated_group_id,
                })
                continue

            active_contents.append({
                'group_name': group_name,
                'id': text_type(child.location),
                '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
 def student_view(self, context=None):
     """
     The primary view of the SurveyMonkeyXBlock, shown to students
     when viewing courses.
     """
     frag = Fragment(
         LOADER.render_template("static/html/surveymonkey.html",
                                self.context))
     frag.add_css(self.resource_string("static/css/surveymonkey.css"))
     frag.add_javascript(
         self.resource_string("static/js/src/surveymonkey.js"))
     frag.initialize_js(
         'SurveyMonkeyXBlock',
         json_args={
             "is_for_external_course": self.is_for_external_course,
         },
     )
     return frag
Exemplo n.º 33
0
    def studio_view(self, context=None):
        """
        The secondary view of the XBlock, shown to teachers
        when editing the XBlock.
        """
        context = {
            'display_name': self.display_name,
            'url': self.url,
            'allow_download': self.allow_download,
            'source_text': self.source_text,
            'source_url': self.source_url
        }
        html = self.render_template('static/html/pdf_edit.html', context)

        frag = Fragment(html)
        frag.add_javascript(self.load_resource("static/js/pdf_edit.js"))
        frag.initialize_js('pdfXBlockInitEdit')
        return frag
Exemplo n.º 34
0
 def problem_view(self, context=None):  # pylint: disable=W0613
     """Returns a view of the problem - a javascript text input field."""
     html = f"<input type='text' name='input' value='{self.student_input}'><span class='message'></span>"
     result = Fragment(html)
     result.add_javascript("""
         function TextInputBlock(runtime, element) {
             return {
                 submit: function() {
                     return $(element).find(':input').serializeArray();
                 },
                 handleSubmit: function(result) {
                     $(element).find('.message').text((result || {}).error || '');
                 }
             }
         }
         """)
     result.initialize_js('TextInputBlock')
     return result
Exemplo n.º 35
0
 def studio_view(self, context=None):
     # Note that we cannot use xblockutils's StudioEditableXBlockMixin because we
     # need to support package file uploads.
     studio_context = {
         "field_display_name": self.fields["display_name"],
         "field_has_score": self.fields["has_score"],
         "field_weight": self.fields["weight"],
         "field_width": self.fields["width"],
         "field_height": self.fields["height"],
         "scorm_xblock": self,
     }
     studio_context.update(context or {})
     template = self.render_template("static/html/studio.html", studio_context)
     frag = Fragment(template)
     frag.add_css(self.resource_string("static/css/scormxblock.css"))
     frag.add_javascript(self.resource_string("static/js/src/studio.js"))
     frag.initialize_js("ScormStudioXBlock")
     return frag
Exemplo n.º 36
0
    def student_view(self, context=None):
        """View shown to students"""
        context = context.copy() if context else {}
        context["steps"] = self.steps
        fragment = Fragment()
        fragment.add_content(
            loader.render_template("templates/chat.html", context))

        fragment.add_css_url(
            self.runtime.local_resource_url(self, "public/css/chat.css"))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(
                self, "public/js/vendor/virtual-dom-1.3.0.min.js"))
        fragment.add_javascript(self.get_translation_content())
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self, "public/js/src/chat.js"))
        fragment.initialize_js("ChatXBlock", self._js_init_data())
        return fragment
Exemplo n.º 37
0
    def studio_view(self, context):
        """
        Create a fragment used to display the edit view in the Studio.
        """
        html_str = pkg_resources.resource_string(
            __name__, "static/html/simplevideo_edit.html")
        href = self.href or ''
        frag = Fragment(
            str(html_str).format(href=href,
                                 maxwidth=self.maxwidth,
                                 maxheight=self.maxheight))

        js_str = pkg_resources.resource_string(
            __name__, "static/js/src/simplevideo_edit.js")
        frag.add_javascript(str(js_str))
        frag.initialize_js('SimpleVideoEditBlock')

        return frag
Exemplo n.º 38
0
    def student_view(self, context):
        """
        Renders the contents of the chosen condition for students, and all the
        conditions for staff.
        """
        if self.child is None:
            # raise error instead?  In fact, could complain on descriptor load...
            return Fragment(content=u"<div>Nothing here.  Move along.</div>")

        if self.system.user_is_staff:
            return self._staff_view(context)
        else:
            child_fragment = self.child.render(STUDENT_VIEW, context)
            fragment = Fragment(self.system.render_template('split_test_student_view.html', {
                'child_content': child_fragment.content,
                'child_id': self.child.scope_ids.usage_id,
            }))
            fragment.add_fragment_resources(child_fragment)
            fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_student.js'))
            fragment.initialize_js('SplitTestStudentView')
            return fragment