本文整理汇总了Python中openedx.features.course_duration_limits.models.CourseDurationLimitConfig.enabled_for_enrollment方法的典型用法代码示例。如果您正苦于以下问题:Python CourseDurationLimitConfig.enabled_for_enrollment方法的具体用法?Python CourseDurationLimitConfig.enabled_for_enrollment怎么用?Python CourseDurationLimitConfig.enabled_for_enrollment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.features.course_duration_limits.models.CourseDurationLimitConfig
的用法示例。
在下文中一共展示了CourseDurationLimitConfig.enabled_for_enrollment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enabled_for_enrollment_flag_override
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_enrollment [as 别名]
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')
))
示例2: get_audit_access_expires
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_enrollment [as 别名]
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)
示例3: get_audit_access_expiration
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_enrollment [as 别名]
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
示例4: test_enabled_for_enrollment
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig 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 = 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)
示例5: check_course_expired
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_enrollment [as 别名]
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
示例6: test_enabled_for_enrollment_failure
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_enrollment [as 别名]
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')
)
示例7: register_course_expired_message
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_enrollment [as 别名]
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'),
)
)
示例8: get
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig 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,
#.........这里部分代码省略.........
示例9: generate_course_expired_message
# 需要导入模块: from openedx.features.course_duration_limits.models import CourseDurationLimitConfig [as 别名]
# 或者: from openedx.features.course_duration_limits.models.CourseDurationLimitConfig import enabled_for_enrollment [as 别名]
def generate_course_expired_message(user, course):
"""
Generate the message for the user course expiration date if it exists.
"""
if not CourseDurationLimitConfig.enabled_for_enrollment(user=user, course_key=course.id):
return
expiration_date = get_user_course_expiration_date(user, course)
if not expiration_date:
return
if is_masquerading_as_specific_student(user, course.id) and timezone.now() > expiration_date:
upgrade_message = _('This learner does not have access to this course. '
u'Their access expired on {expiration_date}.')
return HTML(upgrade_message).format(
expiration_date=strftime_localized(expiration_date, EXPIRATION_DATE_FORMAT_STR)
)
else:
enrollment = CourseEnrollment.get_enrollment(user, course.id)
if enrollment is None:
return
upgrade_deadline = enrollment.upgrade_deadline
now = timezone.now()
course_upgrade_deadline = enrollment.course_upgrade_deadline
if (not upgrade_deadline) or (upgrade_deadline < now):
upgrade_deadline = course_upgrade_deadline
expiration_message = _(u'{strong_open}Audit Access Expires {expiration_date}{strong_close}'
u'{line_break}You lose all access to this course, including your progress, on '
u'{expiration_date}.')
upgrade_deadline_message = _(u'{line_break}Upgrade by {upgrade_deadline} to get unlimited access to the course '
u'as long as it exists on the site. {a_open}Upgrade now{sronly_span_open} to '
u'retain access past {expiration_date}{span_close}{a_close}')
full_message = expiration_message
if upgrade_deadline and now < upgrade_deadline:
full_message += upgrade_deadline_message
using_upgrade_messaging = True
else:
using_upgrade_messaging = False
language = get_language()
date_string = get_date_string()
formatted_expiration_date = date_string.format(
language=language,
formatted_date=expiration_date.strftime("%Y-%m-%d"),
formatted_date_localized=strftime_localized(expiration_date, EXPIRATION_DATE_FORMAT_STR)
)
if using_upgrade_messaging:
formatted_upgrade_deadline = date_string.format(
language=language,
formatted_date=upgrade_deadline.strftime("%Y-%m-%d"),
formatted_date_localized=strftime_localized(upgrade_deadline, EXPIRATION_DATE_FORMAT_STR)
)
return HTML(full_message).format(
a_open=HTML(u'<a href="{upgrade_link}">').format(
upgrade_link=verified_upgrade_deadline_link(user=user, course=course)
),
sronly_span_open=HTML('<span class="sr-only">'),
span_close=HTML('</span>'),
a_close=HTML('</a>'),
expiration_date=HTML(formatted_expiration_date),
strong_open=HTML('<strong>'),
strong_close=HTML('</strong>'),
line_break=HTML('<br>'),
upgrade_deadline=HTML(formatted_upgrade_deadline)
)
else:
return HTML(full_message).format(
span_close=HTML('</span>'),
expiration_date=HTML(formatted_expiration_date),
strong_open=HTML('<strong>'),
strong_close=HTML('</strong>'),
line_break=HTML('<br>'),
)