Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change content.delete to allow obj=None and objects=[] or objects=None. #387

Merged
merged 2 commits into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=[])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is wrong as obj and objects are mutually exclusive parameters:

@mutually_exclusive_parameters('obj', 'objects')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test passes, so apparently it is fine.
I see that the mutually_exclusive_parameters decorator uses _get_supplied_args, which ignores arguments that are None. That seems why it is okay.


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