From 451fed0a600b51bfc8c20f952027aec6392403dd Mon Sep 17 00:00:00 2001 From: Samuel Walladge Date: Tue, 30 Jul 2019 14:40:19 +0930 Subject: [PATCH 1/2] Allows unicode usernames to be used in CCX enrollments and reports. Previously, unicode would result in a UnicodeEncodeError as a result of the format string being str instead of unicode. Additionally, the log calls would crash with a traceback (while not affecting the program flow). (cherry picked from commit 54f9434d468be65bd925628a8812bf33349582ca) --- lms/djangoapps/ccx/tests/test_views.py | 2 +- lms/djangoapps/ccx/utils.py | 10 +++++----- lms/djangoapps/ccx/views.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index 6f3f0c29c05f..b7412ff05560 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -86,7 +86,7 @@ def setup_students_and_grades(context): context.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=context.course.id) - context.student2 = student2 = UserFactory.create() + context.student2 = student2 = UserFactory.create(username=u'u\u0131\u028c\u0279\u0250\u026f') CourseEnrollmentFactory.create(user=student2, course_id=context.course.id) # create grades for self.student as if they'd submitted the ccx diff --git a/lms/djangoapps/ccx/utils.py b/lms/djangoapps/ccx/utils.py index 1ce2daf8a2f4..c301fca6651c 100644 --- a/lms/djangoapps/ccx/utils.py +++ b/lms/djangoapps/ccx/utils.py @@ -236,14 +236,14 @@ def ccx_students_enrolling_center(action, identifiers, email_students, course_ke if student: must_enroll = student in staff or student in admins or student == coach except CCXUserValidationException as exp: - log.info("%s", exp) - errors.append("{0}".format(exp)) + log.info(u"%s", exp) + errors.append(u"{0}".format(exp)) continue if CourseEnrollment.objects.is_course_full(ccx_course_overview) and not must_enroll: error = _('The course is full: the limit is {max_student_enrollments_allowed}').format( max_student_enrollments_allowed=ccx_course_overview.max_student_enrollments_allowed) - log.info("%s", error) + log.info(u"%s", error) errors.append(error) break enroll_email(course_key, email, auto_enroll=True, email_students=email_students, email_params=email_params) @@ -252,8 +252,8 @@ def ccx_students_enrolling_center(action, identifiers, email_students, course_ke try: email, __ = get_valid_student_with_email(identifier) except CCXUserValidationException as exp: - log.info("%s", exp) - errors.append("{0}".format(exp)) + log.info(u"%s", exp) + errors.append(u"{0}".format(exp)) continue unenroll_email(course_key, email, email_students=email_students, email_params=email_params) return errors diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index 556c363ece2d..944c5cdf9c87 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -561,7 +561,8 @@ def ccx_grades_csv(request, course, ccx=None): } row_percents = [percents.get(label, 0.0) for label in header] - rows.append([student.id, student.email, student.username, + rows.append([student.id, student.email.encode('utf-8'), + student.username.encode('utf-8'), course_grade.percent] + row_percents) buf = StringIO() From d2fa0701f11e6e4ded2770e2f6ae22f413b901fa Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Wed, 7 Aug 2019 13:02:41 +0930 Subject: [PATCH 2/2] Fixes another unicode error (already fixed upstream) --- lms/djangoapps/ccx/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/ccx/utils.py b/lms/djangoapps/ccx/utils.py index c301fca6651c..a0ee35e95de2 100644 --- a/lms/djangoapps/ccx/utils.py +++ b/lms/djangoapps/ccx/utils.py @@ -202,7 +202,7 @@ def get_valid_student_with_email(identifier): try: validate_email(email) except ValidationError: - raise CCXUserValidationException('Could not find a user with name or email "{0}" '.format(identifier)) + raise CCXUserValidationException(u'Could not find a user with name or email "{0}" '.format(identifier)) return email, user