From 1cd70ee38620517945aaa88c1f28976107ee719f Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Thu, 25 Jul 2013 21:25:09 -0400 Subject: [PATCH] fix some error messages and also make localizable strings --- .../contentstore/tests/test_contentstore.py | 4 +-- cms/djangoapps/contentstore/views/course.py | 12 ++++++--- cms/static/js/base.js | 26 +++++++++---------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 136fd20e0e..18fbf6fdf1 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -990,7 +990,7 @@ class ContentStoreTest(ModuleStoreTestCase): def test_create_course_duplicate_course(self): """Test new course creation - error path""" self.client.post(reverse('create_new_course'), self.course_data) - self.assert_course_creation_failed('There is already a course defined with the same organization, course number, and course run.') + self.assert_course_creation_failed('There is already a course defined with the same organization, course number, and course run. Please change at least one field to be unique.') def assert_course_creation_failed(self, error_message): """ @@ -1007,7 +1007,7 @@ class ContentStoreTest(ModuleStoreTestCase): self.course_data['display_name'] = 'Robot Super Course Two' self.course_data['run'] = '2013_Summer' - self.assert_course_creation_failed('There is already a course defined with the same organization and course number.') + self.assert_course_creation_failed('There is already a course defined with the same organization and course number. Please change at least one field to be unique.') def test_create_course_with_bad_organization(self): """Test new course creation - error path for bad organization name""" diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 03d2e9214f..4920b46241 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -3,7 +3,7 @@ Views related to operations on course objects """ import json import random -import logging +from django.utils.translation import ugettext as _ import string # pylint: disable=W0402 from django.contrib.auth.decorators import login_required @@ -108,7 +108,7 @@ def create_new_course(request): dest_location = Location('i4x', org, number, 'course', run) except InvalidLocationError as error: return JsonResponse({ - "ErrMsg": "Unable to create course '{name}'.\n\n{err}".format( + "ErrMsg": _("Unable to create course '{name}'.\n\n{err}").format( name=display_name, err=error.message)}) # see if the course already exists @@ -118,12 +118,16 @@ def create_new_course(request): except ItemNotFoundError: pass if existing_course is not None: - return JsonResponse({'ErrMsg': 'There is already a course defined with the same organization, course number, and course run.'}) + return JsonResponse( + { + 'ErrMsg': _('There is already a course defined with the same organization, course number, and course run. Please change at least one field to be unique.'), + } + ) course_search_location = ['i4x', dest_location.org, dest_location.course, 'course', None] courses = modulestore().get_items(course_search_location) if len(courses) > 0: - return JsonResponse({'ErrMsg': 'There is already a course defined with the same organization and course number.'}) + return JsonResponse({'ErrMsg': _('There is already a course defined with the same organization and course number. Please change at least one field to be unique.')}) # instantiate the CourseDescriptor and then persist it # note: no system to pass diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 0043f86446..9f992d5ab2 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -610,8 +610,7 @@ function addNewCourse(e) { }, checkForCancel); } -function setNewCourseFieldInErr(el, msg) -{ +function setNewCourseFieldInErr(el, msg) { el.children('.tip-error').remove(); if (msg !== null && msg !== '') { el.addClass('error'); @@ -621,8 +620,15 @@ function setNewCourseFieldInErr(el, msg) } } -function setNewCourseFieldsInErr(display_name_errMsg, org_errMsg, number_errMsg, run_errMsg) -{ +function setNewCourseErrMsgs(header_err_msg, display_name_errMsg, org_errMsg, number_errMsg, run_errMsg) { + if (header_err_msg) { + $('.wrap-error').addClass('is-shown'); + $('#course_creation_error').html('

' + header_err_msg + '

'); + } else { + $('.wrap-error').removeClass('is-shown'); + $('#course_creation_error').html(''); + } + setNewCourseFieldInErr($('#field-course-name'), display_name_errMsg); setNewCourseFieldInErr($('#field-organization'), org_errMsg); setNewCourseFieldInErr($('#field-course-number'), number_errMsg); @@ -649,15 +655,7 @@ function saveNewCourse(e) { header_err_msg = (bInErr) ? gettext('Please correct the fields below.') : null; - if (header_err_msg) { - $('.wrap-error').addClass('is-shown'); - $('#course_creation_error').html('

' + header_err_msg + '

'); - } else { - $('.wrap-error').removeClass('is-shown'); - $('#course_creation_error').html(''); - } - - setNewCourseFieldsInErr(display_name_errMsg, org_errMsg, number_errMsg, run_errMsg); + setNewCourseErrMsgs(header_err_msg, display_name_errMsg, org_errMsg, number_errMsg, run_errMsg); if (bInErr) return; @@ -679,7 +677,7 @@ function saveNewCourse(e) { if (data.id !== undefined) { window.location = '/' + data.id.replace(/.*:\/\//, ''); } else if (data.ErrMsg !== undefined) { - alert(data.ErrMsg); + setNewCourseErrMsgs(data.ErrMsg, null, null, null, null); } } );