Пример #1
0
    def get(self,
            request,
            course_id,
            chapter=None,
            section=None,
            position=None):
        """
        Displays courseware accordion and associated content.  If course, chapter,
        and section are all specified, renders the page, or returns an error if they
        are invalid.

        If section is not specified, displays the accordion opened to the right
        chapter.

        If neither chapter or section are specified, displays the user's most
        recent chapter, or the first chapter if this is the user's first visit.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
            chapter (unicode): chapter url_name
            section (unicode): section url_name
            position (unicode): position in module, eg of <sequential> module
        """
        self.course_key = CourseKey.from_string(course_id)

        if not (request.user.is_authenticated
                or self.enable_anonymous_courseware_access):
            return redirect_to_login(request.get_full_path())

        self.original_chapter_url_name = chapter
        self.original_section_url_name = section
        self.chapter_url_name = chapter
        self.section_url_name = section
        self.position = position
        self.chapter, self.section = None, None
        self.course = None
        self.url = request.path

        try:
            set_custom_metrics_for_course_key(self.course_key)
            self._clean_position()
            with modulestore().bulk_operations(self.course_key):
                self.course = get_course_with_access(
                    request.user,
                    'load',
                    self.course_key,
                    depth=CONTENT_DEPTH,
                    check_if_enrolled=not self.
                    enable_anonymous_courseware_access,
                )
                self.is_staff = has_access(request.user, 'staff', self.course)
                self._setup_masquerade_for_effective_user()
                register_course_expired_message(request, self.course)

                return self.render(request)
        except Exception as exception:  # pylint: disable=broad-except
            return CourseTabView.handle_exceptions(request, self.course,
                                                   exception)
Пример #2
0
    def get(self, request, course_id, chapter=None, section=None, position=None):
        """
        Displays courseware accordion and associated content.  If course, chapter,
        and section are all specified, renders the page, or returns an error if they
        are invalid.

        If section is not specified, displays the accordion opened to the right
        chapter.

        If neither chapter or section are specified, displays the user's most
        recent chapter, or the first chapter if this is the user's first visit.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
            chapter (unicode): chapter url_name
            section (unicode): section url_name
            position (unicode): position in module, eg of <sequential> module
        """
        self.course_key = CourseKey.from_string(course_id)

        if not (request.user.is_authenticated or self.enable_anonymous_courseware_access):
            return redirect_to_login(request.get_full_path())

        self.original_chapter_url_name = chapter
        self.original_section_url_name = section
        self.chapter_url_name = chapter
        self.section_url_name = section
        self.position = position
        self.chapter, self.section = None, None
        self.course = None
        self.url = request.path

        try:
            set_custom_metrics_for_course_key(self.course_key)
            self._clean_position()
            with modulestore().bulk_operations(self.course_key):
                self.course = get_course_with_access(
                    request.user, 'load', self.course_key,
                    depth=CONTENT_DEPTH,
                    check_if_enrolled=not self.enable_anonymous_courseware_access,
                )
                self.is_staff = has_access(request.user, 'staff', self.course)
                self._setup_masquerade_for_effective_user()
                register_course_expired_message(request, self.course)

                return self.render(request)
        except Exception as exception:  # pylint: disable=broad-except
            return CourseTabView.handle_exceptions(request, self.course, exception)
