当前位置: 首页>>代码示例>>Python>>正文


Python ContentTypeGatingConfig.enabled_for_enrollment方法代码示例

本文整理汇总了Python中openedx.features.content_type_gating.models.ContentTypeGatingConfig.enabled_for_enrollment方法的典型用法代码示例。如果您正苦于以下问题:Python ContentTypeGatingConfig.enabled_for_enrollment方法的具体用法?Python ContentTypeGatingConfig.enabled_for_enrollment怎么用?Python ContentTypeGatingConfig.enabled_for_enrollment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openedx.features.content_type_gating.models.ContentTypeGatingConfig的用法示例。


在下文中一共展示了ContentTypeGatingConfig.enabled_for_enrollment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_group_for_user

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
 def get_group_for_user(cls, course_key, user, user_partition, **kwargs):  # pylint: disable=unused-argument
     """
     Returns the Group for the specified user.
     """
     if not ContentTypeGatingConfig.enabled_for_enrollment(user=user, course_key=course_key,
                                                           user_partition=user_partition):
         return FULL_ACCESS
     else:
         return LIMITED_ACCESS
开发者ID:edx,项目名称:edx-platform,代码行数:11,代码来源:partitions.py

示例2: test_enabled_for_enrollment_failure

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
 def test_enabled_for_enrollment_failure(self):
     with self.assertRaises(ValueError):
         ContentTypeGatingConfig.enabled_for_enrollment(None, None, None)
     with self.assertRaises(ValueError):
         ContentTypeGatingConfig.enabled_for_enrollment(Mock(name='enrollment'), Mock(name='user'), None)
     with self.assertRaises(ValueError):
         ContentTypeGatingConfig.enabled_for_enrollment(Mock(name='enrollment'), None, Mock(name='course_key'))
开发者ID:edx,项目名称:edx-platform,代码行数:9,代码来源:test_models.py

示例3: test_enabled_for_enrollment

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
    def test_enabled_for_enrollment(
        self,
        already_enrolled,
        pass_enrollment,
        enrolled_before_enabled,
    ):

        # Tweak the datetime to enable the config so that it is either before
        # or after now (which is when the enrollment will be created)
        if enrolled_before_enabled:
            enabled_as_of = datetime.now() + timedelta(days=1)
        else:
            enabled_as_of = datetime.now() - timedelta(days=1)

        config = ContentTypeGatingConfig.objects.create(
            enabled=True,
            course=self.course_overview,
            enabled_as_of=enabled_as_of,
        )

        if already_enrolled:
            existing_enrollment = CourseEnrollmentFactory.create(
                user=self.user,
                course=self.course_overview,
            )
        else:
            existing_enrollment = None

        if pass_enrollment:
            enrollment = existing_enrollment
            user = None
            course_key = None
        else:
            enrollment = None
            user = self.user
            course_key = self.course_overview.id

        if already_enrolled and pass_enrollment:
            query_count = 4
        elif not pass_enrollment and already_enrolled:
            query_count = 6
        else:
            query_count = 5

        with self.assertNumQueries(query_count):
            enabled = ContentTypeGatingConfig.enabled_for_enrollment(
                enrollment=enrollment,
                user=user,
                course_key=course_key,
            )
            self.assertEqual(not enrolled_before_enabled, enabled)
开发者ID:mitocw,项目名称:edx-platform,代码行数:53,代码来源:test_models.py

示例4: get_group_for_user

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
    def get_group_for_user(cls, course_key, user, user_partition, **kwargs):  # pylint: disable=unused-argument
        """
        Returns the Group for the specified user.
        """

        # For now, treat everyone as a Full-access user, until we have the rest of the
        # feature gating logic in place.

        if not ContentTypeGatingConfig.enabled_for_enrollment(user=user, course_key=course_key,
                                                              user_partition=user_partition):
            return FULL_ACCESS

        # If CONTENT_TYPE_GATING is enabled use the following logic to determine whether a user should have FULL_ACCESS
        # or LIMITED_ACCESS

        course_mode = apps.get_model('course_modes.CourseMode')
        modes = course_mode.modes_for_course(course_key, include_expired=True, only_selectable=False)
        modes_dict = {mode.slug: mode for mode in modes}

        # If there is no verified mode, all users are granted FULL_ACCESS
        if not course_mode.has_verified_mode(modes_dict):
            return FULL_ACCESS

        course_enrollment = apps.get_model('student.CourseEnrollment')

        mode_slug, is_active = course_enrollment.enrollment_mode_for_user(user, course_key)

        if mode_slug and is_active:
            course_mode = course_mode.mode_for_course(
                course_key,
                mode_slug,
                modes=modes,
            )
            if course_mode is None:
                LOG.error(
                    u"User %s is in an unknown CourseMode '%s'"
                    u" for course %s. Granting full access to content for this user",
                    user.username,
                    mode_slug,
                    course_key,
                )
                return FULL_ACCESS

            if mode_slug == CourseMode.AUDIT:
                return LIMITED_ACCESS
            else:
                return FULL_ACCESS
        else:
            # Unenrolled users don't get gated content
            return LIMITED_ACCESS
