Ejemplo n.º 1
0
    def author_view(self, context):
        if self.question:
            return self.student_view(context)

        fragment = Fragment()
        fragment.add_content(self._(messages.QUESTION_NOT_SELECTED))
        return fragment
Ejemplo n.º 2
0
    def student_view(self, context):
        if self.question is None:
            return Fragment(self._(messages.COMPONENT_MISCONFIGURED))

        raw_feedback = self.get_feedback()

        feedback = []
        for item in raw_feedback:
            feedback.append(html.escape(item['answer']))

        fragment = Fragment()
        title = self.question.assessment_title if self.question.assessment_title else self.question.title
        render_context = {
            'assessment': self,
            'question_title': title,
            'feedback': feedback
        }
        if self.show_mean:
            try:
                if feedback:
                    render_context['mean'] = "{0:.1f}".format(mean(feedback))
                else:
                    render_context['mean'] = _(u"N/A")
            except ValueError as exc:
                log.warn(exc)  # pylint: disable=deprecated-method
                render_context['mean'] = _(u"N/A")

        render_context.update(context)
        fragment.add_content(
            loader.render_django_template(
                "templates/html/components/review_assessment.html",
                render_context,
                i18n_service=self.i18n_service,
            ))
        return fragment
Ejemplo n.º 3
0
    def student_view(self, context):
        fragment = Fragment()
        # Could be a TA not in the group.
        if self.stage.is_group_member:
            user_details = [
                self.stage.project_api.get_member_data(self.stage.user_id)
            ]
        else:
            user_details = []
        render_context = {
            'team_members': user_details + self.stage.team_members,
            'course_id': self.stage.course_id,
            'group_id': self.stage.workgroup.id
        }
        render_context.update(context)

        fragment.add_content(
            loader.render_django_template(
                "templates/html/components/project_team.html",
                render_context,
                i18n_service=self.i18n_service,
            ))
        add_resource(self, 'css', "public/css/components/project_team.css",
                     fragment)
        add_resource(self, 'javascript',
                     "public/js/components/project_team.js", fragment)
        fragment.initialize_js("ProjectTeamXBlock")
        return fragment
Ejemplo n.º 4
0
    def student_view(self, context):
        try:
            activity = self.stage.activity
            target_block = activity.project.navigator.get_child_of_category(
                self.TARGET_PROJECT_NAVIGATOR_VIEW)
        except AttributeError:
            activity = None
            target_block = None

        if target_block is None:
            return Fragment()

        render_context = {
            'block':
            self,
            'block_link':
            get_link_to_block(target_block),
            'block_text':
            self._(self.TEXT_TEMPLATE).format(
                activity_name=self._(activity.display_name)),
            'target_block_id':
            str(target_block.scope_ids.usage_id),
            'view_icon':
            target_block.icon
        }
        render_context.update(context)

        fragment = Fragment()
        fragment.add_content(
            loader.render_template(self.TEMPLATE_PATH, render_context))
        return fragment
Ejemplo n.º 5
0
    def _student_or_public_view(self,
                                context,
                                prereq_met,
                                prereq_meta_info,
                                banner_text=None,
                                view=STUDENT_VIEW):
        """
        Returns the rendered student view of the content of this
        sequential.  If banner_text is given, it is added to the
        content.
        """
        _ = self.runtime.service(self, "i18n").ugettext
        display_items = self.get_display_items()
        self._update_position(context, len(display_items))

        fragment = Fragment()
        params = self._get_render_metadata(context, display_items, prereq_met,
                                           prereq_meta_info, banner_text, view,
                                           fragment)
        fragment.add_content(
            self.system.render_template("seq_module.html", params))

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

        return fragment
    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
Ejemplo n.º 7
0
 def student_view(self, _context):
     """
     Renders the student view.
     """
     fragment = Fragment()
     fragment.add_content(self.rendered_html)
     return fragment
Ejemplo n.º 8
0
 def student_view(self, context):
     """
     Renders the output that a student will see.
     """
     fragment = Fragment()
     fragment.add_content(self.runtime.service(self, 'mako').render_template('edxmako.html', context))
     return fragment
Ejemplo n.º 9
0
    def student_view(self, context):  # lint-amnesty, pylint: disable=missing-function-docstring
        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
