Commit 1cd70ee3 by Chris Dodge Committed by Brian Talbot

fix some error messages and also make localizable strings

parent 39b024b1
...@@ -990,7 +990,7 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -990,7 +990,7 @@ class ContentStoreTest(ModuleStoreTestCase):
def test_create_course_duplicate_course(self): def test_create_course_duplicate_course(self):
"""Test new course creation - error path""" """Test new course creation - error path"""
self.client.post(reverse('create_new_course'), self.course_data) 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): def assert_course_creation_failed(self, error_message):
""" """
...@@ -1007,7 +1007,7 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -1007,7 +1007,7 @@ class ContentStoreTest(ModuleStoreTestCase):
self.course_data['display_name'] = 'Robot Super Course Two' self.course_data['display_name'] = 'Robot Super Course Two'
self.course_data['run'] = '2013_Summer' 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): def test_create_course_with_bad_organization(self):
"""Test new course creation - error path for bad organization name""" """Test new course creation - error path for bad organization name"""
......
...@@ -3,7 +3,7 @@ Views related to operations on course objects ...@@ -3,7 +3,7 @@ Views related to operations on course objects
""" """
import json import json
import random import random
import logging from django.utils.translation import ugettext as _
import string # pylint: disable=W0402 import string # pylint: disable=W0402
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
...@@ -108,7 +108,7 @@ def create_new_course(request): ...@@ -108,7 +108,7 @@ def create_new_course(request):
dest_location = Location('i4x', org, number, 'course', run) dest_location = Location('i4x', org, number, 'course', run)
except InvalidLocationError as error: except InvalidLocationError as error:
return JsonResponse({ 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)}) name=display_name, err=error.message)})
# see if the course already exists # see if the course already exists
...@@ -118,12 +118,16 @@ def create_new_course(request): ...@@ -118,12 +118,16 @@ def create_new_course(request):
except ItemNotFoundError: except ItemNotFoundError:
pass pass
if existing_course is not None: 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] course_search_location = ['i4x', dest_location.org, dest_location.course, 'course', None]
courses = modulestore().get_items(course_search_location) courses = modulestore().get_items(course_search_location)
if len(courses) > 0: 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 # instantiate the CourseDescriptor and then persist it
# note: no system to pass # note: no system to pass
......
...@@ -610,8 +610,7 @@ function addNewCourse(e) { ...@@ -610,8 +610,7 @@ function addNewCourse(e) {
}, checkForCancel); }, checkForCancel);
} }
function setNewCourseFieldInErr(el, msg) function setNewCourseFieldInErr(el, msg) {
{
el.children('.tip-error').remove(); el.children('.tip-error').remove();
if (msg !== null && msg !== '') { if (msg !== null && msg !== '') {
el.addClass('error'); el.addClass('error');
...@@ -621,8 +620,15 @@ function setNewCourseFieldInErr(el, msg) ...@@ -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('<p>' + header_err_msg + '</p>');
} else {
$('.wrap-error').removeClass('is-shown');
$('#course_creation_error').html('');
}
setNewCourseFieldInErr($('#field-course-name'), display_name_errMsg); setNewCourseFieldInErr($('#field-course-name'), display_name_errMsg);
setNewCourseFieldInErr($('#field-organization'), org_errMsg); setNewCourseFieldInErr($('#field-organization'), org_errMsg);
setNewCourseFieldInErr($('#field-course-number'), number_errMsg); setNewCourseFieldInErr($('#field-course-number'), number_errMsg);
...@@ -649,15 +655,7 @@ function saveNewCourse(e) { ...@@ -649,15 +655,7 @@ function saveNewCourse(e) {
header_err_msg = (bInErr) ? gettext('Please correct the fields below.') : null; header_err_msg = (bInErr) ? gettext('Please correct the fields below.') : null;
if (header_err_msg) { setNewCourseErrMsgs(header_err_msg, display_name_errMsg, org_errMsg, number_errMsg, run_errMsg);
$('.wrap-error').addClass('is-shown');
$('#course_creation_error').html('<p>' + header_err_msg + '</p>');
} else {
$('.wrap-error').removeClass('is-shown');
$('#course_creation_error').html('');
}
setNewCourseFieldsInErr(display_name_errMsg, org_errMsg, number_errMsg, run_errMsg);
if (bInErr) if (bInErr)
return; return;
...@@ -679,7 +677,7 @@ function saveNewCourse(e) { ...@@ -679,7 +677,7 @@ function saveNewCourse(e) {
if (data.id !== undefined) { if (data.id !== undefined) {
window.location = '/' + data.id.replace(/.*:\/\//, ''); window.location = '/' + data.id.replace(/.*:\/\//, '');
} else if (data.ErrMsg !== undefined) { } else if (data.ErrMsg !== undefined) {
alert(data.ErrMsg); setNewCourseErrMsgs(data.ErrMsg, null, null, null, null);
} }
} }
); );
......
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