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


Python models.CourseDurationLimitConfig类代码示例

本文整理汇总了Python中openedx.features.course_duration_limits.models.CourseDurationLimitConfig的典型用法代码示例。如果您正苦于以下问题:Python CourseDurationLimitConfig类的具体用法?Python CourseDurationLimitConfig怎么用?Python CourseDurationLimitConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: _get_course_duration_info

    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,代码行数:32,代码来源:feature_based_enrollments.py

示例2: test_config_overrides

    def test_config_overrides(self, global_setting, site_setting, org_setting, course_setting, reverse_order):
        """
        Test that the stacked configuration overrides happen in the correct order and priority.

        This is tested by exhaustively setting each combination of contexts, and validating that only
        the lowest level context that is set to not-None is applied.
        """
        # Add a bunch of configuration outside the contexts that are being tested, to make sure
        # there are no leaks of configuration across contexts
        non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled')
        non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled')
        non_test_site_cfg_enabled = SiteConfigurationFactory.create(
            values={'course_org_filter': non_test_course_enabled.org}
        )
        non_test_site_cfg_disabled = SiteConfigurationFactory.create(
            values={'course_org_filter': non_test_course_disabled.org}
        )

        CourseDurationLimitConfig.objects.create(course=non_test_course_enabled, enabled=True)
        CourseDurationLimitConfig.objects.create(course=non_test_course_disabled, enabled=False)
        CourseDurationLimitConfig.objects.create(org=non_test_course_enabled.org, enabled=True)
        CourseDurationLimitConfig.objects.create(org=non_test_course_disabled.org, enabled=False)
        CourseDurationLimitConfig.objects.create(site=non_test_site_cfg_enabled.site, enabled=True)
        CourseDurationLimitConfig.objects.create(site=non_test_site_cfg_disabled.site, enabled=False)

        # Set up test objects
        test_course = CourseOverviewFactory.create(org='test-org')
        test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': test_course.org})

        if reverse_order:
            CourseDurationLimitConfig.objects.create(site=test_site_cfg.site, enabled=site_setting)
            CourseDurationLimitConfig.objects.create(org=test_course.org, enabled=org_setting)
            CourseDurationLimitConfig.objects.create(course=test_course, enabled=course_setting)
            CourseDurationLimitConfig.objects.create(enabled=global_setting)
        else:
            CourseDurationLimitConfig.objects.create(enabled=global_setting)
            CourseDurationLimitConfig.objects.create(course=test_course, enabled=course_setting)
            CourseDurationLimitConfig.objects.create(org=test_course.org, enabled=org_setting)
            CourseDurationLimitConfig.objects.create(site=test_site_cfg.site, enabled=site_setting)

        expected_global_setting = self._resolve_settings([global_setting])
        expected_site_setting = self._resolve_settings([global_setting, site_setting])
        expected_org_setting = self._resolve_settings([global_setting, site_setting, org_setting])
        expected_course_setting = self._resolve_settings([global_setting, site_setting, org_setting, course_setting])

        self.assertEqual(expected_global_setting, CourseDurationLimitConfig.current().enabled)
        self.assertEqual(expected_site_setting, CourseDurationLimitConfig.current(site=test_site_cfg.site).enabled)
        self.assertEqual(expected_org_setting, CourseDurationLimitConfig.current(org=test_course.org).enabled)
        self.assertEqual(expected_course_setting, CourseDurationLimitConfig.current(course_key=test_course.id).enabled)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:49,代码来源:test_models.py

示例3: test_course_messaging_for_staff

 def test_course_messaging_for_staff(self):
     """
     Staff users will not see the expiration banner when course duration limits
     are on for the course.
     """
     config = CourseDurationLimitConfig(
         course=CourseOverview.get_from_id(self.course.id),
         enabled=True,
         enabled_as_of=datetime(2018, 1, 1)
     )
     config.save()
     url = course_home_url(self.course)
     CourseEnrollment.enroll(self.staff_user, self.course.id)
     response = self.client.get(url)
     bannerText = get_expiration_banner_text(self.staff_user, self.course)
     self.assertNotContains(response, bannerText, html=True)
开发者ID:mitocw,项目名称:edx-platform,代码行数:16,代码来源:test_course_home.py

示例4: test_enabled_for_course

    def test_enabled_for_course(
        self,
        before_enabled,
    ):
        config = CourseDurationLimitConfig.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,
            CourseDurationLimitConfig.enabled_for_course(
                course_key=course_key,
                target_datetime=target_datetime,
            )
        )
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:26,代码来源:test_models.py

示例5: test_enabled_for_enrollment_flag_override

 def test_enabled_for_enrollment_flag_override(self):
     self.assertTrue(CourseDurationLimitConfig.enabled_for_enrollment(
         None,
         None,
         None
     ))
     self.assertTrue(CourseDurationLimitConfig.enabled_for_enrollment(
         Mock(name='enrollment'),
         Mock(name='user'),
         None
     ))
     self.assertTrue(CourseDurationLimitConfig.enabled_for_enrollment(
         Mock(name='enrollment'),
         None,
         Mock(name='course_key')
     ))