Ejemplo n.º 10
0
    def author_view(self, context):
        """
        Renders the Studio views.
        Normal studio view: If block is properly configured, displays library status summary
        Studio container view: displays a preview of all possible children.
        """
        fragment = Fragment()
        root_xblock = context.get('root_xblock')
        is_root = root_xblock and root_xblock.location == self.location

        if is_root:
            # User has clicked the "View" link. Show a preview of all possible children:
            if self.children:  # pylint: disable=no-member
                fragment.add_content(
                    self.system.render_template(
                        "library-block-author-preview-header.html", {
                            'max_count': self.max_count,
                            'display_name': self.display_name or self.url_name,
                        }))
                context['can_edit_visibility'] = False
                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
Ejemplo n.º 11
0
    def _student_view(self, context, prereq_met, prereq_meta_info, banner_text=None):
        """
        Returns the rendered student view of the content of this
        sequential.  If banner_text is given, it is added to the
        content.
        """
        display_items = self.get_display_items()
        self._update_position(context, len(display_items))

        if prereq_met and not self._is_gate_fulfilled():
            banner_text = _('This section is a prerequisite. You must complete this section in order to unlock additional content.')

        fragment = Fragment()
        params = {
            'items': self._render_student_view_for_items(context, display_items, fragment) if prereq_met else [],
            'element_id': self.location.html_id(),
            'item_id': text_type(self.location),
            'position': self.position,
            'tag': self.location.block_type,
            'ajax_url': self.system.ajax_url,
            'next_url': context.get('next_url'),
            'prev_url': context.get('prev_url'),
            'banner_text': banner_text,
            'save_position': self.is_user_authenticated(context),
            'show_completion': self.is_user_authenticated(context),
            'gated_content': self._get_gated_content_info(prereq_met, prereq_meta_info)
        }
        fragment.add_content(self.system.render_template("seq_module.html", params))

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

        return fragment
    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