Пример #3
0
    def test_register_course_expired_message(self, language, offsets,
                                             mock_messages):
        now = timezone.now()
        schedule_offset, course_offset = offsets

        if schedule_offset is not None:
            schedule_upgrade_deadline = now + timedelta(days=schedule_offset)
        else:
            schedule_upgrade_deadline = None

        if course_offset is not None:
            course_upgrade_deadline = now + timedelta(days=course_offset)
        else:
            course_upgrade_deadline = None

        def format_date(date):
            if language.startswith('es-'):
                return strftime_localized(date, '%-d de %b. de %Y').lower()
            else:
                return strftime_localized(date, '%b. %-d, %Y')

        patch_lang = patch(
            'openedx.features.course_duration_limits.access.get_language',
            return_value=language)
        with patch_lang:
            enrollment = CourseEnrollmentFactory.create(
                course__start=datetime(2018, 1, 1, tzinfo=UTC),
                course__self_paced=True,
            )
            CourseModeFactory.create(
                course_id=enrollment.course.id,
                mode_slug=CourseMode.VERIFIED,
                expiration_datetime=course_upgrade_deadline,
            )
            CourseModeFactory.create(
                course_id=enrollment.course.id,
                mode_slug=CourseMode.AUDIT,
            )
            ScheduleFactory.create(
                enrollment=enrollment,
                upgrade_deadline=schedule_upgrade_deadline,
            )
            request = RequestFactory().get('/courseware')
            request.user = enrollment.user

            duration_limit_upgrade_deadline = get_user_course_expiration_date(
                enrollment.user, enrollment.course)
            self.assertIsNotNone(duration_limit_upgrade_deadline)

            register_course_expired_message(request, enrollment.course)
            self.assertEqual(mock_messages.register_info_message.call_count, 1)

            message = str(mock_messages.register_info_message.call_args[0][1])

            self.assertIn(format_date(duration_limit_upgrade_deadline),
                          message)

            soft_upgradeable = schedule_upgrade_deadline is not None and now < schedule_upgrade_deadline
            upgradeable = course_upgrade_deadline is None or now < course_upgrade_deadline
            has_upgrade_deadline = course_upgrade_deadline is not None

            if upgradeable and soft_upgradeable:
                self.assertIn(format_date(schedule_upgrade_deadline), message)
            elif upgradeable and has_upgrade_deadline:
                self.assertIn(format_date(course_upgrade_deadline), message)
            else:
                self.assertNotIn("Upgrade by", message)
Пример #4
0
    def get(self,
            request,
            course_id,
            chapter=None,
            section=None,
            position=None):
        """
        Displays courseware accordion and associated content.  If course, chapter,
        and section are all specified, renders the page, or returns an error if they
        are invalid.

        If section is not specified, displays the accordion opened to the right
        chapter.

        If neither chapter or section are specified, displays the user's most
        recent chapter, or the first chapter if this is the user's first visit.

        Arguments:
            request: HTTP request
            course_id (unicode): course id
            chapter (unicode): chapter url_name
            section (unicode): section url_name
            position (unicode): position in module, eg of <sequential> module
        """
        self.course_key = CourseKey.from_string(course_id)

        if not (request.user.is_authenticated
                or self.enable_unenrolled_access):
            return redirect_to_login(request.get_full_path())

        self.original_chapter_url_name = chapter
        self.original_section_url_name = section
        self.chapter_url_name = chapter
        self.section_url_name = section
        self.position = position
        self.chapter, self.section = None, None
        self.course = None
        self.url = request.path

        try:
            set_custom_metrics_for_course_key(self.course_key)
            self._clean_position()
            with modulestore().bulk_operations(self.course_key):

                self.view = STUDENT_VIEW

                # Do the enrollment check if enable_unenrolled_access is not enabled.
                self.course = get_course_with_access(
                    request.user,
                    'load',
                    self.course_key,
                    depth=CONTENT_DEPTH,
                    check_if_enrolled=not self.enable_unenrolled_access,
                )

                if self.enable_unenrolled_access:
                    # Check if the user is considered enrolled (i.e. is an enrolled learner or staff).
                    try:
                        check_course_access(
                            self.course,
                            request.user,
                            'load',
                            check_if_enrolled=True,
                        )
                    except CourseAccessRedirect as exception:
                        # If the user is not considered enrolled:
                        if self.course.course_visibility == COURSE_VISIBILITY_PUBLIC:
                            # If course visibility is public show the XBlock public_view.
                            self.view = PUBLIC_VIEW
                        else:
                            # Otherwise deny them access.
                            raise exception
                    else:
                        # If the user is considered enrolled show the default XBlock student_view.
                        pass

                self.is_staff = has_access(request.user, 'staff', self.course)
                self._setup_masquerade_for_effective_user()
                register_course_expired_message(request, self.course)

                return self.render(request)
        except Exception as exception:  # pylint: disable=broad-except
            return CourseTabView.handle_exceptions(request, self.course,
                                                   exception)