예제 #1
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
예제 #2
0
    def render_student_view(self, context, add_resources_from=None):
        """
        Common code to render student view
        """
        fragment = Fragment()
        fragment.add_content(
            loader.render_django_template(
                self.TEMPLATE_BASE + self.template,
                context,
                i18n_service=self.i18n_service,
            ))

        if self.css_file:
            add_resource(self, 'css', self.CSS_BASE + self.css_file, fragment)

        if self.js_file:
            add_resource(self, 'javascript', self.JS_BASE + self.js_file,
                         fragment)

        if self.initialize_js_function:
            fragment.initialize_js(self.initialize_js_function)

        for js_file in self.additional_js_files:
            add_resource(self, 'javascript', js_file, fragment, via_url=True)

        if add_resources_from:
            for frag in add_resources_from:
                fragment.add_fragment_resources(frag)
        return fragment
    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]
        for activity_fragment in activity_fragments:
            fragment.add_fragment_resources(activity_fragment)

        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
예제 #4
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="<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
    def submissions_view(self, context):
        fragment = Fragment()

        submissions = [
            submission for stage in self.stages
            if isinstance(stage, SubmissionStage)
            for submission in stage.submissions
        ]
        has_submissions = bool(submissions)

        submission_fragments = self._render_children('submissions_view',
                                                     context, submissions)
        submission_contents = [frag.content for frag in submission_fragments]
        for submission_fragment in submission_fragments:
            fragment.add_fragment_resources(submission_fragment)

        render_context = {
            'activity': self,
            'submission_contents': submission_contents,
            'has_submissions': has_submissions
        }
        fragment.add_content(
            self.render_template('submissions_view', render_context))

        return fragment
예제 #6
0
    def student_view(self, context):
        fragment = Fragment()
        contents = []
        child_context = {} if not context else copy(context)

        for child in self._get_selected_child_blocks():
            for displayable in child.displayable_items():
                rendered_child = displayable.render(STUDENT_VIEW,
                                                    child_context)
                fragment.add_fragment_resources(rendered_child)
                contents.append({
                    'id': text_type(displayable.location),
                    'content': rendered_child.content,
                })

        fragment.add_content(
            self.system.render_template(
                'vert_module.html', {
                    'items': contents,
                    'xblock_context': context,
                    'show_bookmark_button': False,
                    'watched_completable_blocks': set(),
                    'completion_delay_ms': None,
                }))
        return fragment
