Plone Intranet API

The ploneintranet.api package provides a simple developer API to the most commonly used features of ploneintranet.

Disabling event handlers

Sometimes, e.g. during a transmogrifier import, you want to disable certain event handers, either because you don’t want their autocreation effects, or because they’re computationally costly.

This becomes especially important because of the async nature of the costly heavy lifting handlers. In case of a long-running original request (say, a deep copy or a big import) the async job may fire before the original request is completed. In that case, because the original request has not yet committed, the async job has nothing to work on, which leads to rescheduling of async jobs, a lot of log noise, and much developer head scratching.

So, just disable that stuff. Each of these has alternatives that can be used for ex-post batch fixing:

  • Solr indexing can be done post-hoc with the @@solr-maintenance view
  • There’s a subtree reindexing view too somewhere
  • Preview generation can be done post-hoc via @@generate-previews-for-contents and its async variant
  • Microblog content updates can be created post-hoc by running the ploneintranet.microblog:default > discuss older docs upgrade step.
ploneintranet.api.events.disable_solr_indexing(request=None)[source]
ploneintranet.api.events.enable_solr_indexing(request=None)[source]

Microblogging API

ploneintranet.api.microblog.statusupdate.create(text=u'', microblog_context=None, thread_id=None, mention_ids=None, tags=None, user=None, userid=None, time=None, content_context=None, action_verb=None)[source]

Create a status update (post).

Parameters:
  • text (Unicode object) – text of the post
  • microblog_context (Content object) – Container of the post
  • user (user object) – User who should post. By default the current user posts.
  • userid (string) – userid of the user who should post.
  • time (timezone aware datetime object) – time when the post should happen. By default the current time.
  • content_context (content object) – a content referenced we are talking about
  • action_verb (string) – indicate event source (posted, created, published)
Returns:

Newly created statusupdate

Return type:

StatusUpdate object

Note that you can add attachments to statusupdates by calling .add_attachment(filename, data) on the returned StatusUpdate.

ploneintranet.api.microblog.statusupdate.get(status_id)[source]

Get a status update by id.

Parameters:status_id (int) – The id of the status update
Returns:The matching StatusUpdate
Return type:StatusUpdate

Previews API

Methods to generate and access preview images on content

ploneintranet.api.previews.converting(obj)[source]

Check if object is currently being converted

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:True if converting, False if no longer converting
Return type:boolean
ploneintranet.api.previews.events_disable(request=None)[source]

Temporarily disable event-driven preview generation for this request.

Parameters:request (Request) – The request for which events are to be disabled
ploneintranet.api.previews.events_enable(request=None)[source]

Re-enable event-driven preview generation for this request. This only makes sense if you explicitly disabled preview generation, since it is enabled by default.

Parameters:request (Request) – The request for which events were disabled
ploneintranet.api.previews.fallback_image(obj)[source]

DEPRECATED: Return a fallback image for use if there are no previews.

Prototype does not use fallback image anymore, instead offers css solution.

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:An image object
Return type:ZODB.blob.Blob
ploneintranet.api.previews.fallback_image_url(obj)[source]

DEPRECATED: Return a fallback image URL for use if there are no previews.

Prototype does not use fallback image anymore, instead offers css solution.

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:An image object url
Return type:string
ploneintranet.api.previews.generate_pdf(obj, event=None)[source]

Generate a pdf for a content type. We need our own subscriber as c.dv insists on checking for its custom layout. Also we want our own async mechanism, it is using this method.

Parameters:obj (A Plone content object) – The Plone content object to get preview URLs for
Returns:Does not return anything.
Return type:None
ploneintranet.api.previews.generate_previews(obj, event=None)[source]

Generate the previews for a content type. We need our own subscriber as c.dv insists on checking for its custom layout. Also we want our own async mechanism, it is using this method.

Parameters:obj (A Plone content object) – The Plone content object to get preview URLs for
Returns:Does not return anything.
Return type:None
ploneintranet.api.previews.get(obj, scale='normal')[source]

Get the preview images for the given object

If there are currently no previews, an empty list will be returned

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:The preview images
Return type:list
ploneintranet.api.previews.get_pdf(obj)[source]

NOT IMPLEMENTED. Once we do pdf generation for text content, this will work

Parameters:obj (A Plone content object) – The Plone content object to get preview URLs for
Returns:The generated pdf preview of the content item
Return type:Blob
ploneintranet.api.previews.get_preview_urls(obj, scale='normal', with_timestamp=False)[source]

Convenience method to get URLs of image previews as these are most frequently used

Parameters:
  • obj (A Plone content object) – The Plone content object to get preview URLs for
  • scale (str) – The Plone image scale to get preview images at
  • with_timestamp (bool) – If True add a timestamp to the URLs
Returns:

List of preview image absolute URLs

Return type:

list

ploneintranet.api.previews.get_thumbnail(obj)[source]

