mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 03:56:43 +00:00
* refactor entrypoint into helpers * Add lookup by metadata This is geared towards plugins packaged in pkgs that differ in name from their top module * Make module lookup predictable in changing pkg-envs * remove no coverage from plugin packages * ignore coverage for production loadin * refactor plugin collection - move assigment out * do not cover fs errors * test custom dir loading * test module meta fetcher * add a bit more safety * do not cover sanity checkers * add folder loading test * ignore again for cleaner diffs for now * ignore safety catch * rename test * Add test for package installs * fix docstring name * depreciate test for now * Fix for out of BASE_DIR paths * ignore catch * remove unneeded complexity * add testing for outside folders * more docstrings and simpler methods * make call simpler * refactor import * Add registry with all plugins * use full registry and make simpler request * switch path properties to methods * Add typing to plugin * Add a checker fnc for is_sample * Add sample check to admin page * Make file check a cls * more cls methods * Add setting for signature cheks Fixes #3520 * make property statements simpler * use same key in all dicts * Use module name instead of NAME Fixes #3534 * fix naming * fix name * add version checking Fixes #3478 * fix formatting and typing * also save reference to full array * do not cover as we turn on all plugins * add test for check_version * Add version e2e test * make test save * refactor out assignment * safe a db reference first * docstring * condense code a bit * rename * append logging * rename * also safe db reference to new object * docstrings, refactors, typing * fix key lookup
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Load templates for loaded plugins."""
|
|
|
|
from django.template.loaders.filesystem import Loader as FilesystemLoader
|
|
|
|
from plugin import registry
|
|
|
|
|
|
class PluginTemplateLoader(FilesystemLoader):
|
|
"""A custom template loader which allows loading of templates from installed plugins.
|
|
|
|
Each plugin can register templates simply by providing a 'templates' directory in its root path.
|
|
|
|
The convention is that each 'templates' directory contains a subdirectory with the same name as the plugin,
|
|
e.g. templates/myplugin/my_template.html
|
|
|
|
In this case, the template can then be loaded (from any plugin!) by loading "myplugin/my_template.html".
|
|
|
|
The separate plugin-named directories help keep the templates separated and uniquely identifiable.
|
|
"""
|
|
|
|
def get_dirs(self):
|
|
"""Returns all template dir paths in plugins."""
|
|
dirname = 'templates'
|
|
template_dirs = []
|
|
|
|
for plugin in registry.plugins.values():
|
|
new_path = plugin.path().joinpath(dirname)
|
|
if new_path.is_dir():
|
|
template_dirs.append(new_path)
|
|
|
|
return tuple(template_dirs)
|