예제 #7
0
    def dashboard_detail_view(self, context):
        ctx = self._sanitize_context(context)
        self._add_students_and_workgroups_to_context(ctx)

        fragment = Fragment()
        render_context = {
            'project': self,
            'course_id': self.course_id,
            'group_id': self.workgroup.id
        }

        render_context.update(ctx)

        target_block_id = self.get_block_id_from_string(ctx.get(Constants.ACTIVATE_BLOCK_ID_PARAMETER_NAME, None))
        target_activity = self._get_target_block(target_block_id)
        if target_activity is None and self.activities:
            target_activity = self.activities[0]

        activity_fragment = self._render_child_fragment_with_fallback(
            target_activity, ctx, self._(messages.NO_ACTIVITIES), view='dashboard_detail_view'
        )
        render_context['activity_content'] = activity_fragment.content
        fragment.add_fragment_resources(activity_fragment)

        fragment.add_content(self.render_template('dashboard_detail_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)
        add_resource(self, 'javascript', 'public/js/group_project_dashboard_detail.js', fragment)

        fragment.initialize_js('GroupProjectBlockDashboardDetailsView')

        return fragment
    def student_view(self, context):
        fragment = Fragment()
        contents = []
        child_context = {} if not context else copy(context)

        for child in self._get_selected_child_blocks():
            if child is None:
                # TODO: Fix the underlying issue in TNL-7424
                # This shouldn't be happening, but does for an as-of-now
                # unknown reason. Until we address the underlying issue,
                # let's at least log the error explicitly, ignore the
                # exception, and prevent the page from resulting in a
                # 500-response.
                logger.error('Skipping display for child block that is None')
                continue
            for displayable in child.displayable_items():
                rendered_child = displayable.render(STUDENT_VIEW,
                                                    child_context)
                fragment.add_fragment_resources(rendered_child)
                contents.append({
                    'id': text_type(displayable.location),
                    'content': rendered_child.content,
                })

        fragment.add_content(
            self.system.render_template(
                'vert_module.html', {
                    'items': contents,
                    'xblock_context': context,
                    'show_bookmark_button': False,
                    'watched_completable_blocks': set(),
                    'completion_delay_ms': None,
                }))
        return fragment
예제 #9
0
    def get_stage_content_fragment(self, context, view='student_view'):
        fragment = Fragment()
        children_fragments = self.render_children_fragments(context, view=view)
        render_context = {
            'stage': self,
            'children_contents': [frag.content for frag in children_fragments]
        }

        for frag in children_fragments:
            fragment.add_fragment_resources(frag)

        render_context.update(context)
        fragment.add_content(
            loader.render_django_template(
                self.STAGE_CONTENT_TEMPLATE,
                render_context,
                i18n_service=self.i18n_service,
            ))

        if self.js_file:
            add_resource(self, 'javascript', self.js_file, fragment)

        if self.js_init:
            fragment.initialize_js(self.js_init)

        return fragment
예제 #10
0
    def student_view(self, context=None):
        """
        Render student view for LMS.
        """
        context = context or {}

        fragment = Fragment()
        render_context = self.student_view_data()

        if self.has_children:
            child_blocks_data = []
            for child_usage_id in self.children:
                child_block = self.runtime.get_block(child_usage_id)
                if child_block:
                    child_block_fragment = child_block.render(
                        'student_view', context)
                    child_block_content = child_block_fragment.content
                    fragment.add_fragment_resources(child_block_fragment)
                    child_blocks_data.append({
                        'content':
                        child_block_content,
                        'display_name':
                        child_block.display_name,
                    })
            render_context['child_blocks'] = child_blocks_data

        fragment.add_content(
            loader.render_template(self.student_view_template, render_context))

        if self.css_resource_url:
            fragment.add_css_url(
                self.runtime.local_resource_url(self, self.css_resource_url))

        return fragment
예제 #11
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
def wrap_fragment(fragment, new_content):
    """
    Returns a new Fragment that has `new_content` and all
    as its content, and all of the resources from fragment
    """
    wrapper_frag = Fragment(content=new_content)
    wrapper_frag.add_fragment_resources(fragment)
    return wrapper_frag
예제 #13
0
def wrap_fragment(fragment, new_content):
    """
    Returns a new Fragment that has `new_content` and all
    as its content, and all of the resources from fragment
    """
    wrapper_frag = Fragment(content=new_content)
    wrapper_frag.add_fragment_resources(fragment)
    return wrapper_frag
예제 #14
0
 def author_view(self, _context):
     """
     Studio Preview view
     """
     fragment = Fragment(self.display_name_with_default)
     url_name_fragment = self.get_url_name_fragment(self.url_name_caption)
     fragment.add_content(url_name_fragment.content)
     fragment.add_fragment_resources(url_name_fragment)
     return fragment
예제 #15
0
    def student_view(self, context):
        context = context.copy() if context else {}
        fragment = Fragment()

        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            # Child should be an instance of MentoringTableColumn
            child_frag = child.render('mentoring_view', context)
            fragment.add_fragment_resources(child_frag)

        context['allow_sharing'] = self.allow_sharing
        context['allow_download'] = self.allow_download
        user_service = self.runtime.service(self, 'user')
        if user_service:
            context['view_options'] = Share.objects.filter(
                shared_with__username=self.current_user_key,
                block_id=self.block_id,
            ).values_list('shared_by__username', flat=True)
            context['username'] = self.current_user_key
            share_notifications = Share.objects.filter(
                shared_with__username=self.current_user_key,
                notified=False, block_id=self.block_id,
            ).values_list('shared_by__username', flat=True)
            context['share_notifications'] = share_notifications and json.dumps(list(share_notifications))

        if self.type:
            # Load an optional background image:
            context['bg_image_url'] = self.runtime.local_resource_url(self, f'public/img/{self.type}-bg.png')
            # Load an optional description for the background image, for accessibility
            try:
                context['bg_image_description'] = loader.load_unicode(f'static/text/table-{self.type}.txt')
            except OSError as e:
                if e.errno == errno.ENOENT:
                    pass
                else:
                    raise

        report_template = loader.render_django_template('templates/html/mentoring-table-report.html', {
            'title': self.display_name,
            'css': loader.load_unicode(AnswerRecapBlock.css_path) + loader.load_unicode(self.css_path),
            'student_name': self._get_user_full_name(),
            'course_name': self._get_course_name(),
        })

        fragment.add_content(loader.render_django_template('templates/html/mentoring-table-container.html', context))
        fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/mentoring-table.css'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/vendor/jquery-shorten.js'))
        fragment.add_javascript_url(self.runtime.local_resource_url(self, self.js_path))
        fragment.initialize_js(
            'MentoringTableBlock', {
                'reportContentSelector': '.mentoring-table-container',
                'reportTemplate': report_template,
            }
        )

        return fragment
