lino.core.plugin¶
This defines the Plugin
class.
Classes
|
The base class for all plugin descriptors. |
- class lino.core.plugin.Plugin(site, app_label, app_name, app_module, needed_by, configs: dict)¶
Bases:
object
The base class for all plugin descriptors.
For an introduction, see Introduction to plugins.
Plugin descriptors get defined and configured before Django models start to load. Lino creates one
Plugin
instance for every installed plugin and makes it globally available indd.plugins.FOO
(where FOO is the app_label of the plugin).The
Plugin
class is comparable to Django's AppConfig class, which has been added in version 1.7., but there is at least one important difference: in Lino thePlugin
instances for all installed plugins are available (indd.plugins
) before Django starts to load the firstmodels.py
. This is possible because Plugins are defined in__init__.py
files of your plugins. As a consequence, unlike Django's AppConfig, you cannot define a Plugin in yourmodels.py
file, you must define it in your plugins's__init__.py
.- needs_plugins = []¶
A list of names of plugins needed by this plugin.
The default implementation of
get_required_plugins()
returns this list.
- extends_models = None¶
If specified, a list of model names for which this app provides a subclass.
For backwards compatibility this has no effect when
override_modlib_models
is set.
- disables_plugins = []¶
A list of strings with names of plugins to not install even though they are yeld by
get_installed_apps
. This is applied as an additional plugin filter even afterget_apps_modifiers
.The plugin names can be either the full name or just the app_label.
This list is allowed to contain names of plugins which are not installed at all.
Usage example: The
lino.modlib.tinymce
works only with ExtJS 3, and we currently believe that we will never need it in ExtJS 6. When switching back and forth betweenlino.modlib.extjs
andlino_extjs6.extjs6
, we had to remove it explicitly by also defining aget_apps_modifiers
method:def get_apps_modifiers(self, **kw): kw = super(Site, self).get_apps_modifiers(**kw) kw.update(tinymce=None) return kw
Now
lino_extjs6.extjs6
hasdisables_plugins
set to['tinymce']
and we no longer need above code because Lino now removes it automatically when ExtJS 6 is being used.
- ui_handle_attr_name = None¶
Currently implemented by
lino.modlib.extjs
,lino.modlib.bootstrap3
.
The name of another plugin to be used as menu group.
See
get_menu_group()
.
- media_base_url = None¶
Remote URL base for media files.
- media_name = None¶
Either None (default) or a non-empty string with the name of the subdirectory of your
media
directory which is expected to contain media files for this app.None means that there this app has no media files of her own.
Best practice is to set this to the app_label. Will be ignored if
media_base_url
is nonempty.
- url_prefix = None¶
The url prefix under which this plugin should ask to install its url patterns.
- force_url_prefix = False¶
Force lino to use the url_prefix, even if it's the default ui.
- site_js_snippets = []¶
List of js snippets to be injected into the lino_*.js file.
- support_async = False¶
Whether this plugin supports usage of
lino.utils.DelayedValue
.
- renderer = None¶
The renderer used by this plugin. See Introduction to Front end Renderers.
- needed_by = None¶
If not None, then it is the Plugin instance which caused this plugin to automatically install.
- verbose_name = None¶
The verbose name of this plugin, as shown to the user. This can be a lazily translated string.
- short_name = None¶
The abbreviated name of this plugin, shown to the user in places where shortness is important, e.g. as the label of the tabs of a detail layout. This can be a lazily translated string. Defaults to
verbose_name
.
- configure(**kw)¶
Set the given parameter(s) of this Plugin instance. Any number of parameters can be specified as keyword arguments.
Raise an exception if caller specified a key that does not have a corresponding attribute.
- get_required_plugins()¶
Return a list of names of plugins needed by this plugin.
The default implementation returns
needs_plugins
.Lino will automatically install these plugins if necessary.
Note that Lino will add them before your plugin.
Note that only the app_label (not the whole plugin name) is used when testing whether a plugin is installed. IOW if a plugin says it requires a plugin "stdlib.foo" and an application already has some plugin "mylib.foo" installed, then "mylib.foo" satisfies "stdlib.foo".
- on_init()¶
This will be called when the Plugin is being instantiated (i.e. even before the
Site
instantiation has finished. Used bylino.modlib.users
to setuser_model
.
- on_plugins_loaded(site)¶
Called exactly once on each installed plugin, when the
Site
has loaded all plugins, but before callingsetup_plugins()
. All this happens before settings are ready and long before the models modules start to load.This is used for initializing default values of plugin attributes that (a) depend on other plugins but (b) should be overridable in
lino.core.site.Site.setup_plugins()
.For example
groups
uses this to set a default value to thecommentable_model
forcomments
plugin.Or
lino.modlib.checkdata
uses it to set responsible_user to "robin" when it is a demo site.
- on_site_startup(site)¶
This will be called exactly once, when models are ready.
- before_actors_discover()¶
This is called exactly once during site startup, when models are ready. Used by lino.modlib.help
- post_site_startup(site)¶
This will be called exactly once, when models are ready.
- classmethod extends_from()¶
Return the plugin from which this plugin inherits.
- classmethod get_subdir(name)¶
Get the absolute path of the named subdirectory if it exists.
- before_analyze()¶
This is called during startup, when all models modules have been imported, and before Lino starts to analyze them.
- on_ui_init(kernel)¶
This is called when the kernel is being instantiated.
- get_patterns()¶
Override this to return a list of url patterns to be added to the Site's patterns.
- get_requirements(site)¶
Return an iteration of required Python packages.
These will be installed during
install
.Plugins can use quite sophisticated logic to decide which packages they require. For example
lino_xl.lib.appypod
check whether theappy
package is already installed and does not require it then. This is to support the use case when a developer has a clone of the appy sources and uses this version. In this case we don't want to override it. Similar forlino_xl.lib.mailbox
and itsdjango_mailbox
requirement.
- get_head_lines(site, request)¶
Yield or return a list of textlines to add to the <head> of the html page.
Return the plugin (a
Plugin
instance) into the menu of which this plugin should add its menu commands.This returns self by default, unless
this plugin defines an explicit
menu_group
. In this case return the named plugin.this plugin was automatically installed because some other plugin needs it. In this case return that other plugin.
When a plugin A is automatically being installed because needed by a plugin B which is itself being installed automatically because needed by a third plugin C, then
A.get_menu_group
returns C (and not B). A case where this happens islino_welfare.modlib.pcsw
which needslino_xl.lib.coachings
which in turn needslino_xl.lib.clients
.
- setup_user_prefs(up)¶
Called when a
lino.core.userprefs.UserPrefs
get instantiated.
- get_quicklinks()¶
Return or yield a sequence of quick link descriptors to be added to the list of quick links.
A quick link descriptor is a string that identifies either an actor or a bound action.
- setup_quicklinks(tb)¶
Add quicklinks to the list of quick links.
- get_dashboard_items(user)¶
Return or yield a sequence of items to be rendered on the dashboard.
Called by
lino.core.site.Site.get_dashboard_items()
.Every item is expected to be either an instance of
lino.core.dashboard.DashboardItem
, or alino.core.actors.Actor
.Tables are shown with a limit of
lino.core.tables.AbstractTable.preview_limit
rows.
- get_detail_url(ar, actor, pk, *args, **kw)¶
Return the URL to the given database row.
This is only a relative URL. Get the fully qualified URI by prefixing
lino.core.site.Site.server_url
.The extjs frontend overrides this and returns different URIs depending on whether ar.request is set or not.