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)¶ XXX: This should go away because are just alias
-
ploneintranet.api.events.
enable_solr_indexing
(request=None)¶ XXX: This should go away because are just alias
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)¶ 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)¶ 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.
events_disable
(request=None)¶ 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)¶ 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.
get_thumbnail_url
(obj, relative=False)¶ 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.
has_thumbnails
(obj)¶ Test if the object has generated previews. As a fallback, also check for the presence of a lead image.
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)¶ Check if object can actually be converted :param obj: The Plone object to get previews for :type obj: A Plone content object :return: True if object can be converted :rtype: boolean
User Profile API¶
-
ploneintranet.api.userprofile.
avatar_tag
(username=None, link_to=None, link_class=None)¶ 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)¶ 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)¶ 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)¶ 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
()¶ 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)¶ 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:- Users followed by the current logged-in user If not enough combined users from 1+2, fallback to:
- 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_userids
()¶ For the moment it just returns all the ids of the userprofiles we have in the site.
Returns: the userprofile ids Return type: iterator
-
ploneintranet.api.userprofile.
get_users
(context=None, full_objects=True, **kwargs)¶ 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)¶ Given a list of userids and groupids return the set of users
FIXME this has to be folded into get_users