本文整理汇总了Python中student.models.CourseEnrollment.enroll_by_email方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollment.enroll_by_email方法的具体用法?Python CourseEnrollment.enroll_by_email怎么用?Python CourseEnrollment.enroll_by_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.CourseEnrollment
的用法示例。
在下文中一共展示了CourseEnrollment.enroll_by_email方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enrollment_by_email
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enroll_by_email [as 别名]
def test_enrollment_by_email(self):
user = User.objects.create(username="jack", email="[email protected]")
course_id = SlashSeparatedCourseKey("edX", "Test101", "2013")
CourseEnrollment.enroll_by_email("[email protected]", course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
self.assert_enrollment_event_was_emitted(user, course_id)
# This won't throw an exception, even though the user is not found
self.assertIsNone(CourseEnrollment.enroll_by_email("[email protected]", course_id))
self.assert_no_events_were_emitted()
self.assertRaises(
User.DoesNotExist, CourseEnrollment.enroll_by_email, "[email protected]", course_id, ignore_errors=False
)
self.assert_no_events_were_emitted()
# Now unenroll them by email
CourseEnrollment.unenroll_by_email("[email protected]", course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assert_unenrollment_event_was_emitted(user, course_id)
# Harmless second unenroll
CourseEnrollment.unenroll_by_email("[email protected]", course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assert_no_events_were_emitted()
# Unenroll on non-existent user shouldn't throw an error
CourseEnrollment.unenroll_by_email("[email protected]", course_id)
self.assert_no_events_were_emitted()
示例2: cm_enroll_user
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enroll_by_email [as 别名]
def cm_enroll_user(request):
response_format = request.REQUEST.get('format','html')
if response_format == 'json' or 'application/json' in request.META.get('HTTP/ACCEPT', 'application/json'):
if request.method == 'POST':
if validate_token(request.body, request) is False:
return HttpResponse('Unauthorized', status=401)
if 'email' not in request.json or 'course_id' not in request.json:
return HttpResponse(content=json.dumps({'errors':'Missing params'}), \
content_type = 'application/json', status=400)
try:
log.info("Enrolling user: " + request.json.get('email') + " course: " + request.json.get('course_id'))
CourseEnrollment.enroll_by_email(request.json.get('email'), \
get_key_from_course_id(request.json.get('course_id')), ignore_errors=False)
# See if enrolling with staff credentials
if request.json.get('role') == 'staff':
global_admin = AdminFactory()
course = get_key_from_course_id(request.json.get('course_id'))
auth.add_users(global_admin, CourseInstructorRole(course), User.objects.get(email=request.json.get('email')))
content = {'success':'ok'}
status_code = 200
except User.DoesNotExist:
content = {'errors':'User does not exist'}
status_code = 422
return HttpResponse(content=json.dumps(content), status=status_code, \
content_type = 'application/json')
else:
return HttpResponse(content=json.dumps({}), status=404, content_type = 'application/json')
else:
return HttpResponse(content=json.dumps({}), status=404, content_type = 'application/json')
示例3: enroll_email
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enroll_by_email [as 别名]
def enroll_email(course_id, student_email, auto_enroll=False, email_students=False, email_params=None):
"""
Enroll a student by email.
`student_email` is student's emails e.g. "[email protected]"
`auto_enroll` determines what is put in CourseEnrollmentAllowed.auto_enroll
if auto_enroll is set, then when the email registers, they will be
enrolled in the course automatically.
`email_students` determines if student should be notified of action by email.
`email_params` parameters used while parsing email templates (a `dict`).
returns two EmailEnrollmentState's
representing state before and after the action.
"""
previous_state = EmailEnrollmentState(course_id, student_email)
if previous_state.user:
CourseEnrollment.enroll_by_email(student_email, course_id)
if email_students:
email_params['message'] = 'enrolled_enroll'
email_params['email_address'] = student_email
email_params['full_name'] = previous_state.full_name
send_mail_to_student(student_email, email_params)
else:
cea, _ = CourseEnrollmentAllowed.objects.get_or_create(course_id=course_id, email=student_email)
cea.auto_enroll = auto_enroll
cea.save()
if email_students:
email_params['message'] = 'allowed_enroll'
email_params['email_address'] = student_email
send_mail_to_student(student_email, email_params)
after_state = EmailEnrollmentState(course_id, student_email)
return previous_state, after_state
示例4: enroll_email
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enroll_by_email [as 别名]
def enroll_email(course_id, student_email, auto_enroll=False):
"""
Enroll a student by email.
`student_email` is student's emails e.g. "[email protected]"
`auto_enroll` determines what is put in CourseEnrollmentAllowed.auto_enroll
if auto_enroll is set, then when the email registers, they will be
enrolled in the course automatically.
returns two EmailEnrollmentState's
representing state before and after the action.
"""
previous_state = EmailEnrollmentState(course_id, student_email)
if previous_state.user:
CourseEnrollment.enroll_by_email(student_email, course_id)
else:
cea, _ = CourseEnrollmentAllowed.objects.get_or_create(course_id=course_id, email=student_email)
cea.auto_enroll = auto_enroll
cea.save()
after_state = EmailEnrollmentState(course_id, student_email)
return previous_state, after_state
示例5: enroll_email
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enroll_by_email [as 别名]
def enroll_email(course_id, student_email, auto_enroll=False, email_students=False, email_params=None, language=None):
"""
Enroll a student by email.
`student_email` is student's emails e.g. "[email protected]"
`auto_enroll` determines what is put in CourseEnrollmentAllowed.auto_enroll
if auto_enroll is set, then when the email registers, they will be
enrolled in the course automatically.
`email_students` determines if student should be notified of action by email.
`email_params` parameters used while parsing email templates (a `dict`).
`language` is the language used to render the email.
returns two EmailEnrollmentState's
representing state before and after the action.
"""
previous_state = EmailEnrollmentState(course_id, student_email)
if previous_state.user:
# if the student is currently unenrolled, don't enroll them in their
# previous mode
course_mode = u"honor"
if previous_state.enrollment:
course_mode = previous_state.mode
CourseEnrollment.enroll_by_email(student_email, course_id, course_mode)
if email_students:
email_params["message"] = "enrolled_enroll"
email_params["email_address"] = student_email
email_params["full_name"] = previous_state.full_name
send_mail_to_student(student_email, email_params, language=language)
else:
cea, _ = CourseEnrollmentAllowed.objects.get_or_create(course_id=course_id, email=student_email)
cea.auto_enroll = auto_enroll
cea.save()
if email_students:
email_params["message"] = "allowed_enroll"
email_params["email_address"] = student_email
send_mail_to_student(student_email, email_params, language=language)
after_state = EmailEnrollmentState(course_id, student_email)
return previous_state, after_state
示例6: enroll_email
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import enroll_by_email [as 别名]
def enroll_email(course_id, student_email, auto_enroll=False, email_students=False, email_params=None, language=None):
"""
Enroll a student by email.
`student_email` is student's emails e.g. "[email protected]"
`auto_enroll` determines what is put in CourseEnrollmentAllowed.auto_enroll
if auto_enroll is set, then when the email registers, they will be
enrolled in the course automatically.
`email_students` determines if student should be notified of action by email.
`email_params` parameters used while parsing email templates (a `dict`).
`language` is the language used to render the email.
returns two EmailEnrollmentState's
representing state before and after the action.
"""
previous_state = EmailEnrollmentState(course_id, student_email)
enrollment_obj = None
if previous_state.user:
# if the student is currently unenrolled, don't enroll them in their
# previous mode
# for now, White Labels use 'shoppingcart' which is based on the
# "honor" course_mode. Given the change to use "audit" as the default
# course_mode in Open edX, we need to be backwards compatible with
# how White Labels approach enrollment modes.
if CourseMode.is_white_label(course_id):
course_mode = CourseMode.DEFAULT_SHOPPINGCART_MODE_SLUG
else:
course_mode = None
if previous_state.enrollment:
course_mode = previous_state.mode
enrollment_obj = CourseEnrollment.enroll_by_email(student_email, course_id, course_mode)
if email_students:
email_params['message_type'] = 'enrolled_enroll'
email_params['email_address'] = student_email
email_params['full_name'] = previous_state.full_name
send_mail_to_student(student_email, email_params, language=language)
elif not is_email_retired(student_email):
cea, _ = CourseEnrollmentAllowed.objects.get_or_create(course_id=course_id, email=student_email)
cea.auto_enroll = auto_enroll
cea.save()
if email_students:
email_params['message_type'] = 'allowed_enroll'
email_params['email_address'] = student_email
send_mail_to_student(student_email, email_params, language=language)
after_state = EmailEnrollmentState(course_id, student_email)
return previous_state, after_state, enrollment_obj