Commit e1afbe50 by Usman Khalid

Merge pull request #3058 from edx/usman/lms2429-unicode-error-fixes

Unicode support fixes
parents 3e9d1b39 76e59263
...@@ -131,7 +131,7 @@ DATADOG_FEEDBACK_METRIC = "lms_feedback_submissions" ...@@ -131,7 +131,7 @@ DATADOG_FEEDBACK_METRIC = "lms_feedback_submissions"
def _record_feedback_in_datadog(tags): def _record_feedback_in_datadog(tags):
datadog_tags = ["{k}:{v}".format(k=k, v=v) for k, v in tags.items()] datadog_tags = [u"{k}:{v}".format(k=k, v=v) for k, v in tags.items()]
dog_stats_api.increment(DATADOG_FEEDBACK_METRIC, tags=datadog_tags) dog_stats_api.increment(DATADOG_FEEDBACK_METRIC, tags=datadog_tags)
......
...@@ -52,9 +52,9 @@ def get_course(course_id, depth=0): ...@@ -52,9 +52,9 @@ def get_course(course_id, depth=0):
course_loc = CourseDescriptor.id_to_location(course_id) course_loc = CourseDescriptor.id_to_location(course_id)
return modulestore().get_instance(course_id, course_loc, depth=depth) return modulestore().get_instance(course_id, course_loc, depth=depth)
except (KeyError, ItemNotFoundError): except (KeyError, ItemNotFoundError):
raise ValueError("Course not found: {}".format(course_id)) raise ValueError(u"Course not found: {0}".format(course_id))
except InvalidLocationError: except InvalidLocationError:
raise ValueError("Invalid location: {}".format(course_id)) raise ValueError(u"Invalid location: {0}".format(course_id))
def get_course_by_id(course_id, depth=0): def get_course_by_id(course_id, depth=0):
...@@ -127,7 +127,7 @@ def find_file(filesystem, dirs, filename): ...@@ -127,7 +127,7 @@ def find_file(filesystem, dirs, filename):
filepath = path(directory) / filename filepath = path(directory) / filename
if filesystem.exists(filepath): if filesystem.exists(filepath):
return filepath return filepath
raise ResourceNotFoundError("Could not find {0}".format(filename)) raise ResourceNotFoundError(u"Could not find {0}".format(filename))
def get_course_about_section(course, section_key): def get_course_about_section(course, section_key):
...@@ -191,15 +191,16 @@ def get_course_about_section(course, section_key): ...@@ -191,15 +191,16 @@ def get_course_about_section(course, section_key):
html = about_module.render('student_view').content html = about_module.render('student_view').content
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
html = render_to_string('courseware/error-message.html', None) html = render_to_string('courseware/error-message.html', None)
log.exception("Error rendering course={course}, section_key={section_key}".format( log.exception(
course=course, u"Error rendering course={course}, section_key={section_key}".format(
section_key=section_key course=course, section_key=section_key
)) ))
return html return html
except ItemNotFoundError: except ItemNotFoundError:
log.warning("Missing about section {key} in course {url}".format( log.warning(
key=section_key, url=course.location.url())) u"Missing about section {key} in course {url}".format(key=section_key, url=course.location.url())
)
return None return None
elif section_key == "title": elif section_key == "title":
return course.display_name_with_default return course.display_name_with_default
...@@ -243,9 +244,9 @@ def get_course_info_section(request, course, section_key): ...@@ -243,9 +244,9 @@ def get_course_info_section(request, course, section_key):
html = info_module.render('student_view').content html = info_module.render('student_view').content
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
html = render_to_string('courseware/error-message.html', None) html = render_to_string('courseware/error-message.html', None)
log.exception("Error rendering course={course}, section_key={section_key}".format( log.exception(
course=course, u"Error rendering course={course}, section_key={section_key}".format(
section_key=section_key course=course, section_key=section_key
)) ))
return html return html
...@@ -282,8 +283,9 @@ def get_course_syllabus_section(course, section_key): ...@@ -282,8 +283,9 @@ def get_course_syllabus_section(course, section_key):
static_asset_path=course.static_asset_path, static_asset_path=course.static_asset_path,
) )
except ResourceNotFoundError: except ResourceNotFoundError:
log.exception("Missing syllabus section {key} in course {url}".format( log.exception(
key=section_key, url=course.location.url())) u"Missing syllabus section {key} in course {url}".format(key=section_key, url=course.location.url())
)
return "! Syllabus missing !" return "! Syllabus missing !"
raise KeyError("Invalid about key " + str(section_key)) raise KeyError("Invalid about key " + str(section_key))
......
...@@ -364,9 +364,8 @@ def index(request, course_id, chapter=None, section=None, ...@@ -364,9 +364,8 @@ def index(request, course_id, chapter=None, section=None,
raise raise
else: else:
log.exception( log.exception(
"Error in index view: user={user}, course={course}," u"Error in index view: user={user}, course={course}, chapter={chapter}"
" chapter={chapter} section={section}" u" section={section} position={position}".format(
"position={position}".format(
user=user, user=user,
course=course, course=course,
chapter=chapter, chapter=chapter,
...@@ -402,11 +401,15 @@ def jump_to_id(request, course_id, module_id): ...@@ -402,11 +401,15 @@ def jump_to_id(request, course_id, module_id):
) )
if len(items) == 0: if len(items) == 0:
raise Http404("Could not find id = {0} in course_id = {1}. Referer = {2}". raise Http404(
format(module_id, course_id, request.META.get("HTTP_REFERER", ""))) u"Could not find id: {0} in course_id: {1}. Referer: {2}".format(
module_id, course_id, request.META.get("HTTP_REFERER", "")
))
if len(items) > 1: if len(items) > 1:
log.warning("Multiple items found with id = {0} in course_id = {1}. Referer = {2}. Using first found {3}...". log.warning(
format(module_id, course_id, request.META.get("HTTP_REFERER", ""), items[0].location.url())) u"Multiple items found with id: {0} in course_id: {1}. Referer: {2}. Using first: {3}".format(
module_id, course_id, request.META.get("HTTP_REFERER", ""), items[0].location.url()
))
return jump_to(request, course_id, items[0].location.url()) return jump_to(request, course_id, items[0].location.url())
...@@ -795,9 +798,8 @@ def get_static_tab_contents(request, course, tab): ...@@ -795,9 +798,8 @@ def get_static_tab_contents(request, course, tab):
html = tab_module.render('student_view').content html = tab_module.render('student_view').content
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
html = render_to_string('courseware/error-message.html', None) html = render_to_string('courseware/error-message.html', None)
log.exception("Error rendering course={course}, tab={tab_url}".format( log.exception(
course=course, u"Error rendering course={course}, tab={tab_url}".format(course=course,tab_url=tab['url_slug'])
tab_url=tab['url_slug'] )
))
return html return html
...@@ -1519,7 +1519,7 @@ def get_and_clean_student_list(students): ...@@ -1519,7 +1519,7 @@ def get_and_clean_student_list(students):
""" """
students = split_by_comma_and_whitespace(students) students = split_by_comma_and_whitespace(students)
students = [str(s.strip()) for s in students] students = [unicode(s.strip()) for s in students]
students = [s for s in students if s != ''] students = [s for s in students if s != '']
students_lc = [x.lower() for x in students] students_lc = [x.lower() for x in students]
......
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