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


Python ContentTypeGatingConfig.enabled_for_course方法代码示例

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


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

示例1: test_enabled_for_course

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_course [as 别名]
    def test_enabled_for_course(
        self,
        before_enabled,
    ):
        config = ContentTypeGatingConfig.objects.create(
            enabled=True,
            course=self.course_overview,
            enabled_as_of=timezone.now(),
        )

        # Tweak the datetime to check for course enablement so it is either
        # before or after when the configuration was enabled
        if before_enabled:
            target_datetime = config.enabled_as_of - timedelta(days=1)
        else:
            target_datetime = config.enabled_as_of + timedelta(days=1)

        course_key = self.course_overview.id

        self.assertEqual(
            not before_enabled,
            ContentTypeGatingConfig.enabled_for_course(
                course_key=course_key,
                target_datetime=target_datetime,
            )
        )
开发者ID:edx,项目名称:edx-platform,代码行数:28,代码来源:test_models.py

示例2: _get_course_duration_info

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_course [as 别名]
    def _get_course_duration_info(self, course_key):
        """
        Fetch course duration information from database
        """
        try:
            key = CourseKey.from_string(course_key)
            course = CourseOverview.objects.values('display_name').get(id=key)
            duration_config = CourseDurationLimitConfig.current(course_key=key)
            gating_config = ContentTypeGatingConfig.current(course_key=key)
            duration_enabled = CourseDurationLimitConfig.enabled_for_course(course_key=key)
            gating_enabled = ContentTypeGatingConfig.enabled_for_course(course_key=key)

            gating_dict = {
                'enabled': gating_enabled,
                'enabled_as_of': str(gating_config.enabled_as_of) if gating_config.enabled_as_of else 'N/A',
                'reason': gating_config.provenances['enabled'].value
            }
            duration_dict = {
                'enabled': duration_enabled,
                'enabled_as_of': str(duration_config.enabled_as_of) if duration_config.enabled_as_of else 'N/A',
                'reason': duration_config.provenances['enabled'].value
            }

            return {
                'course_id': course_key,
                'course_name': course.get('display_name'),
                'gating_config': gating_dict,
                'duration_config': duration_dict,
            }

        except (ObjectDoesNotExist, InvalidKeyError):
            return {}
开发者ID:edx,项目名称:edx-platform,代码行数:34,代码来源:feature_based_enrollments.py

示例3: create_content_gating_partition

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_course [as 别名]
def create_content_gating_partition(course):
    """
    Create and return the Content Gating user partition.
    """

    enabled_for_course = ContentTypeGatingConfig.enabled_for_course(course_key=course.id)
    studio_override_for_course = ContentTypeGatingConfig.current(course_key=course.id).studio_override_enabled
    if not (enabled_for_course or studio_override_for_course):
        return None

    try:
        content_gate_scheme = UserPartition.get_scheme(CONTENT_TYPE_GATING_SCHEME)
    except UserPartitionError:
        LOG.warning(
            u"No %r scheme registered, ContentTypeGatingPartitionScheme will not be created.",
            CONTENT_TYPE_GATING_SCHEME
        )
        return None

    used_ids = set(p.id for p in course.user_partitions)
    if CONTENT_GATING_PARTITION_ID in used_ids:
        # It's possible for course authors to add arbitrary partitions via XML import. If they do, and create a
        # partition with id 51, it will collide with the Content Gating Partition. We'll catch that here, and
        # then fix the course content as needed (or get the course team to).
        LOG.warning(
            u"Can't add %r partition, as ID %r is assigned to %r in course %s.",
            CONTENT_TYPE_GATING_SCHEME,
            CONTENT_GATING_PARTITION_ID,
            _get_partition_from_id(course.user_partitions, CONTENT_GATING_PARTITION_ID).name,
            unicode(course.id),
        )
        return None

    partition = content_gate_scheme.create_user_partition(
        id=CONTENT_GATING_PARTITION_ID,
        name=_(u"Feature-based Enrollments"),
        description=_(u"Partition for segmenting users by access to gated content types"),
        parameters={"course_id": unicode(course.id)}
    )
    return partition
开发者ID:mitodl,项目名称:edx-platform,代码行数:42,代码来源:partitions.py

示例4: get

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_course [as 别名]

#.........这里部分代码省略.........
        # 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)

        bundle_data = {}
        bundles_on_track_selection = WaffleFlag(WaffleFlagNamespace(name=u'experiments'), u'bundles_on_track_selection')
        if bundles_on_track_selection.is_enabled():
            # enrollment in the course on this page
            current_enrollment = list(CourseEnrollment.enrollments_for_user(request.user).filter(course_id=course_key))
            if current_enrollment:
                meter = ProgramProgressMeter(request.site, request.user, enrollments=current_enrollment)
                meter_inverted_programs = meter.invert_programs()
                if len(meter_inverted_programs) > 0:
                    # program for the course on this page
                    programs_for_course = meter_inverted_programs.get(course_id)
                    if programs_for_course:
                        program_for_course = programs_for_course[0]
                        program_uuid = program_for_course.get('uuid')
                        if program_for_course:
                            # program data with bundle info
                            program_data = ProgramDataExtender(program_for_course, request.user, mobile_only=False).extend()
                            skus = program_data.get('skus')
                            ecommerce_service = EcommerceService()
                            program_bundle_url = ecommerce_service.get_checkout_page_url(*skus, program_uuid=program_uuid)
                            bundle_data = {
                                'program_marketing_site_url': program_data.get('marketing_url'),
                                'program_bundle_url': program_bundle_url,
                                'discount_data': program_data.get('discount_data'),
                                'program_type': program_data.get('type'),
                                'program_title': program_data.get('title'),
                                'program_price': program_data.get('full_program_price'),
                            }

        context = {
            "bundle_data": bundle_data,
            "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_course(course_key=course_key),
        }
        context.update(
            get_experiment_user_metadata_context(
                course,
                request.user,
            )
        )

        title_content = _("Congratulations!  You are now enrolled in {course_name}").format(
            course_name=course.display_name_with_default
        )

        context["title_content"] = title_content

        if "verified" in modes:
            verified_mode = modes["verified"]
            context["suggested_prices"] = [
                decimal.Decimal(x.strip())
                for x in verified_mode.suggested_prices.split(",")
                if x.strip()
            ]
            context["currency"] = verified_mode.currency.upper()
            context["min_price"] = verified_mode.min_price
            context["verified_name"] = verified_mode.name
            context["verified_description"] = verified_mode.description

            if verified_mode.sku:
                context["use_ecommerce_payment_flow"] = ecommerce_service.is_enabled(request.user)
                context["ecommerce_payment_page"] = ecommerce_service.payment_page_url()
                context["sku"] = verified_mode.sku
                context["bulk_sku"] = verified_mode.bulk_sku

        context['currency_data'] = []
        if waffle.switch_is_active('local_currency'):
            if 'edx-price-l10n' not in request.COOKIES:
                currency_data = get_currency_data()
                try:
                    context['currency_data'] = json.dumps(currency_data)
                except TypeError:
                    pass
        return render_to_response("course_modes/choose.html", context)
开发者ID:mitocw,项目名称:edx-platform,代码行数:104,代码来源:views.py

示例5: enabled_for

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import enabled_for_course [as 别名]
 def enabled_for(cls, course):
     """This simple override provider is always enabled"""
     return ContentTypeGatingConfig.enabled_for_course(course_key=course.scope_ids.usage_id.course_key)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:5,代码来源:field_override.py


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