diff --git a/common/djangoapps/student/management/commands/assigngroups.py b/common/djangoapps/student/management/commands/assigngroups.py index 3c6df5b3ba..166e5cab16 100644 --- a/common/djangoapps/student/management/commands/assigngroups.py +++ b/common/djangoapps/student/management/commands/assigngroups.py @@ -82,9 +82,11 @@ class Command(BaseCommand): v = random.uniform(0, 1) group = group_from_value(groups, v) group_objects[group].users.add(user) - f.write("Assigned user {name} ({id}) to {group}\n".format(name=user.username, - id=user.id, - group=group)) + f.write(u"Assigned user {name} ({id}) to {group}\n".format( + name=user.username, + id=user.id, + group=group + ).encode('utf-8')) ## Save groups for group in group_objects: diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 0159587a24..fc036399a9 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -889,7 +889,12 @@ class CourseEnrollment(models.Model): except: # pylint: disable=bare-except if event_name and self.course_id: - log.exception('Unable to emit event %s for user %s and course %s', event_name, self.user.username, self.course_id) + log.exception( + u'Unable to emit event %s for user %s and course %s', + event_name, + self.user.username, # pylint: disable=no-member + self.course_id, + ) @classmethod def enroll(cls, user, course_key, mode="honor", check_access=False): @@ -930,10 +935,9 @@ class CourseEnrollment(models.Model): course = modulestore().get_course(course_key) except ItemNotFoundError: log.warning( - "User {0} failed to enroll in non-existent course {1}".format( - user.username, - course_key.to_deprecated_string() - ) + u"User %s failed to enroll in non-existent course %s", + user.username, + course_key.to_deprecated_string(), ) raise NonExistentCourseError @@ -942,27 +946,24 @@ class CourseEnrollment(models.Model): raise NonExistentCourseError if CourseEnrollment.is_enrollment_closed(user, course): log.warning( - "User {0} failed to enroll in course {1} because enrollment is closed".format( - user.username, - course_key.to_deprecated_string() - ) + u"User %s failed to enroll in course %s because enrollment is closed", + user.username, + course_key.to_deprecated_string() ) raise EnrollmentClosedError if CourseEnrollment.is_course_full(course): log.warning( - "User {0} failed to enroll in full course {1}".format( - user.username, - course_key.to_deprecated_string() - ) + u"User %s failed to enroll in full course %s", + user.username, + course_key.to_deprecated_string(), ) raise CourseFullError if CourseEnrollment.is_enrolled(user, course_key): log.warning( - "User {0} attempted to enroll in {1}, but they were already enrolled".format( - user.username, - course_key.to_deprecated_string() - ) + u"User %s attempted to enroll in %s, but they were already enrolled", + user.username, + course_key.to_deprecated_string() ) if check_access: raise AlreadyEnrolledError @@ -1029,8 +1030,8 @@ class CourseEnrollment(models.Model): record.update_enrollment(is_active=False, skip_refund=skip_refund) except cls.DoesNotExist: - err_msg = u"Tried to unenroll student {} from {} but they were not enrolled" - log.error(err_msg.format(user, course_id)) + err_msg = u"Tried to unenroll student %s from %s but they were not enrolled" + log.error(err_msg, user, course_id) @classmethod def unenroll_by_email(cls, email, course_id): @@ -1046,8 +1047,8 @@ class CourseEnrollment(models.Model): user = User.objects.get(email=email) return cls.unenroll(user, course_id) except User.DoesNotExist: - err_msg = u"Tried to unenroll email {} from course {}, but user not found" - log.error(err_msg.format(email, course_id)) + err_msg = u"Tried to unenroll email %s from course %s, but user not found" + log.error(err_msg, user, course_id) @classmethod def is_enrolled(cls, user, course_key): diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 774cf23168..792dd3c454 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -338,7 +338,7 @@ def _cert_info(user, course, cert_status): if status == 'ready': if 'download_url' not in cert_status: - log.warning("User %s has a downloadable cert for %s, but no download url", + log.warning(u"User %s has a downloadable cert for %s, but no download url", user.username, course.id) return default_info else: @@ -841,13 +841,11 @@ def change_enrollment(request, check_access=True): try: course_id = SlashSeparatedCourseKey.from_deprecated_string(request.POST.get("course_id")) except InvalidKeyError: - log.warning( - "User {username} tried to {action} with invalid course id: {course_id}".format( - username=user.username, - action=action, - course_id=request.POST.get("course_id") - ) - ) + log.warning(u"User %(username)s tried to %(action)s with invalid course id: %(course_id)s", { + "username": user.username, + "action": action, + "course_id": request.POST.get("course_id"), + }) return HttpResponseBadRequest(_("Invalid course id")) if action == "enroll": @@ -1248,11 +1246,11 @@ def disable_account_ajax(request): if account_action == 'disable': user_account.account_status = UserStanding.ACCOUNT_DISABLED context['message'] = _("Successfully disabled {}'s account").format(username) - log.info("{} disabled {}'s account".format(request.user, username)) + log.info(u"%s disabled %s's account", request.user, username) elif account_action == 'reenable': user_account.account_status = UserStanding.ACCOUNT_ENABLED context['message'] = _("Successfully reenabled {}'s account").format(username) - log.info("{} reenabled {}'s account".format(request.user, username)) + log.info(u"%s reenabled %s's account", request.user, username) else: context['message'] = _("Unexpected account status") return JsonResponse(context, status=400) diff --git a/lms/djangoapps/certificates/views.py b/lms/djangoapps/certificates/views.py index e2d5f49f5f..13d341dc1a 100644 --- a/lms/djangoapps/certificates/views.py +++ b/lms/djangoapps/certificates/views.py @@ -36,7 +36,8 @@ def request_certificate(request): status = certificate_status_for_student(student, course_key)['status'] if status in [CertificateStatuses.unavailable, CertificateStatuses.notpassing, CertificateStatuses.error]: - logger.info('Grading and certification requested for user {} in course {} via /request_certificate call'.format(username, course_key)) + log_msg = u'Grading and certification requested for user %s in course %s via /request_certificate call' + logger.info(log_msg, username, course_key) status = xqci.add_cert(student, course_key, course=course) return HttpResponse(json.dumps({'add_status': status}), mimetype='application/json') return HttpResponse(json.dumps({'add_status': 'ERRORANONYMOUSUSER'}), mimetype='application/json') diff --git a/lms/djangoapps/courseware/grades.py b/lms/djangoapps/courseware/grades.py index bd8cb577f2..3db3cb8f35 100644 --- a/lms/djangoapps/courseware/grades.py +++ b/lms/djangoapps/courseware/grades.py @@ -89,8 +89,9 @@ def answer_distributions(course_key): raw_answers = state_dict.get("student_answers", {}) except ValueError: log.error( - "Answer Distribution: Could not parse module state for " + - "StudentModule id={}, course={}".format(module.id, course_key) + u"Answer Distribution: Could not parse module state for StudentModule id=%s, course=%s", + module.id, + course_key, ) continue diff --git a/lms/djangoapps/courseware/management/commands/regrade_partial.py b/lms/djangoapps/courseware/management/commands/regrade_partial.py index c24f84ddfc..1cbcd52b87 100644 --- a/lms/djangoapps/courseware/management/commands/regrade_partial.py +++ b/lms/djangoapps/courseware/management/commands/regrade_partial.py @@ -52,9 +52,13 @@ class Command(BaseCommand): module_state = module.state if module_state is None: # not likely, since we filter on it. But in general... - LOG.info("No state found for {type} module {id} for student {student} in course {course_id}" - .format(type=module.module_type, id=module.module_state_key, - student=module.student.username, course_id=module.course_id)) + LOG.info( + u"No state found for %(type)s module %(id)s for student %(student)s in course %(course_id)s", + module.module_type, + module.module_state_key, + module.student.username, + module.course_id, + ) return state_dict = json.loads(module_state) @@ -66,15 +70,31 @@ class Command(BaseCommand): if (not student_answers) or len(student_answers) == 0: # we should not have a grade here: if module.grade != 0: - LOG.error("No answer found but grade {grade} exists for {type} module {id} for student {student} " - "in course {course_id}".format(grade=module.grade, - type=module.module_type, id=module.module_state_key, - student=module.student.username, course_id=module.course_id)) + log_msg = ( + u"No answer found but grade %(grade)s exists for %(type)s module %(id)s for student %(student)s " + + u"in course %(course_id)s" + ) + + LOG.error(log_msg, { + "grade": module.grade, + "type": module.module_type, + "id": module.module_state_key, + "student": module.student.username, + "course_id": module.course_id, + }) else: - LOG.debug("No answer and no grade found for {type} module {id} for student {student} " - "in course {course_id}".format(grade=module.grade, - type=module.module_type, id=module.module_state_key, - student=module.student.username, course_id=module.course_id)) + log_msg = ( + u"No answer and no grade found for %(type)s module %(id)s for student %(student)s " + + u"in course %(course_id)s" + ) + + LOG.debug(log_msg, { + "grade": module.grade, + "type": module.module_type, + "id": module.module_state_key, + "student": module.student.username, + "course_id": module.course_id, + }) return # load into a CorrectMap, as done in LoncapaProblem.__init__(): @@ -90,24 +110,48 @@ class Command(BaseCommand): if module.grade == correct: # nothing to change - LOG.debug("Grade matches for {type} module {id} for student {student} in course {course_id}" - .format(type=module.module_type, id=module.module_state_key, - student=module.student.username, course_id=module.course_id)) + log_msg = u"Grade matches for %(type)s module %(id)s for student %(student)s in course %(course_id)s" + LOG.debug(log_msg, { + "type": module.module_type, + "id": module.module_state_key, + "student": module.student.username, + "course_id": module.course_id, + }) elif save_changes: # make the change - LOG.info("Grade changing from {0} to {1} for {type} module {id} for student {student} " - "in course {course_id}".format(module.grade, correct, - type=module.module_type, id=module.module_state_key, - student=module.student.username, course_id=module.course_id)) + log_msg = ( + u"Grade changing from %(grade)s to %(correct)s for %(type)s module " + + u"%(id)s for student %(student)s in course %(course_id)s" + ) + + LOG.debug(log_msg, { + "grade": module.grade, + "correct": correct, + "type": module.module_type, + "id": module.module_state_key, + "student": module.student.username, + "course_id": module.course_id, + }) + module.grade = correct module.save() self.num_changed += 1 else: # don't make the change, but log that the change would be made - LOG.info("Grade would change from {0} to {1} for {type} module {id} for student {student} " - "in course {course_id}".format(module.grade, correct, - type=module.module_type, id=module.module_state_key, - student=module.student.username, course_id=module.course_id)) + log_msg = ( + u"Grade would change from %(grade)s to %(correct)s for %(type)s module %(id)s for student " + + u"%(student)s in course %(course_id)s" + ) + + LOG.debug(log_msg, { + "grade": module.grade, + "correct": correct, + "type": module.module_type, + "id": module.module_state_key, + "student": module.student.username, + "course_id": module.course_id, + }) + self.num_changed += 1 def handle(self, **options): diff --git a/lms/djangoapps/courseware/management/commands/remove_input_state.py b/lms/djangoapps/courseware/management/commands/remove_input_state.py index e45d08e351..3e86d213a9 100644 --- a/lms/djangoapps/courseware/management/commands/remove_input_state.py +++ b/lms/djangoapps/courseware/management/commands/remove_input_state.py @@ -68,7 +68,7 @@ class Command(BaseCommand): try: module = StudentModule.objects.get(id=student_module_id) except StudentModule.DoesNotExist: - LOG.error("Unable to find student module with id = {0}: skipping... ".format(student_module_id)) + LOG.error(u"Unable to find student module with id = %s: skipping... ", student_module_id) continue self.remove_studentmodule_input_state(module, save_changes) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 8c97f1e899..73d544030e 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -353,12 +353,20 @@ def register_and_enroll_students(request, course_id): # pylint: disable=too-man 'username': username, 'email': email, 'response': warning_message}) log.warning('email {email} already exist'.format(email=email)) else: - log.info("user already exists with username '{username}' and email '{email}'".format(email=email, username=username)) + log.info( + u"user already exists with username '%s' and email '%s'", + email=email, + username=username, + ) # make sure user is enrolled in course if not CourseEnrollment.is_enrolled(user, course_id): CourseEnrollment.enroll(user, course_id) - log.info('user {username} enrolled in the course {course}'.format(username=username, course=course.id)) + log.info( + u'user %s enrolled in the course %s', + username=username, + course=course.id, + ) enroll_email(course_id=course_id, student_email=email, auto_enroll=True, email_students=True, email_params=email_params) else: # This email does not yet exist, so we need to create a new account diff --git a/lms/djangoapps/instructor/views/legacy.py b/lms/djangoapps/instructor/views/legacy.py index 4bb65e5849..09ecfe05d3 100644 --- a/lms/djangoapps/instructor/views/legacy.py +++ b/lms/djangoapps/instructor/views/legacy.py @@ -252,9 +252,11 @@ def instructor_dashboard(request, course_id): try: ddata.append([student.email, student.grades[aidx]]) except IndexError: - log.debug('No grade for assignment {idx} ({name}) for student {email}'.format( - idx=aidx, name=aname, email=student.email) - ) + log.debug(u'No grade for assignment %(idx)s (%(name)s) for student %(email)s', { + "idx": aidx, + "name": aname, + "email": student.email, + }) datatable['data'] = ddata datatable['title'] = _('Grades for assignment "{name}"').format(name=aname) @@ -749,7 +751,7 @@ def get_student_grade_summary_data(request, course, get_grades=True, get_raw_sco if get_grades: gradeset = student_grades(student, request, course, keep_raw_scores=get_raw_scores, use_offline=use_offline) - log.debug('student={0}, gradeset={1}'.format(student, gradeset)) + log.debug(u'student=%s, gradeset=%s', student, gradeset) with gtab.add_row(student.id) as add_grade: if get_raw_scores: # TODO (ichuang) encode Score as dict instead of as list, so score[0] -> score['earned'] diff --git a/lms/djangoapps/lms_migration/migrate.py b/lms/djangoapps/lms_migration/migrate.py index ee6f715fb6..eb33a14773 100644 --- a/lms/djangoapps/lms_migration/migrate.py +++ b/lms/djangoapps/lms_migration/migrate.py @@ -69,11 +69,11 @@ def manage_modulestores(request, reload_dir=None, commit_id=None): html += '