开发者ID:mitocw,项目名称:edx-platform,代码行数:16,代码来源:test_models.py

示例6: get_audit_access_expires

    def get_audit_access_expires(self, model):
        """
        Returns expiration date for a course audit expiration, if any or null
        """
        if not CourseDurationLimitConfig.enabled_for_enrollment(user=model.user, course_key=model.course.id):
            return None

        return get_user_course_expiration_date(model.user, model.course)
开发者ID:jolyonb,项目名称:edx-platform,代码行数:8,代码来源:serializers.py

示例7: test_all_current_course_configs

    def test_all_current_course_configs(self):
        # Set up test objects
        for global_setting in (True, False, None):
            CourseDurationLimitConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1))
            for site_setting in (True, False, None):
                test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': []})
                CourseDurationLimitConfig.objects.create(
                    site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)
                )

                for org_setting in (True, False, None):
                    test_org = "{}-{}".format(test_site_cfg.id, org_setting)
                    test_site_cfg.values['course_org_filter'].append(test_org)
                    test_site_cfg.save()

                    CourseDurationLimitConfig.objects.create(
                        org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1)
                    )

                    for course_setting in (True, False, None):
                        test_course = CourseOverviewFactory.create(
                            org=test_org,
                            id=CourseLocator(test_org, 'test_course', 'run-{}'.format(course_setting))
                        )
                        CourseDurationLimitConfig.objects.create(
                            course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1)
                        )

            with self.assertNumQueries(4):
                all_configs = CourseDurationLimitConfig.all_current_course_configs()

        # Deliberatly using the last all_configs that was checked after the 3rd pass through the global_settings loop
        # We should be creating 3^4 courses (3 global values * 3 site values * 3 org values * 3 course values)
        # Plus 1 for the edX/toy/2012_Fall course
        self.assertEqual(len(all_configs), 3**4 + 1)

        # Point-test some of the final configurations
        self.assertEqual(
            all_configs[CourseLocator('7-True', 'test_course', 'run-None')],
            {
                'enabled': (True, Provenance.org),
                'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
            }
        )
        self.assertEqual(
            all_configs[CourseLocator('7-True', 'test_course', 'run-False')],
            {
                'enabled': (False, Provenance.run),
                'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
            }
        )
        self.assertEqual(
            all_configs[CourseLocator('7-None', 'test_course', 'run-None')],
            {
                'enabled': (True, Provenance.site),
                'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
            }
        )
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:58,代码来源:test_models.py

示例8: get_audit_access_expiration

def get_audit_access_expiration(user, course):
    """
    Return the expiration date for the user's audit access to this course.
    """
    if AUDIT_DEADLINE_FLAG.is_enabled():
        if not CourseDurationLimitConfig.enabled_for_enrollment(user=user, course_key=course.id):
            return None

        return get_user_course_expiration_date(user, course)
    return None
开发者ID:edx,项目名称:edx-platform,代码行数:10,代码来源:utils.py

示例9: test_caching_global

    def test_caching_global(self):
        global_config = CourseDurationLimitConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
        global_config.save()

        # Check that the global value is not retrieved from cache after save
        with self.assertNumQueries(1):
            self.assertTrue(CourseDurationLimitConfig.current().enabled)

        # Check that the global value can be retrieved from cache after read
        with self.assertNumQueries(0):
            self.assertTrue(CourseDurationLimitConfig.current().enabled)

        global_config.enabled = False
        global_config.save()

        # Check that the global value in cache was deleted on save
        with self.assertNumQueries(1):
            self.assertFalse(CourseDurationLimitConfig.current().enabled)
开发者ID:mitocw,项目名称:edx-platform,代码行数:18,代码来源:test_models.py

示例10: test_course_expiration_banner_with_unicode

    def test_course_expiration_banner_with_unicode(self, mock_strftime_localized, mock_get_date_string):
        """
        Ensure that switching to other languages that have unicode in their
        date representations will not cause the course home page to 404.
        """
        fake_unicode_start_time = u"üñîçø∂é_ßtå®t_tîµé"
        mock_strftime_localized.return_value = fake_unicode_start_time
        date_string = u'<span class="localized-datetime" data-format="shortDate" \
        data-datetime="{formatted_date}" data-language="{language}">{formatted_date_localized}</span>'
        mock_get_date_string.return_value = date_string

        config = CourseDurationLimitConfig(
            course=CourseOverview.get_from_id(self.course.id),
            enabled=True,
            enabled_as_of=datetime(2018, 1, 1)
        )
        config.save()
        url = course_home_url(self.course)
        user = self.create_user_for_course(self.course, CourseUserType.UNENROLLED)
        CourseEnrollment.enroll(user, self.course.id)

        language = 'eo'
        DarkLangConfig(
            released_languages=language,
            changed_by=user,
            enabled=True
        ).save()

        response = self.client.get(url, HTTP_ACCEPT_LANGUAGE=language)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Language'], language)

        # Check that if the string is incorrectly not marked as unicode we still get the error
        with mock.patch("openedx.features.course_duration_limits.access.get_date_string",
                        return_value=date_string.encode('utf-8')):
            response = self.client.get(url, HTTP_ACCEPT_LANGUAGE=language)
            self.assertEqual(response.status_code, 500)