开发者ID:mitodl,项目名称:edx-platform,代码行数:52,代码来源:partitions.py

示例5: transform

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
    def transform(self, usage_info, block_structure):
        if not ContentTypeGatingConfig.enabled_for_enrollment(
            user=usage_info.user,
            course_key=usage_info.course_key,
        ):
            return

        for block_key in block_structure.topological_traversal():
            graded = block_structure.get_xblock_field(block_key, 'graded')
            has_score = block_structure.get_xblock_field(block_key, 'has_score')
            weight_not_zero = block_structure.get_xblock_field(block_key, 'weight') != 0
            problem_eligible_for_content_gating = graded and has_score and weight_not_zero
            if problem_eligible_for_content_gating:
                current_access = block_structure.get_xblock_field(block_key, 'group_access')
                if current_access is None:
                    current_access = {}
                current_access.setdefault(
                    CONTENT_GATING_PARTITION_ID,
                    [settings.CONTENT_TYPE_GATE_GROUP_IDS['full_access']]
                )
                block_structure.override_xblock_field(block_key, 'group_access', current_access)
开发者ID:mitocw,项目名称:edx-platform,代码行数:23,代码来源:block_transformers.py

示例6: get

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
    def get(self, request, course_id, error=None):
        """Displays the course mode choice page.

        Args:
            request (`Request`): The Django Request object.
            course_id (unicode): The slash-separated course key.

        Keyword Args:
            error (unicode): If provided, display this error message
                on the page.

        Returns:
            Response

        """
        course_key = CourseKey.from_string(course_id)

        # Check whether the user has access to this course
        # based on country access rules.
        embargo_redirect = embargo_api.redirect_if_blocked(
            course_key,
            user=request.user,
            ip_address=get_ip(request),
            url=request.path
        )
        if embargo_redirect:
            return redirect(embargo_redirect)

        enrollment_mode, is_active = CourseEnrollment.enrollment_mode_for_user(request.user, course_key)
        modes = CourseMode.modes_for_course_dict(course_key)
        ecommerce_service = EcommerceService()

        # We assume that, if 'professional' is one of the modes, it should be the *only* mode.
        # If there are both modes, default to non-id-professional.
        has_enrolled_professional = (CourseMode.is_professional_slug(enrollment_mode) and is_active)
        if CourseMode.has_professional_mode(modes) and not has_enrolled_professional:
            purchase_workflow = request.GET.get("purchase_workflow", "single")
            verify_url = reverse('verify_student_start_flow', kwargs={'course_id': unicode(course_key)})
            redirect_url = "{url}?purchase_workflow={workflow}".format(url=verify_url, workflow=purchase_workflow)
            if ecommerce_service.is_enabled(request.user):
                professional_mode = modes.get(CourseMode.NO_ID_PROFESSIONAL_MODE) or modes.get(CourseMode.PROFESSIONAL)
                if purchase_workflow == "single" and professional_mode.sku:
                    redirect_url = ecommerce_service.get_checkout_page_url(professional_mode.sku)
                if purchase_workflow == "bulk" and professional_mode.bulk_sku:
                    redirect_url = ecommerce_service.get_checkout_page_url(professional_mode.bulk_sku)
            return redirect(redirect_url)

        course = modulestore().get_course(course_key)

        # If there isn't a verified mode available, then there's nothing
        # to do on this page.  Send the user to the dashboard.
        if not CourseMode.has_verified_mode(modes):
            return redirect(reverse('dashboard'))

        # If a user has already paid, redirect them to the dashboard.
        if is_active and (enrollment_mode in CourseMode.VERIFIED_MODES + [CourseMode.NO_ID_PROFESSIONAL_MODE]):
            # If the course has started redirect to course home instead
            if course.has_started():
                return redirect(reverse('openedx.course_experience.course_home', kwargs={'course_id': course_key}))
            return redirect(reverse('dashboard'))

        donation_for_course = request.session.get("donation_for_course", {})
        chosen_price = donation_for_course.get(unicode(course_key), None)

        if CourseEnrollment.is_enrollment_closed(request.user, course):
            locale = to_locale(get_language())
            enrollment_end_date = format_datetime(course.enrollment_end, 'short', locale=locale)
            params = urllib.urlencode({'course_closed': enrollment_end_date})
            return redirect('{0}?{1}'.format(reverse('dashboard'), params))

        # When a credit mode is available, students will be given the option
        # to upgrade from a verified mode to a credit mode at the end of the course.
        # This allows students who have completed photo verification to be eligible
        # for univerity credit.
        # Since credit isn't one of the selectable options on the track selection page,
        # we need to check *all* available course modes in order to determine whether
        # a credit mode is available.  If so, then we show slightly different messaging
        # for the verified track.
        has_credit_upsell = any(
            CourseMode.is_credit_mode(mode) for mode
            in CourseMode.modes_for_course(course_key, only_selectable=False)
        )
        course_id = text_type(course_key)

        context = {
            "course_modes_choose_url": reverse(
                "course_modes_choose",
                kwargs={'course_id': course_id}
            ),
            "modes": modes,
            "has_credit_upsell": has_credit_upsell,
            "course_name": course.display_name_with_default,
            "course_org": course.display_org_with_default,
            "course_num": course.display_number_with_default,
            "chosen_price": chosen_price,
            "error": error,
            "responsive": True,
            "nav_hidden": True,
            "content_gating_enabled": ContentTypeGatingConfig.enabled_for_enrollment(
                user=request.user,
#.........这里部分代码省略.........
开发者ID:jolyonb,项目名称:edx-platform,代码行数:103,代码来源:views.py

示例7: get_group_for_user

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
    def get_group_for_user(cls, course_key, user, user_partition, **kwargs):  # pylint: disable=unused-argument
        """
        Returns the Group for the specified user.
        """

        # First, check if we have to deal with masquerading.
        # If the current user is masquerading as a specific student, use the
        # same logic as normal to return that student's group. If the current
        # user is masquerading as a generic student in a specific group, then
        # return that group.
        course_masquerade = get_course_masquerade(user, course_key)
        if course_masquerade and not is_masquerading_as_specific_student(user, course_key):
            masquerade_group = get_masquerading_user_group(course_key, user, user_partition)
            if masquerade_group is not None:
                return masquerade_group
            else:
                audit_mode_id = settings.COURSE_ENROLLMENT_MODES.get(CourseMode.AUDIT, {}).get('id')
                if course_masquerade.user_partition_id == ENROLLMENT_TRACK_PARTITION_ID:
                    if course_masquerade.group_id != audit_mode_id:
                        return cls.FULL_ACCESS
                    else:
                        return cls.LIMITED_ACCESS

        # For now, treat everyone as a Full-access user, until we have the rest of the
        # feature gating logic in place.

        if not ContentTypeGatingConfig.enabled_for_enrollment(user=user, course_key=course_key):
            return cls.FULL_ACCESS

        # If CONTENT_TYPE_GATING is enabled use the following logic to determine whether a user should have FULL_ACCESS
        # or LIMITED_ACCESS

        course_mode = apps.get_model('course_modes.CourseMode')
        modes = course_mode.modes_for_course(course_key, include_expired=True, only_selectable=False)
        modes_dict = {mode.slug: mode for mode in modes}

        # If there is no verified mode, all users are granted FULL_ACCESS
        if not course_mode.has_verified_mode(modes_dict):
            return cls.FULL_ACCESS

        # If the user is a beta tester for this course they are granted FULL_ACCESS
        if CourseBetaTesterRole(course_key).has_user(user):
            return cls.FULL_ACCESS

        course_enrollment = apps.get_model('student.CourseEnrollment')

        mode_slug, is_active = course_enrollment.enrollment_mode_for_user(user, course_key)

        if mode_slug and is_active:
            course_mode = course_mode.mode_for_course(
                course_key,
                mode_slug,
                modes=modes,
            )
            if course_mode is None:
                LOG.error(
                    "User %s is in an unknown CourseMode '%s'"
                    " for course %s. Granting full access to content for this user",
                    user.username,
                    mode_slug,
                    course_key,
                )
                return cls.FULL_ACCESS

            if mode_slug == CourseMode.AUDIT:
                return cls.LIMITED_ACCESS
            else:
                return cls.FULL_ACCESS
        else:
            # Unenrolled users don't get gated content
            return cls.LIMITED_ACCESS
开发者ID:mitocw,项目名称:edx-platform,代码行数:73,代码来源:partitions.py

示例8: test_enabled_for_enrollment_flag_override

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_enrollment [as 别名]
 def test_enabled_for_enrollment_flag_override(self):
     self.assertTrue(ContentTypeGatingConfig.enabled_for_enrollment(None, None, None))
     self.assertTrue(ContentTypeGatingConfig.enabled_for_enrollment(Mock(name='enrollment'), Mock(name='user'), None))
     self.assertTrue(ContentTypeGatingConfig.enabled_for_enrollment(Mock(name='enrollment'), None, Mock(name='course_key')))
开发者ID:mitocw,项目名称:edx-platform,代码行数:6,代码来源:test_models.py


注:本文中的openedx.features.content_type_gating.models.ContentTypeGatingConfig.enabled_for_enrollment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。