-
Notifications
You must be signed in to change notification settings - Fork 506
Developing your own plugin
The architecture of FIR is very modular and can be extended using plugins.
A plugin is a set of files in a folder, which are defined like this:
fir
├── fir_<yourplugin> # name of your plugin
│ ├── urls.py # URLs file. This is the only required file in a plugin
│ ├── hooks.py # Hooks file. Can contain code to enrich existing functionalities of FIR (eg, add a keyword that that be used in the search bar, etc...).
│ ├── views.py # The controller (and not the view, as its name would imply). Will handle response to HTTP requests
│ ├── models.py # Should contain "objects" of your plugin, the ones that will be stored in DB. Examples of "object" are todos, incidents, comments, etc...
│ ├── migrations
│ │ └── 0001.py # Django migrations related to changes in models.py. Can be generated using 'manage.py makemigrations'
│ ├── templates
│ │ └── fir_<yourplugin>
│ │ └── sometemplate.html # May contain some Jinja2 templates
│ ├── templatetags
│ │ └── <exemple-of-tag>.py # If you are using Jinja2 tags in your templates, the code of those tags should be placed here
│ ├── admin.py # Can contain code to customize Django Admin panel
│ ├── forms.py # Can contain code relative to forms.
│ ├── fixtures
│ │ └── 001-<yourplugin>.json # May contain initial data relative to your plugin. Can be generated using 'manage.py dumpdata'
│ ├── locale
│ │ └── <country-code>
│ │ └── LC_MESSAGES
│ │ └── django.po # Localization: language file of your plugin. Can be generated using 'manage.py compilemessages -l <country-code>'
│ ├── static
│ │ └── fir_<yourplugin>
│ │ ├── vendor
│ │ │ └── <public library folder> # Location of library code: bootstrap, javascript libraries, etc...
│ │ └── <yourplugin>.js # Location of custom javascript, font or CSS files
│ ├── README.md # Readme describing what your plugin does and how to install it
│ └── requirements.txt # Python requirements of your library, if any.
In order to create your own plugin, you just need to create a folder named fir_<yourplugin>
in the root directory of FIR.
The only required file in a plugin is urls.py
. This file MUST contain two variables:
-
app_name
, which should contain the name of your plugin:app_name = "fir_myplugin"
-
urlpatterns
, which should be a list of URLs that can be called. If your plugin doesn't have any HTTP endpoint, you can set this variable to an empty list (urlpatterns = []
)
The other files are all optional, you are free to create them or not depending on your plugin's purpose.
During development of your plugin, you may want to add additional content into an existing HTML page of FIR.
This is exactly what plugin_points
are designed for!
Plugin points are a way for your plugin to embed additional content into an existing Jinja2 template of FIR.
For instance, if a plugin point named dashboard_tab
has been defined somewhere in any FIR template, then you can create a file at fir_<yourplugin>/template/fir_<yourplugin>/plugins/dashboard_tab.html
. This file will be included automatically at the location of the plugin point.
Here is how Plugin points are declared in FIR templates : {% plugin_point 'dashboard_tab' %}
. Plugin points have been defined in most existing HTML files of FIR, feel free to use them!