Commit e23b693d by Chris Dodge Committed by Brian Talbot

put a 4th field in the create new course form where the user must specify a…

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.
parent 7d7513b6
......@@ -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(
......
......@@ -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.')
......
......@@ -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)
......
......@@ -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) {
......
......@@ -401,7 +401,8 @@ body.dashboard {
.new-course-org,
.new-course-number,
.new-course-name {
.new-course-name,
.new-course-run {
width: 100%;
}
......
......@@ -55,6 +55,10 @@
<label>${_("Course Number")}</label>
<input type="text" class="new-course-number" />
</div>
<div class="column">
<label>Course Run</label>
<input type="text" class="new-course-run" />
</div>
</div>
<div class="row">
<input type="submit" value="${_('Save')}" class="new-course-save"/>
......
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