예제 #16
0
    def _render_view(self, child_view, template, context):
        fragment = Fragment()

        submission_contents = []
        for submission in self.submissions:
            submission_fragment = submission.render(child_view, context)
            fragment.add_fragment_resources(submission_fragment)
            submission_contents.append(submission_fragment.content)

        context = {'stage': self, 'submission_contents': submission_contents}
        fragment.add_content(loader.render_django_template(template, context, i18n_service=self.i18n_service))

        return fragment
예제 #17
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
예제 #18
0
    def dashboard_view(self, context):
        fragment = Fragment()

        children_context = context.copy()

        stage_fragments = self._render_children('dashboard_view', children_context, self.stages)
        stage_contents = [frag.content for frag in stage_fragments]
        for stage_fragment in stage_fragments:
            fragment.add_fragment_resources(stage_fragment)

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

        return fragment
예제 #19
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
예제 #20
0
 def mentoring_view(self, context=None):
     """ Render this XBlock within a mentoring block. """
     context = context.copy() if context else {}
     fragment = Fragment()
     for child_id in self.children:
         child = self.runtime.get_block(child_id)
         if child.scope_ids.block_type == "html":
             # HTML block current doesn't support "mentoring_view" and if "student_view" is used, it gets wrapped
             # with HTML we don't want. So just grab its HTML directly.
             child_frag = Fragment(child.data)
         else:
             child_frag = child.render('mentoring_view', context)
         fragment.add_content(child_frag.content)
         fragment.add_fragment_resources(child_frag)
     return fragment
예제 #21
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]
        for stage_fragment in stage_fragments:
            fragment.add_fragment_resources(stage_fragment)

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

        return fragment
예제 #22
0
    def resources_view(self, context):
        fragment = Fragment()

        resources = [resource for stage in self.stages for resource in stage.resources]
        has_resources = bool(resources)

        resource_fragments = self._render_children('resources_view', context, resources)
        resource_contents = [frag.content for frag in resource_fragments]
        for resource_fragment in resource_fragments:
            fragment.add_fragment_resources(resource_fragment)

        render_context = {'activity': self, 'resource_contents': resource_contents, 'has_resources': has_resources}
        fragment.add_content(self.render_template('resources_view', render_context))

        return fragment
예제 #23
0
    def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
        position_for_asides = '<!-- footer for xblock_aside -->'
        result = Fragment()
        result.add_fragment_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_fragment_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
예제 #24
0
    def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
        position_for_asides = '<!-- footer for xblock_aside -->'
        result = Fragment()
        result.add_fragment_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_fragment_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
예제 #25
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_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(),
        }))

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

        return fragment
예제 #26
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
    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
