From e23b693d90fd0e200fd0d640d6ec0babe94f3fc5 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 5 Jun 2013 21:31:32 -0400 Subject: [PATCH] put a 4th field in the create new course form where the user must specify a course_run. Also update unit tests to also provide this 4th parameter. Styling changes to better lay out the form fields are still TBD. --- cms/djangoapps/contentstore/features/common.py | 4 +++- .../contentstore/tests/test_contentstore.py | 15 +++++++++++---- cms/djangoapps/contentstore/views/course.py | 5 +++-- cms/static/js/base.js | 11 +++++++---- cms/static/sass/views/_dashboard.scss | 3 ++- cms/templates/index.html | 4 ++++ 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/cms/djangoapps/contentstore/features/common.py b/cms/djangoapps/contentstore/features/common.py index 648ca680b9..f4d9cc339f 100644 --- a/cms/djangoapps/contentstore/features/common.py +++ b/cms/djangoapps/contentstore/features/common.py @@ -132,10 +132,12 @@ def create_studio_user( def fill_in_course_info( name='Robot Super Course', org='MITx', - num='999'): + num='999', + run='2013_Spring'): world.css_fill('.new-course-name', name) world.css_fill('.new-course-org', org) world.css_fill('.new-course-number', num) + world.css_fill('.new-course-run', run) def log_into_studio( diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 1020f68326..1928ac4b7f 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -604,6 +604,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): 'org': 'MITx', 'number': '999', 'display_name': 'Robot Super Course', + 'run': '2013_Spring' } module_store = modulestore('direct') @@ -612,12 +613,12 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): resp = self.client.post(reverse('create_new_course'), course_data) self.assertEqual(resp.status_code, 200) data = parse_json(resp) - self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course') + self.assertEqual(data['id'], 'i4x://MITx/999/course/2013_Spring') content_store = contentstore() source_location = CourseDescriptor.id_to_location('edX/toy/2012_Fall') - dest_location = CourseDescriptor.id_to_location('MITx/999/Robot_Super_Course') + dest_location = CourseDescriptor.id_to_location('MITx/999/2013_Spring') clone_course(module_store, content_store, source_location, dest_location) @@ -954,6 +955,7 @@ class ContentStoreTest(ModuleStoreTestCase): 'org': 'MITx', 'number': '999', 'display_name': 'Robot Super Course', + 'run': '2013_Spring' } def tearDown(self): @@ -972,11 +974,15 @@ class ContentStoreTest(ModuleStoreTestCase): resp = self.client.post(reverse('create_new_course'), self.course_data) self.assertEqual(resp.status_code, 200) data = parse_json(resp) - self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course') + self.assertEqual(data['id'], 'i4x://MITx/999/course/2013_Spring') def test_create_course_check_forum_seeding(self): """Test new course creation and verify forum seeding """ self.assert_created_course() + resp = self.client.post(reverse('create_new_course'), self.course_data) + self.assertEqual(resp.status_code, 200) + data = parse_json(resp) + self.assertEqual(data['id'], 'i4x://MITx/999/course/2013_Spring') self.assertTrue(are_permissions_roles_seeded('MITx/999/Robot_Super_Course')) def test_create_course_duplicate_course(self): @@ -991,12 +997,13 @@ class ContentStoreTest(ModuleStoreTestCase): resp = self.client.post(reverse('create_new_course'), self.course_data) self.assertEqual(resp.status_code, 200) data = parse_json(resp) - self.assertEqual(data['ErrMsg'], error_message) + self.assertEqual(data['ErrMsg'], 'There is already a course defined with the same organization, course number, and course run.') def test_create_course_duplicate_number(self): """Test new course creation - error path""" self.client.post(reverse('create_new_course'), self.course_data) 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.') diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 02eb4c65b8..b2c3251e5a 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -101,9 +101,10 @@ def create_new_course(request): org = request.POST.get('org') number = request.POST.get('number') display_name = request.POST.get('display_name') + run = request.POST.get('run') try: - dest_location = Location('i4x', org, number, 'course', Location.clean(display_name)) + dest_location = Location('i4x', org, number, 'course', run) except InvalidLocationError as error: return JsonResponse({ "ErrMsg": "Unable to create course '{name}'.\n\n{err}".format( @@ -116,7 +117,7 @@ def create_new_course(request): except ItemNotFoundError: pass if existing_course is not None: - return JsonResponse({'ErrMsg': 'There is already a course defined with this name.'}) + return JsonResponse({'ErrMsg': 'There is already a course defined with the same organization, course number, and course run.'}) course_search_location = ['i4x', dest_location.org, dest_location.course, 'course', None] courses = modulestore().get_items(course_search_location) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index ebd7ed95cb..60e3420be2 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -617,22 +617,25 @@ function saveNewCourse(e) { var org = $newCourse.find('.new-course-org').val(); var number = $newCourse.find('.new-course-number').val(); var display_name = $newCourse.find('.new-course-name').val(); + var run = $newCourse.find('.new-course-run').val(); - if (org == '' || number == '' || display_name == '') { + if (org == '' || number == '' || display_name == '' || run == '') { alert(gettext('You must specify all fields in order to create a new course.')); - return; + return; } analytics.track('Created a Course', { 'org': org, 'number': number, - 'display_name': display_name + 'display_name': display_name, + 'run': run }); $.post('/create_new_course', { 'org': org, 'number': number, - 'display_name': display_name + 'display_name': display_name, + 'run': run }, function(data) { diff --git a/cms/static/sass/views/_dashboard.scss b/cms/static/sass/views/_dashboard.scss index 63c8ab36fd..bfdf93aa19 100644 --- a/cms/static/sass/views/_dashboard.scss +++ b/cms/static/sass/views/_dashboard.scss @@ -401,7 +401,8 @@ body.dashboard { .new-course-org, .new-course-number, - .new-course-name { + .new-course-name, + .new-course-run { width: 100%; } diff --git a/cms/templates/index.html b/cms/templates/index.html index 53c744c780..da1a271630 100644 --- a/cms/templates/index.html +++ b/cms/templates/index.html @@ -55,6 +55,10 @@ +
+ + +