本文整理汇总了Python中openedx.features.course_duration_limits.models.CourseDurationLimitConfig.enabled_for_course方法的典型用法代码示例。如果您正苦于以下问题:Python CourseDurationLimitConfig.enabled_for_course方法的具体用法?Python CourseDurationLimitConfig.enabled_for_course怎么用?Python CourseDurationLimitConfig.enabled_for_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.features.course_duration_limits.models.CourseDurationLimitConfig
的用法示例。
在下文中一共展示了CourseDurationLimitConfig.enabled_for_course方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enabled_for_course
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_course [as 别名]
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,
)
)
示例2: _get_course_duration_info
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig 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 {}