GitHub-only
WARNING: If you are reading this on GitHub, DON'T! Read the documentation at api.plone.org so you have working references and proper formatting.
plone
- local
Getting the Plone portal object is easy with api.portal.get
.
from plone import api
portal = api.portal.get()
In multi-lingual or multi-site Plone installations you probably want to get the language-specific navigation root object, not the top portal object. You do this with api.portal.get_navigation_root()
.
Assuming there is a document english_page
in a folder en
, which is the navigation root:
from plone import api
nav_root = api.portal.get_navigation_root(english_page)
returns the folder en
. If the folder en
is not a navigation root it would return the portal.
Since we now have the portal object, it's easy to get the portal url.
from plone import api
url = api.portal.get().absolute_url()
To get a portal tool in a simple way, just use api.portal.get_tool
and pass in the name of the tool you need.
from plone import api
catalog = api.portal.get_tool(name='portal_catalog')
To display the date/time in a user-friendly way, localized to the user's prefered language, use api.portal.get_localized_time
.
from plone import api
from DateTime import DateTime
today = DateTime()
localized = api.portal.get_localized_time(datetime=today)
To send an e-mail use api.portal.send_email
:
from plone import api
api.portal.send_email(
recipient="bob@plone.org",
sender="noreply@plone.org",
subject="Trappist",
body="One for you Bob!",
)
With api.portal.show_message
you can show a notification message to the user.
from plone import api
api.portal.show_message(message='Blueberries!')
Plone comes with a package plone.app.registry
that provides a common way to store various configuration and settings. api.portal.get_registry_record
provides an easy way to access these.
from plone import api
api.portal.get_registry_record('my.package.someoption')
Plone comes with a package plone.app.registry
that provides a common way to store various configuration and settings. api.portal.set_registry_record
provides an easy way to change these.
from plone import api
api.portal.set_registry_record('my.package.someoption', False)
For more information on possible flags and usage options please see the full plone-api-portal
specification.