开发者ID:edx,项目名称:edx-platform,代码行数:37,代码来源:test_course_home.py

示例11: test_enabled_for_enrollment

    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 = timezone.now() + timedelta(days=1)
        else:
            enabled_as_of = timezone.now() - timedelta(days=1)

        CourseDurationLimitConfig.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

        query_count = 7
        if pass_enrollment and already_enrolled:
            query_count = 6

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

示例12: check_course_expired

def check_course_expired(user, course):
    """
    Check if the course expired for the user.
    """
    # masquerading course staff should always have access
    if get_course_masquerade(user, course.id):
        return ACCESS_GRANTED

    if not CourseDurationLimitConfig.enabled_for_enrollment(user=user, course_key=course.id):
        return ACCESS_GRANTED

    expiration_date = get_user_course_expiration_date(user, course)
    if expiration_date and timezone.now() > expiration_date:
        return AuditExpiredError(user, course, expiration_date)

    return ACCESS_GRANTED
开发者ID:mitocw,项目名称:edx-platform,代码行数:16,代码来源:access.py

示例13: test_enabled_for_enrollment_failure

 def test_enabled_for_enrollment_failure(self):
     with self.assertRaises(ValueError):
         CourseDurationLimitConfig.enabled_for_enrollment(None, None, None)
     with self.assertRaises(ValueError):
         CourseDurationLimitConfig.enabled_for_enrollment(
             Mock(name='enrollment'),
             Mock(name='user'),
             None
         )
     with self.assertRaises(ValueError):
         CourseDurationLimitConfig.enabled_for_enrollment(
             Mock(name='enrollment'),
             None,
             Mock(name='course_key')
         )
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:15,代码来源:test_models.py

示例14: _get_course_duration_info

    def _get_course_duration_info(self, course_key):
        """
        Fetch course duration information from database
        """
        results = []

        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)
            partially_enabled = duration_config.enabled != gating_config.enabled

            if partially_enabled:
                if duration_config.enabled:
                    enabled = 'Course Duration Limits Only'
                    enabled_as_of = str(duration_config.enabled_as_of) if duration_config.enabled_as_of else 'N/A'
                    reason = 'Course duration limits are enabled for this course, but content type gating is disabled.'
                elif gating_config.enabled:
                    enabled = 'Content Type Gating Only'
                    enabled_as_of = str(gating_config.enabled_as_of) if gating_config.enabled_as_of else 'N/A'
                    reason = 'Content type gating is enabled for this course, but course duration limits are disabled.'
            else:
                enabled = duration_config.enabled or False
                enabled_as_of = str(duration_config.enabled_as_of) if duration_config.enabled_as_of else 'N/A'
                reason = duration_config.provenances['enabled']

            data = {
                'course_id': course_key,
                'course_name': course.get('display_name'),
                'enabled': enabled,
                'enabled_as_of': enabled_as_of,
                'reason': reason,
            }
            results.append(data)

        except (ObjectDoesNotExist, InvalidKeyError):
            pass

        return results
开发者ID:mitodl,项目名称:edx-platform,代码行数:40,代码来源:feature_based_enrollments.py

示例15: register_course_expired_message

def register_course_expired_message(request, course):
    """
    Add a banner notifying the user of the user course expiration date if it exists.
    """
    if not CourseDurationLimitConfig.enabled_for_enrollment(user=request.user, course_key=course.id):
        return

    expiration_date = get_user_course_expiration_date(request.user, course)
    if not expiration_date:
        return

    if is_masquerading_as_student(request.user, course.id) and timezone.now() > expiration_date:
        upgrade_message = _('This learner would not have access to this course. '
                            'Their access expired on {expiration_date}.')
        PageLevelMessages.register_warning_message(
            request,
            HTML(upgrade_message).format(
                expiration_date=expiration_date.strftime('%b %-d')
            )
        )
    else:
        upgrade_message = _('Your access to this course expires on {expiration_date}. \
                    {a_open}Upgrade now {sronly_span_open}to retain access past {expiration_date}.\
                    {span_close}{a_close}{sighted_only_span_open}for unlimited access.{span_close}')
        PageLevelMessages.register_info_message(
            request,
            Text(upgrade_message).format(
                a_open=HTML('<a href="{upgrade_link}">').format(
                    upgrade_link=verified_upgrade_deadline_link(user=request.user, course=course)
                ),
                sronly_span_open=HTML('<span class="sr-only">'),
                sighted_only_span_open=HTML('<span aria-hidden="true">'),
                span_close=HTML('</span>'),
                a_close=HTML('</a>'),
                expiration_date=expiration_date.strftime('%b %-d'),
            )
        )
开发者ID:mitocw,项目名称:edx-platform,代码行数:37,代码来源:access.py


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