Skip to content

Commit

Permalink
Merge pull request #387 from plone/383-content-delete
Browse files Browse the repository at this point in the history
Change content.delete to allow obj=None and objects=[] or objects=None.
  • Loading branch information
mauritsvanrees committed Sep 25, 2017
2 parents 03ec149 + 3842d62 commit 482c272
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ New features:

Bug fixes:

- Change content.delete to allow both obj=None and objects=[] or objects=None. Fixes #383
[jaroel]

- Let ``zope.i18n`` do the language negotiation for our ``translate`` function.
Our ``get_current_translation`` does not always give the correct one, especially with combined languages:
``nl-be`` (Belgian/Flemish) should fall back to ``nl`` (Dutch).
Expand Down
12 changes: 8 additions & 4 deletions src/plone/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def move(source=None, target=None, id=None, safe_id=False):

# If no target is given the object is probably renamed
if target and source.aq_parent is not target:
target.manage_pasteObjects(
source.aq_parent.manage_cutObjects(source_id),
)
target.manage_pasteObjects(
source.aq_parent.manage_cutObjects(source_id),
)
else:
target = source.aq_parent

Expand Down Expand Up @@ -296,7 +296,11 @@ def delete(obj=None, objects=None, check_linkintegrity=True):
:Example: :ref:`content_delete_example`
"""
objects = objects or [obj]
objects = [obj] if obj else objects

# Return early if we have no objects to delete.
if not objects:
return

if check_linkintegrity and NEW_LINKINTEGRITY:
site = portal.get()
Expand Down
4 changes: 4 additions & 0 deletions src/plone/api/tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ def test_delete_multiple(self):
self.assertNotIn('copy_of_about', container)
self.assertNotIn('about', container['events'])

def test_delete_no_objs(self):
# Check that we allow passing in an empty list of objects.
api.content.delete(obj=None, objects=[])

def test_delete_ignore_linkintegrity(self):
"""Test deleting a content item with a link pointed at it."""
self._set_text(self.team, '<a href="contact">contact</a>')
Expand Down

0 comments on commit 482c272

Please sign in to comment.