本文整理汇总了Python中student.models.CourseEnrollmentAllowed.save方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollmentAllowed.save方法的具体用法?Python CourseEnrollmentAllowed.save怎么用?Python CourseEnrollmentAllowed.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.CourseEnrollmentAllowed
的用法示例。
在下文中一共展示了CourseEnrollmentAllowed.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unenrollment_email_on
# 需要导入模块: from student.models import CourseEnrollmentAllowed [as 别名]
# 或者: from student.models.CourseEnrollmentAllowed import save [as 别名]
def test_unenrollment_email_on(self):
"""
Do email on unenroll test
"""
course = self.course
#Create invited, but not registered, user
cea = CourseEnrollmentAllowed(email='[email protected]', course_id=course.id)
cea.save()
url = reverse('instructor_dashboard', kwargs={'course_id': course.id})
response = self.client.post(url, {'action': 'Unenroll multiple students', 'multiple_students': '[email protected], [email protected], [email protected]', 'email_students': 'on'})
#Check the page output
self.assertContains(response, '<td>[email protected]</td>')
self.assertContains(response, '<td>[email protected]</td>')
self.assertContains(response, '<td>un-enrolled, email sent</td>')
#Check the outbox
self.assertEqual(len(mail.outbox), 3)
self.assertEqual(mail.outbox[0].subject, 'You have been un-enrolled from MITx/999/Robot_Super_Course')
self.assertEqual(mail.outbox[0].body, "Dear Student,\n\nYou have been un-enrolled from course MITx/999/Robot_Super_Course by a member of the course staff. " +
"Please disregard the invitation previously sent.\n\n" +
"----\nThis email was automatically sent from edx.org to [email protected]")
self.assertEqual(mail.outbox[1].subject, 'You have been un-enrolled from MITx/999/Robot_Super_Course')
示例2: test_unenrollment_email_on
# 需要导入模块: from student.models import CourseEnrollmentAllowed [as 别名]
# 或者: from student.models.CourseEnrollmentAllowed import save [as 别名]
def test_unenrollment_email_on(self):
"""
Do email on unenroll test
"""
course = self.course
# Create invited, but not registered, user
cea = CourseEnrollmentAllowed(email="[email protected]", course_id=course.id)
cea.save()
url = reverse("instructor_dashboard_legacy", kwargs={"course_id": course.id.to_deprecated_string()})
response = self.client.post(
url,
{
"action": "Unenroll multiple students",
"multiple_students": "[email protected], [email protected], [email protected]",
"email_students": "on",
},
)
# Check the page output
self.assertContains(response, "<td>[email protected]</td>")
self.assertContains(response, "<td>[email protected]</td>")
self.assertContains(response, "<td>un-enrolled, email sent</td>")
# Check the outbox
self.assertEqual(len(mail.outbox), 3)
self.assertEqual(mail.outbox[0].subject, "You have been un-enrolled from {}".format(course.display_name))
self.assertEqual(
mail.outbox[0].body,
"Dear Student,\n\nYou have been un-enrolled from course "
"{} by a member of the course staff. "
"Please disregard the invitation previously sent.\n\n"
"----\nThis email was automatically sent from edx.org "
"to [email protected]".format(course.display_name),
)
self.assertEqual(mail.outbox[1].subject, "You have been un-enrolled from {}".format(course.display_name))
示例3: _do_enroll_students
# 需要导入模块: from student.models import CourseEnrollmentAllowed [as 别名]
# 或者: from student.models.CourseEnrollmentAllowed import save [as 别名]
def _do_enroll_students(course, course_key, students, secure=False, overload=False, auto_enroll=False, email_students=False, is_shib_course=False):
"""
Do the actual work of enrolling multiple students, presented as a string
of emails separated by commas or returns
`course` is course object
`course_key` id of course (a CourseKey)
`students` string of student emails separated by commas or returns (a `str`)
`overload` un-enrolls all existing students (a `boolean`)
`auto_enroll` is user input preference (a `boolean`)
`email_students` is user input preference (a `boolean`)
"""
new_students, new_students_lc = get_and_clean_student_list(students)
status = dict([x, 'unprocessed'] for x in new_students)
if overload: # delete all but staff
todelete = CourseEnrollment.objects.filter(course_id=course_key)
for enrollee in todelete:
if not has_access(enrollee.user, 'staff', course) and enrollee.user.email.lower() not in new_students_lc:
status[enrollee.user.email] = 'deleted'
enrollee.deactivate()
else:
status[enrollee.user.email] = 'is staff'
ceaset = CourseEnrollmentAllowed.objects.filter(course_id=course_key)
for cea in ceaset:
status[cea.email] = 'removed from pending enrollment list'
ceaset.delete()
if email_students:
protocol = 'https' if secure else 'http'
stripped_site_name = microsite.get_value(
'SITE_NAME',
settings.SITE_NAME
)
# TODO: Use request.build_absolute_uri rather than '{proto}://{site}{path}'.format
# and check with the Services team that this works well with microsites
registration_url = '{proto}://{site}{path}'.format(
proto=protocol,
site=stripped_site_name,
path=reverse('student.views.register_user')
)
course_url = '{proto}://{site}{path}'.format(
proto=protocol,
site=stripped_site_name,
path=reverse('course_root', kwargs={'course_id': course_key.to_deprecated_string()})
)
# We can't get the url to the course's About page if the marketing site is enabled.
course_about_url = None
if not settings.FEATURES.get('ENABLE_MKTG_SITE', False):
course_about_url = u'{proto}://{site}{path}'.format(
proto=protocol,
site=stripped_site_name,
path=reverse('about_course', kwargs={'course_id': course_key.to_deprecated_string()})
)
# Composition of email
email_data = {
'site_name': stripped_site_name,
'registration_url': registration_url,
'course': course,
'auto_enroll': auto_enroll,
'course_url': course_url,
'course_about_url': course_about_url,
'is_shib_course': is_shib_course
}
for student in new_students:
try:
user = User.objects.get(email=student)
except User.DoesNotExist:
# Student not signed up yet, put in pending enrollment allowed table
cea = CourseEnrollmentAllowed.objects.filter(email=student, course_id=course_key)
# If enrollmentallowed already exists, update auto_enroll flag to however it was set in UI
# Will be 0 or 1 records as there is a unique key on email + course_id
if cea:
cea[0].auto_enroll = auto_enroll
cea[0].save()
status[student] = 'user does not exist, enrollment already allowed, pending with auto enrollment ' \
+ ('on' if auto_enroll else 'off')
continue
# EnrollmentAllowed doesn't exist so create it
cea = CourseEnrollmentAllowed(email=student, course_id=course_key, auto_enroll=auto_enroll)
cea.save()
status[student] = 'user does not exist, enrollment allowed, pending with auto enrollment ' \
+ ('on' if auto_enroll else 'off')
if email_students:
# User is allowed to enroll but has not signed up yet
email_data['email_address'] = student
email_data['message'] = 'allowed_enroll'
send_mail_ret = send_mail_to_student(student, email_data)
status[student] += (', email sent' if send_mail_ret else '')
continue
# Student has already registered
if CourseEnrollment.is_enrolled(user, course_key):
#.........这里部分代码省略.........
示例4: _do_enroll_students
# 需要导入模块: from student.models import CourseEnrollmentAllowed [as 别名]
# 或者: from student.models.CourseEnrollmentAllowed import save [as 别名]
def _do_enroll_students(
course,
course_key,
students,
secure=False,
overload=False,
auto_enroll=False,
email_students=False,
is_shib_course=False,
):
"""
Do the actual work of enrolling multiple students, presented as a string
of emails separated by commas or returns
`course` is course object
`course_key` id of course (a CourseKey)
`students` string of student emails separated by commas or returns (a `str`)
`overload` un-enrolls all existing students (a `boolean`)
`auto_enroll` is user input preference (a `boolean`)
`email_students` is user input preference (a `boolean`)
"""
new_students, new_students_lc = get_and_clean_student_list(students)
status = dict([x, "unprocessed"] for x in new_students)
if overload: # delete all but staff
todelete = CourseEnrollment.objects.filter(course_id=course_key)
for enrollee in todelete:
if not has_access(enrollee.user, "staff", course) and enrollee.user.email.lower() not in new_students_lc:
status[enrollee.user.email] = "deleted"
enrollee.deactivate()
else:
status[enrollee.user.email] = "is staff"
ceaset = CourseEnrollmentAllowed.objects.filter(course_id=course_key)
for cea in ceaset:
status[cea.email] = "removed from pending enrollment list"
ceaset.delete()
if email_students:
protocol = "https" if secure else "http"
stripped_site_name = microsite.get_value("SITE_NAME", settings.SITE_NAME)
# TODO: Use request.build_absolute_uri rather than '{proto}://{site}{path}'.format
# and check with the Services team that this works well with microsites
registration_url = "{proto}://{site}{path}".format(
proto=protocol, site=stripped_site_name, path=reverse("register_user")
)
course_url = "{proto}://{site}{path}".format(
proto=protocol,
site=stripped_site_name,
path=reverse("course_root", kwargs={"course_id": course_key.to_deprecated_string()}),
)
# We can't get the url to the course's About page if the marketing site is enabled.
course_about_url = None
if not settings.FEATURES.get("ENABLE_MKTG_SITE", False):
course_about_url = u"{proto}://{site}{path}".format(
proto=protocol,
site=stripped_site_name,
path=reverse("about_course", kwargs={"course_id": course_key.to_deprecated_string()}),
)
# Composition of email
email_data = {
"site_name": stripped_site_name,
"registration_url": registration_url,
"course": course,
"auto_enroll": auto_enroll,
"course_url": course_url,
"course_about_url": course_about_url,
"is_shib_course": is_shib_course,
}
for student in new_students:
try:
user = User.objects.get(email=student)
except User.DoesNotExist:
# Student not signed up yet, put in pending enrollment allowed table
cea = CourseEnrollmentAllowed.objects.filter(email=student, course_id=course_key)
# If enrollmentallowed already exists, update auto_enroll flag to however it was set in UI
# Will be 0 or 1 records as there is a unique key on email + course_id
if cea:
cea[0].auto_enroll = auto_enroll
cea[0].save()
status[student] = "user does not exist, enrollment already allowed, pending with auto enrollment " + (
"on" if auto_enroll else "off"
)
continue
# EnrollmentAllowed doesn't exist so create it
cea = CourseEnrollmentAllowed(email=student, course_id=course_key, auto_enroll=auto_enroll)
cea.save()
status[student] = "user does not exist, enrollment allowed, pending with auto enrollment " + (
"on" if auto_enroll else "off"
)
if email_students:
# User is allowed to enroll but has not signed up yet
email_data["email_address"] = student
email_data["message"] = "allowed_enroll"
#.........这里部分代码省略.........