plone.api.content#

Module that provides functionality for content manipulation.

plone.api.content.copy(source=None, target=None, id=None, safe_id=False)[source]#

Copy the object to the target container.

Parameters:
  • source (Content object) -- [required] Object that we want to copy.

  • target (Folderish content object) -- Target container to which the source object will be moved. If no target is specified, the source object's container will be used as a target.

  • id (string) -- Id of the copied object on the target location. If no id is provided, the copied object will have the same id as the source object - however, if the new object's id conflicts with another object in the target container, a suffix will be added to the new object's id.

  • safe_id (boolean) -- When False, the given id will be enforced. If the id is conflicting with another object in the target container, raise a InvalidParameterError. When True, choose a new, non-conflicting id.

Returns:

Content object that was created in the target location

Raises:

KeyError, ValueError

Example:

Copy content

plone.api.content.create(container=None, type=None, id=None, title=None, safe_id=False, **kwargs)[source]#

Create a new content item.

Parameters:
  • container (Folderish content object) -- [required] Container object in which to create the new object.

  • type (string) -- [required] Type of the object.

  • id (string) -- Id of the object. If the id conflicts with another object in the container, a suffix will be added to the new object's id. If no id is provided, automatically generate one from the title. If there is no id or title provided, raise a ValueError.

  • title (string) -- Title of the object. If no title is provided, use id as the title.

  • safe_id (boolean) -- When False, the given id will be enforced. If the id is conflicting with another object in the target container, raise an InvalidParameterError. When True, choose a new, non-conflicting id.

Returns:

Content object

Raises:

KeyError, MissingParameterError, InvalidParameterError

Example:

Create content

plone.api.content.delete(obj=None, objects=None, check_linkintegrity=True)[source]#

Delete the object(s).

Parameters:
  • obj (Content object) -- Object that we want to delete.

  • objects (List of content objects) -- Objects that we want to delete.

  • check_linkintegrity (boolean) -- Raise exception if there are linkintegrity-breaches.

Raises:

ValueError plone.app.linkintegrity.exceptions.LinkIntegrityNotificationException

Example:

Delete content

plone.api.content.disable_roles_acquisition(obj=None)[source]#

Disable acquisition of local roles on given obj.

Set __ac_local_roles_block__ = 1 on obj.

Parameters:

obj (Content object) -- [required] Context object to block the acquisition on.

Example:

Disable local roles acquisition

plone.api.content.enable_roles_acquisition(obj=None)[source]#

Enable acquisition of local roles on given obj.

Set __ac_local_roles_block__ = 0 on obj.

Parameters:

obj (Content object) -- [required] Context object to enable the acquisition on.

Example:

Enable local roles acquisition

plone.api.content.find(context=None, depth=None, unrestricted=False, **kwargs)[source]#

Find content in the portal.

Parameters:
  • context -- Context for the search

  • depth -- How far in the content tree we want to search from context

  • unrestricted -- Boolean, use unrestrictedSearchResults if True

Returns:

Catalog brains

Return type:

List

Example:

Find content objects

plone.api.content.get(path=None, UID=None)[source]#

Get an object.

Parameters:
  • path (string) -- Path to the object we want to get, relative to the portal root.

  • UID (string) -- UID of the object we want to get.

Returns:

Content object

Raises:

ValueError,

Example:

Get content object

plone.api.content.get_closest_ancestor(obj=None, function=None, interface=None, stop_at=[])[source]#

Get the closest ancestor that matches the criteria.

See iter_ancestors() for more information on the parameters.

Parameters:
  • obj (Content object) -- [required] Object for which we want to get the ancestor.

  • function (callable) -- Optional callable that takes an object and returns a boolean.

  • interface (zope.interface.Interface) -- Optional interface that should be provided by the ancestor.

  • stop_at (Content object or False) -- Optional object at which to stop the iteration. If False is passed as the value, we will return all the matching objects in the acquisition chain

Returns:

Iterator of ancestor objects, from immediate to site root.

Return type:

iterator

Example:

Get closest ancestor

