本文整理汇总了Python中student.models.CourseEnrollmentAllowed.for_user方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollmentAllowed.for_user方法的具体用法?Python CourseEnrollmentAllowed.for_user怎么用?Python CourseEnrollmentAllowed.for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.CourseEnrollmentAllowed
的用法示例。
在下文中一共展示了CourseEnrollmentAllowed.for_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from student.models import CourseEnrollmentAllowed [as 别名]
# 或者: from student.models.CourseEnrollmentAllowed import for_user [as 别名]
def __init__(self, course_id, email):
# N.B. retired users are not a concern here because they should be
# handled at a higher level (i.e. in enroll_email). Besides, this
# class creates readonly objects.
exists_user = User.objects.filter(email=email).exists()
if exists_user:
user = User.objects.get(email=email)
mode, is_active = CourseEnrollment.enrollment_mode_for_user(user, course_id)
# is_active is `None` if the user is not enrolled in the course
exists_ce = is_active is not None and is_active
full_name = user.profile.name
ceas = CourseEnrollmentAllowed.for_user(user).filter(course_id=course_id).all()
else:
mode = None
exists_ce = False
full_name = None
ceas = CourseEnrollmentAllowed.objects.filter(email=email, course_id=course_id).all()
exists_allowed = ceas.exists()
state_auto_enroll = exists_allowed and ceas[0].auto_enroll
self.user = exists_user
self.enrollment = exists_ce
self.allowed = exists_allowed
self.auto_enroll = bool(state_auto_enroll)
self.full_name = full_name
self.mode = mode