Get the thumnail preview image for the given object

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:The preview thumbnail
Return type:ImageScaling
ploneintranet.api.previews.get_thumbnail_url(obj, relative=False)[source]

Convenience method to get the absolute URL of thumbnail image

Parameters:
  • obj (A Plone content object) – The Plone content object to get preview URLs for
  • relative (boolean) – Specify whether the url should be relative or not
Returns:

The absolute URL to the thumbnail image

Return type:

str

ploneintranet.api.previews.get_thumbnail_url_by_uid(uid, relative=False)[source]

Convenience method to get the absolute URL of thumbnail image this time without fetching the object but by calculating it from the uid this can be used in catalog results where we already know using has_thumb that a thumbnail image exists.

Parameters:
  • uid (string) – The UID of a Plone content object to get preview URLs for
  • relative (boolean) – Specify whether the url should be relative or not
Returns:

The absolute URL to the thumbnail image

Return type:

str

ploneintranet.api.previews.has_pdf(obj)[source]

NOT IMPLEMENTED. Once we do pdf generation for text content, this will work

Parameters:obj (A Plone content object) – The Plone content object to get preview URLs for
Returns:True if there is a pdf available
Return type:boolean
ploneintranet.api.previews.has_previews(obj)[source]

Test if the object has generated previews.

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:True if there are previews. False otherwise.
Return type:boolean
ploneintranet.api.previews.is_allowed_document_type(obj)[source]

Check if object can actually be converted

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:True if object can be converted
Return type:boolean
ploneintranet.api.previews.purge_previews(obj)[source]

Purge the previews from obj

Parameters:obj (A Plone content object) – The Plone content object for which we want to purge the previews
Returns:Does not return anything.
Return type:None
ploneintranet.api.previews.successfully_converted(obj)[source]

Check if object could be converted

Parameters:obj (A Plone content object) – The Plone object to get previews for
Returns:True if successfully converted, False if conversion failed
Return type:boolean

User Profile API

ploneintranet.api.userprofile.avatar_tag(username=None, link_to=None)[source]

Get the tag that renders the user avatar wrapped in a link

Parameters:username (string) – Username for which to get the avatar url
Returns:HTML for the avatar tag
Return type:string
ploneintranet.api.userprofile.avatar_url(username=None)[source]

Get the avatar image url for a user profile

Parameters:username (string) – Username for which to get the avatar url
Returns:absolute url for the avatar image
Return type:string
ploneintranet.api.userprofile.create(username, email=None, password=None, approve=False, properties=None)[source]

Create a Plone Intranet user profile.

Parameters:
  • username (string) – [required] The userid for the new user. WTF? see #1043.
  • email (string) – [required] Email for the new user.
  • password (string) – Password for the new user. If it’s not set we generate a random 12-char alpha-numeric one.
  • approve (boolean) – If True, the user profile will be automatically approved and be able to log in.
  • properties (dict) – User properties to assign to the new user.
Returns:

Newly created user

Return type:

ploneintranet.userprofile.content.userprofile.UserProfile object

ploneintranet.api.userprofile.get(userid)[source]

Get a Plone Intranet user profile by userid. userid == username, but username != getUsername(), see #1043.

Parameters:userid (string) – Usernid of the user profile to be found
Returns:User profile matching the given userid
Return type:ploneintranet.userprofile.content.userprofile.UserProfile object
ploneintranet.api.userprofile.get_current()[source]

Get the Plone Intranet user profile for the current logged-in user

Returns:User profile matching the current logged-in user
Return type:ploneintranet.userprofile.content.userprofile.UserProfile object
ploneintranet.api.userprofile.get_user_suggestions(context=None, full_objects=True, min_matches=5, **kwargs)[source]

This is a wrapper around get_users with the intent of providing staggered suggestion of users for a user picker: 1. Users from the current context (workspace)

If not enough users, add:
  1. Users followed by the current logged-in user If not enough combined users from 1+2, fallback to:
  2. All users in the portal.

List users from catalog, avoiding expensive LDAP lookups.

Parameters:
  • context (Content object) – Any content object that will be used to find the UserResolver context
  • full_objects (boolean) – A switch to indicate if full objects or brains should be returned
  • min_matches (int) – Keeps expanding search until this treshold is reached
Returns:

user brains or user objects

Return type:

iterator

ploneintranet.api.userprofile.get_users(context=None, full_objects=True, **kwargs)[source]

List users from catalog, avoiding expensive LDAP lookups.

Parameters:
  • context (Content object) – Any content object that will be used to find the UserResolver context
  • full_objects (boolean) – A switch to indicate if full objects or brains should be returned
Returns:

user brains or user objects

Return type:

iterator

ploneintranet.api.userprofile.get_users_from_userids_and_groupids(ids=None)[source]

Given a list of userids and groupids return the set of users

FIXME this has to be folded into get_users