Beispiel #1
0
    def get(self, request, usage_key_string, *args, **kwargs):  # lint-amnesty, pylint: disable=unused-argument
        """
        Return response to a GET request.
        """
        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError:
            raise NotFound("Invalid usage key: '{}'.".format(usage_key_string))  # lint-amnesty, pylint: disable=raise-missing-from

        _, request.user = setup_masquerade(
            request,
            usage_key.course_key,
            staff_access=has_access(request.user, 'staff',
                                    usage_key.course_key),
            reset_masquerade_data=True,
        )

        sequence, _ = get_module_by_usage_id(self.request,
                                             str(usage_key.course_key),
                                             str(usage_key),
                                             disable_staff_debug_info=True,
                                             will_recheck_access=True)

        view = STUDENT_VIEW
        if request.user.is_anonymous:
            view = PUBLIC_VIEW

        return Response(
            json.loads(sequence.handle_ajax('metadata', None, view=view)))
Beispiel #2
0
    def get(self, request, usage_key_string, *args, **kwargs):  # lint-amnesty, pylint: disable=unused-argument
        """
        Return response to a GET request.
        """
        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError:
            raise NotFound(f"Invalid usage key: '{usage_key_string}'.")  # lint-amnesty, pylint: disable=raise-missing-from

        _, request.user = setup_masquerade(
            request,
            usage_key.course_key,
            staff_access=has_access(request.user, 'staff', usage_key.course_key),
            reset_masquerade_data=True,
        )

        sequence, _ = get_module_by_usage_id(
            self.request,
            str(usage_key.course_key),
            str(usage_key),
            disable_staff_debug_info=True,
            will_recheck_access=True)

        view = STUDENT_VIEW
        if request.user.is_anonymous:
            view = PUBLIC_VIEW

        context = {'specific_masquerade': is_masquerading_as_specific_student(request.user, usage_key.course_key)}
        return Response(sequence.get_metadata(view=view, context=context))
Beispiel #3
0
    def get(self, request, usage_key_string, *args, **kwargs):  # lint-amnesty, pylint: disable=unused-argument
        """
        Return response to a GET request.
        """
        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError as exc:
            raise NotFound(f"Invalid usage key: '{usage_key_string}'.") from exc
        _, request.user = setup_masquerade(
            request,
            usage_key.course_key,
            staff_access=has_access(request.user, 'staff', usage_key.course_key),
            reset_masquerade_data=True,
        )

        sequence, _ = get_module_by_usage_id(
            self.request,
            str(usage_key.course_key),
            str(usage_key),
            disable_staff_debug_info=True,
            will_recheck_access=True)

        if not hasattr(sequence, 'get_metadata'):
            # Looks like we were asked for metadata on something that is not a sequence (or section).
            return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY)

        view = STUDENT_VIEW
        if request.user.is_anonymous:
            view = PUBLIC_VIEW

        context = {'specific_masquerade': is_masquerading_as_specific_student(request.user, usage_key.course_key)}
        return Response(sequence.get_metadata(view=view, context=context))
Beispiel #4
0
    def get(self, request, usage_key_string, *args, **kwargs):
        """
        Return response to a GET request.
        """
        usage_key = UsageKey.from_string(usage_key_string)

        sequence, _ = get_module_by_usage_id(self.request,
                                             str(usage_key.course_key),
                                             str(usage_key),
                                             disable_staff_debug_info=True)
        return Response(json.loads(sequence.handle_ajax('metadata', None)))
