Commit a7b1f79d by Peter Fogg

Better error logging for full courses during enrollment.

ECOM-3685
parent 90e1b626
......@@ -984,7 +984,7 @@ class CourseEnrollment(models.Model):
if user.id is None:
user.save()
enrollment, created = CourseEnrollment.objects.get_or_create(
enrollment, created = cls.objects.get_or_create(
user=user,
course_id=course_key,
)
......@@ -1009,7 +1009,7 @@ class CourseEnrollment(models.Model):
Course enrollment object or None
"""
try:
return CourseEnrollment.objects.get(
return cls.objects.get(
user=user,
course_id=course_key
)
......@@ -1171,7 +1171,7 @@ class CourseEnrollment(models.Model):
raise NonExistentCourseError
if check_access:
if CourseEnrollment.is_enrollment_closed(user, course):
if cls.is_enrollment_closed(user, course):
log.warning(
u"User %s failed to enroll in course %s because enrollment is closed",
user.username,
......@@ -1179,14 +1179,15 @@ class CourseEnrollment(models.Model):
)
raise EnrollmentClosedError
if CourseEnrollment.objects.is_course_full(course):
if cls.objects.is_course_full(course):
log.warning(
u"User %s failed to enroll in full course %s",
user.username,
u"Course %s has reached its maximum enrollment of %d learners. User %s failed to enroll.",
course_key.to_deprecated_string(),
course.max_student_enrollments_allowed,
user.username,
)
raise CourseFullError
if CourseEnrollment.is_enrolled(user, course_key):
if cls.is_enrolled(user, course_key):
log.warning(
u"User %s attempted to enroll in %s, but they were already enrolled",
user.username,
......@@ -1254,7 +1255,7 @@ class CourseEnrollment(models.Model):
`skip_refund` can be set to True to avoid the refund process.
"""
try:
record = CourseEnrollment.objects.get(user=user, course_id=course_id)
record = cls.objects.get(user=user, course_id=course_id)
record.update_enrollment(is_active=False, skip_refund=skip_refund)
except cls.DoesNotExist:
......@@ -1300,7 +1301,7 @@ class CourseEnrollment(models.Model):
return False
try:
record = CourseEnrollment.objects.get(user=user, course_id=course_key)
record = cls.objects.get(user=user, course_id=course_key)
return record.is_active
except cls.DoesNotExist:
return False
......@@ -1325,7 +1326,7 @@ class CourseEnrollment(models.Model):
course_key = SlashSeparatedCourseKey(course_id_partial.org, course_id_partial.course, '')
querystring = unicode(course_key.to_deprecated_string())
try:
return CourseEnrollment.objects.filter(
return cls.objects.filter(
user=user,
course_id__startswith=querystring,
is_active=1
......@@ -1346,14 +1347,14 @@ class CourseEnrollment(models.Model):
Returns (None, None) if the courseenrollment record does not exist.
"""
try:
record = CourseEnrollment.objects.get(user=user, course_id=course_id)
record = cls.objects.get(user=user, course_id=course_id)
return (record.mode, record.is_active)
except cls.DoesNotExist:
return (None, None)
@classmethod
def enrollments_for_user(cls, user):
return CourseEnrollment.objects.filter(user=user, is_active=1)
return cls.objects.filter(user=user, is_active=1)
def is_paid_course(self):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment