Addons¶
Addons are integrations that can be installed or uninstalled against a Guillotina container. Guillotina applications can potentially provide many addons. If you have not read the section on applications, please read that before you come here.
The only way to provide add-ons is to first implement a Guillotina application.
Creating an Addon¶
Create an addon installer class in an install.py file in your Guillotina application:
from guillotina.addons import Addon
from guillotina import configure
@configure.addon(
name="myaddon",
title="My addon",
dependencies=['cms'])
class MyAddon(Addon):
@classmethod
def install(cls, container, request):
# install code
pass
@classmethod
def uninstall(cls, container, request):
# uninstall code
pass
Note
Scanning
If your service modules are not imported at run-time, you may need to provide an additional scan call to get your services noticed by guillotina.
In your application __init__.py file, you can simply provide a scan call like
from guillotina import configure
def includeme(root):
configure.scan('my.package')
Layers¶
A Layer is a marker you install with your addon, this allows your application to lookup views and adapters (override core functionality) only for the container you installed the add-on.
from guillotina.addons import Addon
from guillotina import configure
from guillotina.interfaces import ILayers
LAYER = 'guillotina_myaddon.interfaces.ILayer'
@configure.addon(
name="myaddon",
title="My addon")
class MyAddon(Addon):
@classmethod
def install(cls, container, request):
registry = task_vars.registry.get()
registry.for_interface(ILayers).active_layers |= {
LAYER
}
@classmethod
def uninstall(cls, container, request):
registry = task_vars.registry.get()
registry.for_interface(ILayers).active_layers -= {
LAYER
}
Installing an Addon into a container¶
Addons can be installed into a container using @addons
endpoint by providing
addon name as id For example:
POST /db/container/@addons HTTP/1.1
Accept: application/json
Authorization: Basic cm9vdDpyb290
Content-Type: application/json
Host: localhost:8080
{
"id": "myaddon"
}
curl -i -X POST http://localhost:8080/db/container/@addons -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"id": "myaddon"}' --user root:root
wget -S -O- http://localhost:8080/db/container/@addons --header='Accept: application/json' --header='Content-Type: application/json' --post-data='{"id": "myaddon"}' --auth-no-challenge --user=root --password=root
echo '{
"id": "myaddon"
}' | http POST http://localhost:8080/db/container/@addons Accept:application/json Content-Type:application/json -a root:root
requests.post('http://localhost:8080/db/container/@addons', headers={'Accept': 'application/json', 'Content-Type': 'application/json'}, json={'id': 'myaddon'}, auth=('root', 'root'))
HTTP/1.1 200 OK
Content-Type: application/json
{
"available": [
{
"id": "myaddon",
"title": "Guillotina DB Users"
},
{
"id": "application_name",
"title": "Your application title"
}
],
"installed": [
"dbusers",
"application_name"
]
}