Beispiel #5
0
    def get(self, request, usage_key_string):
        """
        Returns an HttpResponse with HTML content for the xBlock with the given usage_key.
        The returned HTML is a chromeless rendering of the xBlock (excluding content of the containing courseware).
        """
        usage_key = UsageKey.from_string(usage_key_string)

        usage_key = usage_key.replace(course_key=modulestore().fill_in_run(usage_key.course_key))
        course_key = usage_key.course_key

        requested_view = request.GET.get('view', 'student_view')
        if requested_view != 'student_view':
            return HttpResponseBadRequest(
                "Rendering of the xblock view '{}' is not supported.".format(clean(requested_view, strip=True))
            )

        with modulestore().bulk_operations(course_key):
            # verify the user has access to the course, including enrollment check
            try:
                course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
            except CourseAccessRedirect:
                raise Http404("Course not found.")

            # get the block, which verifies whether the user has access to the block.
            block, _ = get_module_by_usage_id(
                request, text_type(course_key), text_type(usage_key), disable_staff_debug_info=True, course=course
            )

            student_view_context = request.GET.dict()
            student_view_context['show_bookmark_button'] = False

            enable_completion_on_view_service = False
            completion_service = block.runtime.service(block, 'completion')
            if completion_service and completion_service.completion_tracking_enabled():
                if completion_service.blocks_to_mark_complete_on_view({block}):
                    enable_completion_on_view_service = True
                    student_view_context['wrap_xblock_data'] = {
                        'mark-completed-on-view-after-delay': completion_service.get_complete_on_view_delay_ms()
                    }

            context = {
                'fragment': block.render('student_view', context=student_view_context),
                'course': course,
                'disable_accordion': True,
                'allow_iframing': True,
                'disable_header': True,
                'disable_footer': True,
                'disable_window_wrap': False,
                'mobile_view': True,
                'enable_completion_on_view_service': enable_completion_on_view_service,
                'staff_access': bool(has_access(request.user, 'staff', course)),
                'xqa_server': settings.FEATURES.get('XQA_SERVER', 'http://your_xqa_server.com'),
            }
            return render_to_response('courseware/courseware-chromeless.html', context)
Beispiel #6
0
    def get(self, request, usage_key_string, *args, **kwargs):
        """
        Return response to a GET request.
        """
        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError:
            raise NotFound("Invalid usage key: '{}'.".format(usage_key_string))

        sequence, _ = get_module_by_usage_id(self.request,
                                             str(usage_key.course_key),
                                             str(usage_key),
                                             disable_staff_debug_info=True)
        return Response(json.loads(sequence.handle_ajax('metadata', None)))
def _section_open_response_assessment(request, course, openassessment_blocks, access):
    """Provide data for the corresponding dashboard section """
    course_key = course.id

    ora_items = []
    parents = {}

    for block in openassessment_blocks:
        block_parent_id = str(block.parent)
        result_item_id = str(block.location)
        if block_parent_id not in parents:
            parents[block_parent_id] = modulestore().get_item(block.parent)
        assessment_name = _("Team") + " : " + block.display_name if block.teams_enabled else block.display_name
        ora_items.append({
            'id': result_item_id,
            'name': assessment_name,
            'parent_id': block_parent_id,
            'parent_name': parents[block_parent_id].display_name,
            'staff_assessment': 'staff-assessment' in block.assessment_steps,
            'peer_assessment': 'peer-assessment' in block.assessment_steps,
            'team_assignment': block.teams_enabled,
            'url_base': reverse('xblock_view', args=[course.id, block.location, 'student_view']),
            'url_grade_available_responses': reverse('xblock_view', args=[course.id, block.location,
                                                                          'grade_available_responses_view']),
            'url_waiting_step_details': reverse(
                'xblock_view',
                args=[course.id, block.location, 'waiting_step_details_view'],
            ),
        })

    openassessment_block = openassessment_blocks[0]
    block, __ = get_module_by_usage_id(
        request, str(course_key), str(openassessment_block.location),
        disable_staff_debug_info=True, course=course
    )
    section_data = {
        'fragment': block.render('ora_blocks_listing_view', context={
            'ora_items': ora_items,
            'ora_item_view_enabled': settings.FEATURES.get('ENABLE_XBLOCK_VIEW_ENDPOINT', False)
        }),
        'section_key': 'open_response_assessment',
        'section_display_name': _('Open Responses'),
        'access': access,
        'course_id': str(course_key),
    }
    return section_data
