コード例 #1
0
def update_library(
    library_key,
    title=None,
    description=None,
    allow_public_learning=None,
    allow_public_read=None,
    library_type=None,
):
    """
    Update a library's title or description.
    (Slug cannot be changed as it would break IDs throughout the system.)

    A value of None means "don't change".
    """
    ref = ContentLibrary.objects.get_by_key(library_key)
    # Update MySQL model:
    changed = False
    if allow_public_learning is not None:
        ref.allow_public_learning = allow_public_learning
        changed = True
    if allow_public_read is not None:
        ref.allow_public_read = allow_public_read
        changed = True
    if library_type is not None:
        if library_type != COMPLEX:
            for block in get_library_blocks(library_key):
                if block.usage_key.block_type != library_type:
                    raise IncompatibleTypesError(
                        _('You can only set a library to {library_type} if all existing blocks are of that type. '
                          'Found incompatible block {block_id} with type {block_type}.'
                          ).format(
                              library_type=library_type,
                              block_type=block.usage_key.block_type,
                              block_id=block.usage_key.block_id,
                          ), )
        ref.type = library_type

        changed = True
    if changed:
        ref.save()
    # Update Blockstore:
    fields = {
        # We don't ever read the "slug" value from the Blockstore bundle, but
        # we might as well always do our best to keep it in sync with the "slug"
        # value in the LMS that we do use.
        "slug": ref.slug,
    }
    if title is not None:
        assert isinstance(title, six.string_types)
        fields["title"] = title
    if description is not None:
        assert isinstance(description, six.string_types)
        fields["description"] = description
    update_bundle(ref.bundle_uuid, **fields)
    CONTENT_LIBRARY_UPDATED.send(sender=None, library_key=ref.library_key)
コード例 #2
0
 def test_bundle_crud(self):
     """ Create, Fetch, Update, and Delete a Bundle """
     coll = api.create_collection("Test Collection")
     args = {
         "title": "Water 💧 Bundle",
         "slug": "h2o",
         "description": "Sploosh",
     }
     # Create:
     bundle = api.create_bundle(coll.uuid, **args)
     for attr, value in args.items():
         self.assertEqual(getattr(bundle, attr), value)
     self.assertIsInstance(bundle.uuid, UUID)
     # Fetch:
     bundle2 = api.get_bundle(bundle.uuid)
     self.assertEqual(bundle, bundle2)
     # Update:
     new_description = "Water Nation Bending Lessons"
     bundle3 = api.update_bundle(bundle.uuid, description=new_description)
     self.assertEqual(bundle3.description, new_description)
     bundle4 = api.get_bundle(bundle.uuid)
     self.assertEqual(bundle4.description, new_description)
     # Delete:
     api.delete_bundle(bundle.uuid)
     with self.assertRaises(api.BundleNotFound):
         api.get_bundle(bundle.uuid)
コード例 #3
0
 def test_bundle_crud(self):
     """ Create, Fetch, Update, and Delete a Bundle """
     coll = api.create_collection("Test Collection")
     args = {
         "title": "Water 💧 Bundle",
         "slug": "h2o",
         "description": "Sploosh",
     }
     # Create:
     bundle = api.create_bundle(coll.uuid, **args)
     for attr, value in args.items():
         assert getattr(bundle, attr) == value
     assert isinstance(bundle.uuid, UUID)
     # Fetch:
     bundle2 = api.get_bundle(bundle.uuid)
     assert bundle == bundle2
     # Update:
     new_description = "Water Nation Bending Lessons"
     bundle3 = api.update_bundle(bundle.uuid, description=new_description)
     assert bundle3.description == new_description
     bundle4 = api.get_bundle(bundle.uuid)
     assert bundle4.description == new_description
     # Delete:
     api.delete_bundle(bundle.uuid)
     with pytest.raises(api.BundleNotFound):
         api.get_bundle(bundle.uuid)
コード例 #4
0
ファイル: api.py プロジェクト: ultrasound/edx-platform
def update_library(library_key, title=None, description=None):
    """
    Update a library's title or description.
    (Slug cannot be changed as it would break IDs throughout the system.)

    A value of None means "don't change".
    """
    ref = ContentLibrary.objects.get_by_key(library_key)
    fields = {
        # We don't ever read the "slug" value from the Blockstore bundle, but
        # we might as well always do our best to keep it in sync with the "slug"
        # value in the LMS that we do use.
        "slug": ref.slug,
    }
    if title is not None:
        assert isinstance(title, six.string_types)
        fields["title"] = title
    if description is not None:
        assert isinstance(description, six.string_types)
        fields["description"] = description
    update_bundle(ref.bundle_uuid, **fields)
コード例 #5
0
def update_library(
    library_key,
    title=None,
    description=None,
    allow_public_learning=None,
    allow_public_read=None,
):
    """
    Update a library's title or description.
    (Slug cannot be changed as it would break IDs throughout the system.)

    A value of None means "don't change".
    """
    ref = ContentLibrary.objects.get_by_key(library_key)
    # Update MySQL model:
    changed = False
    if allow_public_learning is not None:
        ref.allow_public_learning = allow_public_learning
        changed = True
    if allow_public_read is not None:
        ref.allow_public_read = allow_public_read
        changed = True
    if changed:
        ref.save()
    # Update Blockstore:
    fields = {
        # We don't ever read the "slug" value from the Blockstore bundle, but
        # we might as well always do our best to keep it in sync with the "slug"
        # value in the LMS that we do use.
        "slug": ref.slug,
    }
    if title is not None:
        assert isinstance(title, six.string_types)
        fields["title"] = title
    if description is not None:
        assert isinstance(description, six.string_types)
        fields["description"] = description
    update_bundle(ref.bundle_uuid, **fields)
    CONTENT_LIBRARY_UPDATED.send(sender=None, library_key=ref.library_key)