-
Notifications
You must be signed in to change notification settings - Fork 7
How to create plugins
UNCode, and as per the design of INGInious, provides a simple plugin system that allow to register some hooks to extend existing features, create new frontend pages and features, add new authentication methods, subproblem types, among others.
As mentioned in other pages, there are several plugins that either us or INGInious have developed to extend the functionality initially provided by INGInious. See the current developed plugins. Additionally, to avoid doing big changes on the INGInous base code, the development of UNCode is pretty much based on adding plugins; if a new utility or functionality want to be added, add a new plugin or modify one of the current developed plugins.
Thus, in a plugin you can add or call hooks
, which is actually a callback function that you indicated with the add_hook
method from HookManager
. Please note that all hooks may be called by another thread, so all actions done into a hook have to be thread-safe.
To see how to create a plugin and more information please refer to creating plugins in INGInious documentation. Additionally, bear in mind the next:
-
Update the
MANIFIEST.in
file with the new plugin, this is to allow production server to download this new plugin:recursive-include inginious/frontend/plugins/<plugin_name> *
. -
The folder
/plugins/utils
contains some utilities you can use to, for instance, add security to APIs, among other utilities you can use for your plugins. -
To add a new API or page to UNCode, use the
add_page
method in thePluginManager
. -
Use the methods from the
TemplateManager
:add_javascript
andadd_css
to add static files when a page is rendered. Be careful with this, try to load the static files only when the page that uses them is loaded, that way, the payload of UNCode is reduced and the web app might be faster in slow connections. -
In case there are some static files in the plugin, call the function
add_page
to be able to access them, for instance:plugin_manager.add_page(r'/<plugin_name>/static/(.*)', create_static_resource_page('<static_dir_path>'))
, wherecreate_static_resource_page
function is located in theutils/
folder. -
The directory hierarchy of your page should follow next structure, remember to use good and understandable names for the files:
<plugin_name>/ pages/ -> Contains new pages, and apis added via Python api/ -> API files in python. Create this folder in case there are APIs in your plugin. templates/ -> html templates for the pages __init__.py -> generally empty file but necessary page1.py -> this is just an example name for the python file that renders a page. page2.py -> this is just an example name for the python file that renders a page. Add all the files you need. ... ... static/ -> This folder must contain static files like js, css and others css/ js/ images/ json/ ... ... <file1>.py -> other file (optional) <file2>.py -> other file (optional) __init__.py -> file that initializes the plugin and its configuration. This is mandatory.
Remember to see the other plugins to understand more how they work and their structure.
A hook can be seen as dictionary in python that is updated when UNCode is started and the plugins modify these dictionaries with new settings or options that the frontend should render. That way, you can extend the functionality of UNCode from plugins, as well as adding new hooks to the system.
As mentioned, you can use some hooks that are already added or create new ones to hook on UNCode for new features. See the hooks list to understand how and when to use them. Additionally, there are some few additional hooks that are not listed there. Check inside the plugins to see if there is a hook that might work for you.
In order to reduce static files' size, static files like js and css must be minified. Check the minify plugins documentation to see how to either update the corresponding files or just run the minifier to update the min files. This is mandatory for all plugins, do not forget to do this.
UNCode - Distributed and maintained by the Universidad Nacional de Colombia, Campus Bogotá.
Visit the UNCode web page.
Visit UNCode.
- Home
- User's Documentation
- Developer's Documentation
- Deploy UNCode
- Others