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


Python CourseEnrollment.unenroll_by_email方法代码示例

本文整理汇总了Python中student.models.CourseEnrollment.unenroll_by_email方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollment.unenroll_by_email方法的具体用法?Python CourseEnrollment.unenroll_by_email怎么用?Python CourseEnrollment.unenroll_by_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在student.models.CourseEnrollment的用法示例。


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

示例1: unenroll_email

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import unenroll_by_email [as 别名]
def unenroll_email(course_id, student_email, email_students=False, email_params=None):
    """
    Unenroll a student by email.

    `student_email` is student's emails e.g. "[email protected]"
    `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.enrollment:
        CourseEnrollment.unenroll_by_email(student_email, course_id)
        if email_students:
            email_params['message'] = 'enrolled_unenroll'
            email_params['email_address'] = student_email
            email_params['full_name'] = previous_state.full_name
            send_mail_to_student(student_email, email_params)

    if previous_state.allowed:
        CourseEnrollmentAllowed.objects.get(course_id=course_id, email=student_email).delete()
        if email_students:
            email_params['message'] = 'allowed_unenroll'
            email_params['email_address'] = student_email
            # Since no User object exists for this student there is no "full_name" available.
            send_mail_to_student(student_email, email_params)

    after_state = EmailEnrollmentState(course_id, student_email)

    return previous_state, after_state
开发者ID:CEIT-UQ,项目名称:edx-platform,代码行数:35,代码来源:enrollment.py

示例2: unenroll_email

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import unenroll_by_email [as 别名]
def unenroll_email(course_id, student_email):
    """
    Unenroll a student by email.

    `student_email` is student's emails e.g. "[email protected]"

    returns two EmailEnrollmentState's
        representing state before and after the action.
    """

    previous_state = EmailEnrollmentState(course_id, student_email)

    if previous_state.enrollment:
        CourseEnrollment.unenroll_by_email(student_email, course_id)

    if previous_state.allowed:
        CourseEnrollmentAllowed.objects.get(course_id=course_id, email=student_email).delete()

    after_state = EmailEnrollmentState(course_id, student_email)

    return previous_state, after_state
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:23,代码来源:enrollment.py

示例3: test_enrollment_by_email

# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import unenroll_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()
开发者ID:Geekathon,项目名称:edx-platform,代码行数:32,代码来源:tests.py


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