Beispiel #8
0
    def get(self, request, usage_key_string, *args, **kwargs):
        """
        Return response to a GET request.
        """
        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError:
            raise NotFound("Invalid usage key: '{}'.".format(usage_key_string))

        sequence, _ = get_module_by_usage_id(
            self.request,
            str(usage_key.course_key),
            str(usage_key),
            disable_staff_debug_info=True,
            will_recheck_access=True)

        view = STUDENT_VIEW
        if request.user.is_anonymous:
            view = PUBLIC_VIEW

        return Response(json.loads(sequence.handle_ajax('metadata', None, view=view)))
def _section_open_response_assessment(request, course, openassessment_blocks, access):
    """Provide data for the corresponding dashboard section """
    course_key = course.id

    ora_items = []
    parents = {}

    for block in openassessment_blocks:
        block_parent_id = unicode(block.parent)
        result_item_id = unicode(block.location)
        if block_parent_id not in parents:
            parents[block_parent_id] = modulestore().get_item(block.parent)

        ora_items.append({
            'id': result_item_id,
            'name': block.display_name,
            'parent_id': block_parent_id,
            'parent_name': parents[block_parent_id].display_name,
            'staff_assessment': 'staff-assessment' in block.assessment_steps,
            'url_base': reverse('xblock_view', args=[course.id, block.location, 'student_view']),
            'url_grade_available_responses': reverse('xblock_view', args=[course.id, block.location,
                                                                          'grade_available_responses_view']),
        })

    openassessment_block = openassessment_blocks[0]
    block, __ = get_module_by_usage_id(
        request, unicode(course_key), unicode(openassessment_block.location),
        disable_staff_debug_info=True, course=course
    )
    section_data = {
        'fragment': block.render('ora_blocks_listing_view', context={
            'ora_items': ora_items,
            'ora_item_view_enabled': settings.FEATURES.get('ENABLE_XBLOCK_VIEW_ENDPOINT', False)
        }),
        'section_key': 'open_response_assessment',
        'section_display_name': _('Open Responses'),
        'access': access,
        'course_id': unicode(course_key),
    }
    return section_data
def _section_recap(request, course, recap_blocks, access):
    """Provide data for the Recap dashboard section """

    course_key = course.id
    recap_items = []
    recap_fragments = []

    # Get list of enrolled students for this course

    user_list = User.objects.filter(
        courseenrollment__course_id=course_key,
        courseenrollment__is_active=1,
    ).order_by('username').select_related('profile')

    for block in recap_blocks:
        recap_items.append({
            'name':
            block.display_name,
            'block_list':
            block.xblock_list,
            'url_base':
            reverse(
                'xblock_view',
                args=[course.id, block.location, 'recap_blocks_listing_view']),
            'make_pdf_json':
            reverse('xblock_handler',
                    args=[course.id, block.location, 'make_pdf_json']),
        })

    recap_block = recap_blocks[0]
    block, __ = get_module_by_usage_id(request,
                                       unicode(course_key),
                                       unicode(recap_block.location),
                                       disable_staff_debug_info=True,
                                       course=course)
    # Set up recap instructor dashboard fragment, pass data to the context
    fragment = block.render('recap_blocks_listing_view',
                            context={
                                'recap_items': recap_items,
                                'users': user_list,
                            })
    # Wrap the fragment and get all resources associated with this XBlock view
    fragment = wrap_xblock(
        'LmsRuntime',
        recap_block,
        'recap_blocks_listing_view',
        fragment,
        None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex())

    section_data = {
        'fragment': fragment,
        'users': user_list,
        'section_key': 'recap',
        'section_display_name': _('Recap'),
        'access': access,
        'course_id': unicode(course_key)
    }

    return section_data