GitHub-only

WARNING: If you are reading this on GitHub, DON’T! Read the documentation at docs.plone.org so you have working references and proper formatting.

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, **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

Returns

Catalog brains

Return type

List

Example

Find content objects

Find works alike catalog(). Indexes are passing in as arguments with the search query as the values.

Specify indexes as arguments: >>> find(portal_type=’Document’)

or combinations of indexes. >>> find(portal_type=’Document’, SearchableText=’Team’)

Differences to using the catalog directly are:

The context argument allows passing in an context object, instead of path=’/’.join(context.getPhysicalPath().

>>> find(context=context)
- or -
>>> find(context=context, portal_type='Document')

Specifing the search depth is supported using the depth argument. >>> find(depth=1)

Using depth needs a context for it’s path. If no context and no path is passed, the portal root is used. >>> find(context=portal, depth=1, portal_type=’Document’) - or - >>> find(depth=1, path=’/plone/folder’, portal_type=’Document’) - or - >>> find(depth=1, portal_type=’Document’)

The path can be queried directly, too: >>> find(path={‘query’: ‘/plone/about/team’, ‘depth’: 1})

The object_provides index/argument allows Interface objects as well as identifiers. It also supports querying multiple interfaces combined with and or or. >>> find(object_provides=IATDocument) - or - >>> find(object_provides=IATDocument.__identifier__) - or - >>> find(object_provides={ … ‘query’: [IATFolder, INavigationRoot], … ‘operator’: ‘and’, … })

An empty resultset is returned if no valid indexes are queried. >>> len(find()) >>> 0

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_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.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