Ejemplo n.º 13
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.parse.urlencode({
                'course_id': self.course_key,
                'enrollment_action': 'enroll',
                'email_opt_in': False,
            })
            login_msg = Text(
                _(u"You are not signed in. To view the discussion content, {sign_in_link} or "
                  u"{register_link}, and enroll in this course.")).format(
                      sign_in_link=HTML(
                          u'<a href="{url}">{sign_in_label}</a>').format(
                              sign_in_label=_('sign in'),
                              url='{}?{}'.format(reverse('signin_user'), qs),
                          ),
                      register_link=HTML(
                          u'<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
    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
    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
Ejemplo n.º 16
0
    def student_view(self, context=None):
        # pylint: disable=no-member
        """
        The primary view of the StaffGradedAssignmentXBlock, shown to students
        when viewing courses.
        """
        context = {
            "student_state": json.dumps(self.student_state()),
            "id": self.location.name.replace('.', '_'),
            # "id": self.block_id.replace('.', '_'),
            "max_file_size": self.student_upload_max_size(),
            "support_email": settings.TECH_SUPPORT_EMAIL
        }
        if self.show_staff_grading_interface():
            context['is_course_staff'] = True
            self.update_staff_debug_context(context)

        fragment = Fragment()
        fragment.add_content(
            render_template('templates/staff_graded_assignment/show.html',
                            context))
        fragment.add_css(_resource("static/css/edx_sga.css"))
        fragment.add_javascript(_resource("static/js/src/edx_sga.js"))
        fragment.add_javascript(
            _resource("static/js/src/jquery.tablesorter.min.js"))
        fragment.initialize_js('StaffGradedAssignmentXBlock')
        return fragment
Ejemplo n.º 17
0
    def student_view(self, context=None):
        """
        The primary view, shown to students
        when viewing courses.
        """
        user_service = self.runtime.service(self, 'user')
        xb_user = user_service.get_current_user()
        CURRENT = xb_user.opt_attrs.get('edx-platform.username')

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

        res0 = textwrap.dedent("""
            <p id='goss_hidden'><span id="gosscurrent">{}</span></p>
        """).format(CURRENT)
        frag.add_content(SafeText(res0))

        HTMLURL = 'https://node-server.online/r/assets/x92.html'
        if sys.version_info.major >= 3:
            response = urlopen(HTMLURL)
            encoding = response.info().get_content_charset('utf-8')
            html_data = response.read().decode(encoding)
        else:
            html_data = urlopen(HTMLURL).read().decode('utf-8')

        res = textwrap.dedent(html_data)
        frag.add_content(SafeText(res))

        frag.add_css(self.resource_string("static/css/gossxblock.css"))
        frag.add_javascript(
            self.resource_string("static/js/src/goss92xblock.js"))
        frag.initialize_js('Goss92XBlock')
        return frag
Ejemplo n.º 18
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):
        """
        Player view, displayed to the student
        """

        fragment = Fragment()
        fragment.add_content(
            loader.render_django_template('/templates/html/drag_and_drop.html',
                                          i18n_service=self.i18n_service))
        css_urls = ('public/css/drag_and_drop.css', )
        js_urls = [
            'public/js/vendor/virtual-dom-1.3.0.min.js',
            'public/js/drag_and_drop.js',
        ]

        statici18n_js_url = self._get_statici18n_js_url()
        if statici18n_js_url:
            js_urls.append(statici18n_js_url)

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

        self.include_theme_files(fragment)

        fragment.initialize_js('DragAndDropBlock', self.student_view_data())

        return fragment
Ejemplo n.º 20
0
    def student_view(self, context):
        """
        XBlock student view of this component.

        Makes a request to `lti_launch_handler` either
        in an iframe or in a new window depending on the
        configuration of the instance of this XBlock

        Arguments:
            context (dict): XBlock context

        Returns:
            xblock.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        loader = ResourceLoader(__name__)
        context.update(self._get_context_for_template())
        fragment.add_content(
            loader.render_mako_template('/templates/html/student.html',
                                        context))
        fragment.add_css(loader.load_unicode('static/css/student.css'))
        fragment.add_javascript(
            loader.load_unicode('static/js/xblock_lti_consumer.js'))
        fragment.initialize_js('LtiConsumerXBlock')
        return fragment
    def _student_or_public_view(self,
                                context,
                                prereq_met,
                                prereq_meta_info,
                                banner_text=None,
                                view=STUDENT_VIEW):
        """
        Returns the rendered student view of the content of this
        sequential.  If banner_text is given, it is added to the
        content.
        """
        _ = self.runtime.service(self, "i18n").ugettext
        display_items = self.get_display_items()
        self._update_position(context, len(display_items))

        fragment = Fragment()
        params = self._get_render_metadata(context, display_items, prereq_met, prereq_meta_info, banner_text, view, fragment)  # lint-amnesty, pylint: disable=line-too-long
        fragment.add_content(
            self.system.render_template("seq_module.html", params))

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

        add_webpack_to_fragment(fragment, 'SequenceBlockPreview')
        shim_xmodule_js(fragment, 'Sequence')
        return fragment
Ejemplo n.º 22
0
    def author_view(self, context):
        """
        Renders the Studio preview by rendering each child so that they can all be seen and edited.
        """
        fragment = Fragment()
        root_xblock = context.get('root_xblock')
        is_root = root_xblock and root_xblock.location == self.location
        active_groups_preview = None
        inactive_groups_preview = None

        if is_root:
            [active_children, inactive_children] = self.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.runtime.service(self, 'mako').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.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
Ejemplo n.º 23
0
 def author_view(self, context=None):
     """
     The primary view of the CLFClientXBlock, shown to students
     when viewing courses.
     """
     frag = Fragment()
     clf_info = {}
     if (self.clfId != ''):
         status, clf_info = self.consume_service('getClf',
                                                 {'clfId': self.clfId})
     html_context = dict(
         self=self,
         clf_info=clf_info,
         back_icon=self.runtime.local_resource_url(
             self, 'static/icons/back-016.png'),
     )
     frag.add_content(
         loader.render_template('templates/clfclient-author.html',
                                html_context))
     frag.add_css_url(
         "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
     )
     frag.add_javascript(
         self.resource_string("static/js/src/clfclient-author.js"))
     frag.initialize_js('CLFClientXBlock')
     return frag
Ejemplo n.º 24
0
 def author_view(self, context):
     fragment = Fragment()
     loader = ResourceLoader(__name__)
     context.update(self._get_context_for_template())
     fragment.add_content(
         loader.render_mako_template('/templates/author.html', context))
     return fragment
Ejemplo n.º 25
0
    def student_view(self, context=None):
        """
        The primary view of the Goss2XBlock, shown to students
        when viewing courses.
        """
        user_service = self.runtime.service(self, 'user')
        xb_user = user_service.get_current_user()
        CURRENT = xb_user.opt_attrs.get('edx-platform.username')

        XURL = 'https://fork.kodaktor.ru/testxblock2'
        response = urllib.urlopen(XURL)
        data = json.loads(response.read())
        CHECK = data['message']

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

        res = textwrap.dedent("""
            <h2>X4a: Server app challenge</h2>
            <p>Your server app URL should return this: <span id="gosscurrent">{}</span>!</h2>
            <p>The address {} returned {}</h2>
            <div>Enter URL: <input id='gossinput' /><br/>
            <button id='gosssend'>send to server</button>
            </div> 
        """).format(CURRENT, XURL, CHECK)
        frag.add_content(SafeText(res))

        frag.add_css(self.resource_string("static/css/goss4xblock.css"))
        frag.add_javascript(
            self.resource_string("static/js/src/goss4xblock.js"))
        frag.initialize_js('Goss4XBlock')
        return frag
Ejemplo n.º 26
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
Ejemplo n.º 27
0
    def author_view(self, context):
        """
        Renders the Studio preview by rendering each child so that they can all be seen and edited.
        """
        fragment = Fragment()
        root_xblock = context.get('root_xblock')
        is_root = root_xblock and root_xblock.location == self.location
        active_groups_preview = None
        inactive_groups_preview = None

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

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

        return fragment
Ejemplo n.º 28
0
    def studio_view(self, _context=None):  # pylint: disable=unused-argument
        '''
        Minimal view with no configuration options giving some help text.
        '''
        self.init_emulation()

        ctx = {
            'done': self.done,
            'feedback': self.feedback,
            'description': self.description,
            'button_name': self.button_name,
            'id': uuid.uuid1(0)
        }

        frag = Fragment()

        frag.add_content(
            loader.render_django_template(
                "static/html/studioview.html",
                context=ctx,
                i18n_service=self.runtime.service(self, "i18n"),
            ))

        frag.add_javascript(resource_string("static/js/src/studioview.js"))
        frag.initialize_js("DoneWithAnswerXBlockEdit")
        return frag
    def _student_view(self, context, banner_text=None):
        """
        Returns the rendered student view of the content of this
        sequential.  If banner_text is given, it is added to the
        content.
        """
        display_items = self.get_display_items()
        self._update_position(context, len(display_items))
        prereq_met = True
        prereq_meta_info = {}
        _ = self.runtime.service(self, "i18n").ugettext

        if self._required_prereq():
            if self.runtime.user_is_staff:
                banner_text = _(
                    'This subsection is unlocked for learners when they meet the prerequisite requirements.'
                )
            else:
                # check if prerequisite has been met
                prereq_met, prereq_meta_info = self._compute_is_prereq_met(
                    True)
        if prereq_met and not self._is_gate_fulfilled():
            banner_text = _(
                'This section is a prerequisite. You must complete this section in order to unlock additional content.'
            )

        fragment = Fragment()
        params = {
            'items':
            self._render_student_view_for_items(
                context, display_items, fragment) if prereq_met else [],
            'element_id':
            self.location.html_id(),
            'item_id':
            text_type(self.location),
            'position':
            self.position,
            'tag':
            self.location.block_type,
            'ajax_url':
            self.system.ajax_url,
            'next_url':
            context.get('next_url'),
            'prev_url':
            context.get('prev_url'),
            'banner_text':
            banner_text,
            'disable_navigation':
            not self.is_user_authenticated(context),
            'gated_content':
            self._get_gated_content_info(prereq_met, prereq_meta_info)
        }
        fragment.add_content(
            self.system.render_template("seq_module.html", params))

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

        return fragment
Ejemplo n.º 30
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 resources_view(self, context):
     fragment = Fragment()
     render_context = {'resource': self}
     render_context.update(context)
     fragment.add_content(
         loader.render_template(self.PROJECT_NAVIGATOR_VIEW_TEMPLATE,
                                render_context))
     return fragment
Ejemplo n.º 32
0
 def get_url_name_fragment(self, caption):
     fragment = Fragment()
     fragment.add_content(
         loader.render_template("templates/html/url_name.html", {
             'url_name': self.url_name,
             'caption': caption
         }))
     return fragment
Ejemplo n.º 33
0
    def student_view(self, context):
        ctx = self._sanitize_context(context)

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

        render_context.update(context)

        def render_child_fragment(child, content_key, fallback_message, extra_context=None):
            """
            Renders child, appends child fragment resources to parent fragment and
            updates parent's rendering context
            """
            internal_context = dict(ctx)
            if extra_context:
                internal_context.update(extra_context)

            child_fragment = self._render_child_fragment_with_fallback(
                child, internal_context, fallback_message, 'student_view'
            )
            fragment.add_fragment_resources(child_fragment)
            render_context[content_key] = child_fragment.content

        target_block_id = self.get_block_id_from_string(ctx.get(Constants.ACTIVATE_BLOCK_ID_PARAMETER_NAME, None))
        target_stage = self.get_stage_to_display(target_block_id)

        child_context = {}
        if target_stage:
            child_context[Constants.CURRENT_STAGE_ID_PARAMETER_NAME] = target_stage.id

        # activity should be rendered first, as some stages might report completion in student-view - this way stage
        # PN sees updated state.
        target_activity = target_stage.activity if target_stage else None
        render_child_fragment(target_activity, 'activity_content', self._(messages.NO_ACTIVITIES), child_context)

        # TODO: project nav is slow, mostly due to navigation view. It might make sense to rework it into
        # asynchronously loading navigation and stage states.
        project_navigator = self.get_child_of_category(GroupProjectNavigatorXBlock.CATEGORY)
        render_child_fragment(
            project_navigator, 'project_navigator_content', self._(messages.NO_PROJECT_NAVIGATOR), child_context
        )

        discussion = self.get_child_of_category(DiscussionXBlockShim.CATEGORY)
        render_child_fragment(discussion, 'discussion_content', self._(messages.NO_DISCUSSION), child_context)

        fragment.add_content(self.render_template('student_view', render_context))

        add_resource(self, 'css', 'public/css/group_project.css', fragment)
        add_resource(self, 'css', 'public/css/group_project_common.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.js', fragment)
        add_resource(self, 'javascript', 'public/js/group_project_common.js', fragment)
        fragment.initialize_js("GroupProjectBlock")
        return fragment
Ejemplo n.º 34
0
 def author_view(self, context=None):  # pylint: disable=unused-argument
     """
     Renders author view for Studio.
     """
     fragment = Fragment()
     fragment.add_content(self.runtime.render_template(
         'discussion/_discussion_inline_studio.html',
         {'discussion_id': self.discussion_id}
     ))
     return fragment
Ejemplo n.º 35
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
Ejemplo n.º 36
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
Ejemplo n.º 37
0
    def student_view(self, context):
        """
        Renders the output that a student will see.
        """
        fragment = Fragment()

        fragment.add_content(self.system.render_template('word_cloud.html', {
            'ajax_url': self.system.ajax_url,
            'display_name': self.display_name,
            'instructions': self.instructions,
            'element_class': self.location.block_type,
            'element_id': self.location.html_id(),
            'num_inputs': self.num_inputs,
            'submitted': self.submitted,
        }))

        return fragment
Ejemplo n.º 38
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
Ejemplo n.º 39
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
Ejemplo n.º 40
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
Ejemplo n.º 41
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
    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
Ejemplo n.º 43
0
    def _student_view(self, context, banner_text=None):
        """
        Returns the rendered student view of the content of this
        sequential.  If banner_text is given, it is added to the
        content.
        """
        display_items = self.get_display_items()
        self._update_position(context, len(display_items))
        prereq_met = True
        prereq_meta_info = {}

        if self._required_prereq():
            if self.runtime.user_is_staff:
                banner_text = _('This subsection is unlocked for learners when they meet the prerequisite requirements.')
            else:
                # check if prerequisite has been met
                prereq_met, prereq_meta_info = self._compute_is_prereq_met(True)
        if prereq_met and not self._is_gate_fulfilled():
            banner_text = _('This section is a prerequisite. You must complete this section in order to unlock additional content.')

        fragment = Fragment()
        params = {
            'items': self._render_student_view_for_items(context, display_items, fragment) if prereq_met else [],
            'element_id': self.location.html_id(),
            'item_id': text_type(self.location),
            'position': self.position,
            'tag': self.location.block_type,
            'ajax_url': self.system.ajax_url,
            'next_url': context.get('next_url'),
            'prev_url': context.get('prev_url'),
            'banner_text': banner_text,
            'disable_navigation': not self.is_user_authenticated(context),
            'gated_content': self._get_gated_content_info(prereq_met, prereq_meta_info)
        }
        fragment.add_content(self.system.render_template("seq_module.html", params))

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

        return fragment
Ejemplo n.º 44
0
    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