예제 #28
0
파일: runtime.py 프로젝트: edx/XBlock
    def _wrap_ele(self, block, view, 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 = (
                '<script type="json/xblock-args" class="xblock_json_init_args">'
                '{data}</script>'
            ).format(data=json.dumps(frag.json_init_args))

        block_css_entrypoint = block.entry_point.replace('.', '-')
        css_classes = [
            block_css_entrypoint,
            '{}-{}'.format(block_css_entrypoint, view),
        ]

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

        wrapped.add_content(html)
        wrapped.add_fragment_resources(frag)
        return wrapped
예제 #29
0
    def _wrap_ele(self, block, view, 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 = (
                '<script type="json/xblock-args" class="xblock_json_init_args">'
                '{data}</script>').format(data=json.dumps(frag.json_init_args))

        block_css_entrypoint = block.entry_point.replace('.', '-')
        css_classes = [
            block_css_entrypoint,
            '{}-{}'.format(block_css_entrypoint, view),
        ]

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

        wrapped.add_content(html)
        wrapped.add_fragment_resources(frag)
        return wrapped
예제 #30
0
    def _view_render(self, context, view='student_view'):
        stage_fragment = self.get_stage_content_fragment(context, view)

        fragment = Fragment()
        fragment.add_fragment_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_django_template(
                self.STAGE_WRAPPER_TEMPLATE,
                render_context,
                i18n_service=self.i18n_service,
            ))
        if stage_fragment.js_init_fn:
            fragment.initialize_js(stage_fragment.js_init_fn)

        return fragment
예제 #31
0
 def author_preview_view(self, context):
     context['self'] = self
     fragment = Fragment()
     fragment.add_content(
         loader.render_django_template('templates/html/plot_preview.html',
                                       context))
     fragment.add_css_url(
         self.runtime.local_resource_url(self,
                                         'public/css/plot-preview.css'))
     if self.overlay_ids:
         message = _(
             "In addition to the default and average overlays the plot includes the following overlays:"
         )
         fragment.add_content(f'<p>{message}</p>')
         for overlay in self.overlays:
             overlay_fragment = self._render_child_fragment(
                 overlay, context, view='mentoring_view')
             fragment.add_fragment_resources(overlay_fragment)
             fragment.add_content(overlay_fragment.content)
     return fragment
    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
    def student_view(self, context):
        fragment = Fragment()
        contents = []
        child_context = {} if not context else copy(context)

        for child in self._get_selected_child_blocks():
            for displayable in child.displayable_items():
                rendered_child = displayable.render(STUDENT_VIEW, child_context)
                fragment.add_fragment_resources(rendered_child)
                contents.append({
                    'id': text_type(displayable.location),
                    'content': rendered_child.content,
                })

        fragment.add_content(self.system.render_template('vert_module.html', {
            'items': contents,
            'xblock_context': context,
            'show_bookmark_button': False,
            'watched_completable_blocks': set(),
        }))
        return fragment
예제 #34
0
    def author_preview_view(self, context):
        fragment = Fragment()
        children_contents = []
        for child in self._children:
            child_fragment = child.render('preview_view', context)
            fragment.add_fragment_resources(child_fragment)
            children_contents.append(child_fragment.content)

        fragment.add_content(
            loader.render_django_template(
                "templates/html/project_navigator/project_navigator_author_view.html",
                {
                    'navigator': self,
                    'children_contents': children_contents
                },
                i18n_service=self.i18n_service,
            ))
        add_resource(self, 'css',
                     'public/css/project_navigator/project_navigator.css',
                     fragment)
        return fragment
예제 #35
0
    def student_view(self, context):
        """
        Player view, displayed to the student
        """
        fragment = Fragment()

        current_stage_id = context.get(Constants.CURRENT_STAGE_ID_PARAMETER_NAME, None)
        target_stage = self.get_stage_to_display(current_stage_id)

        if not target_stage:
            fragment.add_content(self._(messages.NO_STAGES))
        else:
            stage_fragment = target_stage.render('student_view', context)
            fragment.add_fragment_resources(stage_fragment)
            render_context = {
                'activity': self,
                'stage_content': stage_fragment.content,
            }
            render_context.update(context)
            fragment.add_content(self.render_template('student_view', render_context))

        return fragment
예제 #36
0
    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(f'<p>[{self._("Error: Unable to load child component.")}]</p>')
            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(f"<p>{child.display_name}</p>")
                else:
                    child_fragment = self._render_child_fragment(child, context, view)
                    fragment.add_fragment_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
예제 #37
0
파일: runtime.py 프로젝트: edx/XBlock
    def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
        """
        Execute and layout the aside_frags wrt the block's frag. Runtimes should feel free to override this
        method to control execution, place, and style the asides appropriately for their application

        This default method appends the aside_frags after frag. If you override this, you must
        call wrap_aside around each aside as per this function.

        Args:
            block (XBlock): the block being rendered
            frag (html): The result from rendering the block
            aside_frag_fns list((aside, aside_fn)): The asides and closures for rendering to call
        """
        result = Fragment(frag.content)
        result.add_fragment_resources(frag)

        for aside, aside_fn in aside_frag_fns:
            aside_frag = self.wrap_aside(block, aside, view_name, aside_fn(block, context), context)
            aside.save()
            result.add_content(aside_frag.content)
            result.add_fragment_resources(aside_frag)

        return result
예제 #38
0
    def author_preview_view(self, context):
        """
        View for previewing contents in studio.
        """
        children_contents = []

        fragment = Fragment()
        for child_id in self.children:
            child = self.runtime.get_block(child_id)
            child_fragment = self._render_child_fragment(
                child, context, 'preview_view')
            fragment.add_fragment_resources(child_fragment)
            children_contents.append(child_fragment.content)

        render_context = {
            'block': self,
            'children_contents': children_contents
        }
        render_context.update(context)
        fragment.add_content(
            self.loader.render_django_template(self.CHILD_PREVIEW_TEMPLATE,
                                               render_context))
        return fragment