Skip to content
Tomas Machalek edited this page Dec 5, 2016 · 10 revisions

# Plug-ins / Plug-in API object (kontext.PluginApi)

Please note that the PluginApi object lifetime is delimited by a single request. It means that there can be no permanent 1:1 relationship between plug-in object and PluginApi object. PluginApi objects are typically injected via plug-in's exposed methods used by the controller.

# PluginApi.set_shared(key, value)

Puts a data item into a request-scope shared storage. This actually presents the only way how a plug-in can pass data to other plug-in within a request scope (remember - plug-ins' instances themselves are global). Example: ucnk_remote_auth3 loads a response from authentication service where the response contains not only user's credentials but also an HTML snippet to be displayed on pages. But the HTML handling task is actually performed by ucnk_toolbar3 plug-in. To prevent it from calling the API for the second time, auth plugin stores the HTML into the shared space and makes it available for application_bar plug-in.

# PluginApi.get_shared(key)

Get data from a request-scope shared storage. See set_shared for more details.

# PluginApi.get_environ(key, default=None)

Return a WSGI environment variable.

# PluginApi.redirect(url, code=303)

Adds a request for redirect. Please note that calling this method will not make KonText stop processing current action.

# PluginApi.cookies (@property)

Refers to the controller's KonTextCookie instance.

# PluginApi.session (@property)

Refers to the "session" object (see Werkzeug sessions).

# PluginApi.refresh_session_id()

Registers a request to change session_id. This is typically done once a user changes status (logged-in/logged-out) etc. The actual change is done after an action is processed.

# PluginApi.user_lang (@property)

Contains current user's language (languge + region form - e.g. en_US, cs_CZ)

#PluginApi.user_id (@property)

Contains a database ID of the current user

#PluginApi.user_is_anonymous (@property)

A bool attribute telling whether the current user is anonymous or not.

#PluginApi.current_corpus (@property)

Contains a current corpus (= manatee.Corpus) instance

#PluginApi.get_canonical_corpname(c)

Transform a general corpus name into a canonical one (e.g. public/europarl to europarl).

#PluginApi.text_types (@property)

Contains all the text types (= structural attributes and their respective values) for the current corpus.

#PluginApi.current_url (@property)

Contains current URL (including correct protocol and application path prefix).

Clone this wiki locally