Merge pull request #1621 from edx/christina/item-create
Change save_item and create_item to be RESTful.
This commit is contained in:
@@ -31,7 +31,7 @@ REQUIREJS_WAIT = {
|
||||
|
||||
# Individual Unit (editing)
|
||||
re.compile('^Individual Unit \|'): [
|
||||
"js/base", "coffee/src/models/module", "coffee/src/views/unit",
|
||||
"js/base", "coffee/src/views/unit",
|
||||
"coffee/src/views/module_edit"],
|
||||
|
||||
# Content - Outline
|
||||
|
||||
12
common/djangoapps/util/string_utils.py
Normal file
12
common/djangoapps/util/string_utils.py
Normal file
@@ -0,0 +1,12 @@
|
||||
"""
|
||||
Utilities for string manipulation.
|
||||
"""
|
||||
|
||||
def str_to_bool(str):
|
||||
"""
|
||||
Converts "true" (case-insensitive) to the boolean True.
|
||||
Everything else will return False (including None).
|
||||
|
||||
An error will be thrown for non-string input (besides None).
|
||||
"""
|
||||
return False if str is None else str.lower() == "true"
|
||||
33
common/djangoapps/util/tests/test_string_utils.py
Normal file
33
common/djangoapps/util/tests/test_string_utils.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
Tests for string_utils.py
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
from util.string_utils import str_to_bool
|
||||
|
||||
class StringUtilsTest(TestCase):
|
||||
"""
|
||||
Tests for str_to_bool.
|
||||
"""
|
||||
def test_str_to_bool_true(self):
|
||||
self.assertTrue(str_to_bool('True'))
|
||||
self.assertTrue(str_to_bool('true'))
|
||||
self.assertTrue(str_to_bool('trUe'))
|
||||
|
||||
def test_str_to_bool_false(self):
|
||||
self.assertFalse(str_to_bool('Tru'))
|
||||
self.assertFalse(str_to_bool('False'))
|
||||
self.assertFalse(str_to_bool('false'))
|
||||
self.assertFalse(str_to_bool(''))
|
||||
self.assertFalse(str_to_bool(None))
|
||||
self.assertFalse(str_to_bool('anything'))
|
||||
|
||||
def test_str_to_bool_errors(self):
|
||||
def test_raises_error(val):
|
||||
with self.assertRaises(AttributeError):
|
||||
self.assertFalse(str_to_bool(val))
|
||||
|
||||
test_raises_error({})
|
||||
test_raises_error([])
|
||||
test_raises_error(1)
|
||||
test_raises_error(True)
|
||||
@@ -184,12 +184,17 @@ class DraftModuleStore(MongoModuleStore):
|
||||
location: Something that can be passed to Location
|
||||
children: A list of child item identifiers
|
||||
"""
|
||||
|
||||
# We expect the children IDs to always be the non-draft version. With view refactoring
|
||||
# for split, we are now passing the draft version in some cases.
|
||||
children_ids = [as_published(child).url() for child in children]
|
||||
|
||||
draft_loc = as_draft(location)
|
||||
draft_item = self.get_item(location)
|
||||
if not getattr(draft_item, 'is_draft', False):
|
||||
self.convert_to_draft(as_published(location))
|
||||
|
||||
return super(DraftModuleStore, self).update_children(draft_loc, children)
|
||||
return super(DraftModuleStore, self).update_children(draft_loc, children_ids)
|
||||
|
||||
def update_metadata(self, location, metadata):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user