plone.api.content.get_path(obj=None, relative=False)[source]#

Get the path of an object.

Parameters:
  • obj (Content object) -- [required] Object for which to get its path

  • relative (boolean) -- Return a relative path from the portal root

Returns:

Path to the object

Return type:

string

Raises:

InvalidParameterError

Example:

Get content path

plone.api.content.get_state(obj=None, default=[])[source]#

Get the current workflow state of the object.

Parameters:
  • obj (Content object) -- [required] Object that we want to get the state for.

  • default -- Returned if no workflow is defined for the object.

Returns:

Object's current workflow state, or default.

Return type:

string

Raises:

Products.CMFCore.WorkflowCore.WorkflowException

Example:

Get workflow state

plone.api.content.get_uuid(obj=None)[source]#

Get the object's Universally Unique IDentifier (UUID).

Parameters:

obj (Content object) -- [required] Object we want its UUID.

Returns:

Object's UUID

Return type:

string

Raises:

ValueError

Example:

Get content object UUID

plone.api.content.get_view(name=None, context=None, request=None)[source]#

Get a BrowserView object.

Parameters:
  • name (string) -- [required] Name of the view.

  • context (context object) -- [required] Context on which to get view.

  • request (request object) -- [required] Request on which to get view.

Raises:

MissingParameterError, InvalidParameterError

Example:

Get view

plone.api.content.iter_ancestors(obj=None, function=None, interface=None, stop_at=[])[source]#

Iterate over the object ancestors.

Optionally filter the ancestors:

  1. by a custom function.

  2. by interface.

The iteration will stop by default at the portal root. If you want to stop at a specific object, pass it as the stop_at parameter. If you want to return all the matching objects in the acquisition chain, pass False as the value of the stop_at parameter.

Parameters:
  • obj (Content object) -- [required] Object for which we want to iterate over the ancestors.

  • function (callable) -- Optional callable that takes an object and returns a boolean.

  • interface (zope.interface.Interface) -- Optional interface that should be provided by the ancestor.

  • stop_at (Content object or False) -- Optional object at which to stop the iteration. If False is passed as the value, we will return all the matching objects in the acquisition chain

Returns:

Iterator of ancestor objects, from immediate to site root.

Return type:

iterator

Example:

Iterate over object ancestors

plone.api.content.move(source=None, target=None, id=None, safe_id=False)[source]#

Move the object to the target container.

Parameters:
  • source (Content object) -- [required] Object that we want to move.

  • target (Folderish content object) -- Target container to which the source object will be moved. If no target is specified, the source object's container will be used as a target, effectively making this operation a rename (Rename content).

  • id (string) -- Pass this parameter if you want to change the id of the moved object on the target location. If the new id conflicts with another object in the target container, a suffix will be added to the moved object's id.

  • safe_id (boolean) -- When False, the given id will be enforced. If the id is conflicting with another object in the target container, raise a InvalidParameterError. When True, choose a new, non-conflicting id.

Returns:

Content object that was moved to the target location

Raises:

KeyError ValueError

Example:

Move content

plone.api.content.rename(obj=None, new_id=None, safe_id=False)[source]#

Rename the object.

Parameters:
  • obj (Content object) -- [required] Object that we want to rename.

  • new_id (string) -- New id of the object.

  • safe_id (boolean) -- When False, the given id will be enforced. If the id is conflicting with another object in the container, raise a InvalidParameterError. When True, choose a new, non-conflicting id.

Returns:

Content object that was renamed

Example:

Rename content

plone.api.content.transition(obj=None, transition=None, to_state=None, **kwargs)[source]#

Perform a workflow transition.

for the object or attempt to perform workflow transitions on the object to reach the given state. The later will not guarantee that transition guards conditions can be met.

Accepts kwargs to supply to the workflow policy in use, such as "comment"

Parameters:
  • obj (Content object) -- [required] Object for which we want to perform the workflow transition.

  • transition (string) -- Name of the workflow transition.

  • to_state (string) -- Name of the workflow state.

Raises:

MissingParameterError, InvalidParameterError

Example:

Transition