2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00

enable templates for plugins

This commit is contained in:
Matthias
2021-10-03 13:39:11 +02:00
parent 04eee50653
commit 9695d50bf4
3 changed files with 29 additions and 3 deletions

View File

@ -214,6 +214,8 @@ class IntegrationPlugin(MixinBase, plugin.InvenTreePlugin):
def __init__(self):
super().__init__()
self.add_mixin('base')
self.def_path = inspect.getfile(self.__class__)
self.path = os.path.dirname(self.def_path)
self.set_sign_values()
@ -230,8 +232,7 @@ class IntegrationPlugin(MixinBase, plugin.InvenTreePlugin):
def get_plugin_commit(self):
"""get last git commit for plugin"""
path = inspect.getfile(self.__class__)
return get_git_log(path)
return get_git_log(self.def_path)
def set_sign_values(self):
"""add the last commit of the plugins class file into plugins context"""

View File

@ -0,0 +1,19 @@
"""
load templates for loaded plugins
"""
from django.conf import settings
from django.template.loaders.filesystem import Loader as FilesystemLoader
from pathlib import Path
class PluginTemplateLoader(FilesystemLoader):
def get_dirs(self):
dirname = 'templates'
template_dirs = []
for plugin in settings.INTEGRATION_PLUGINS:
new_path = Path(plugin.path) / dirname
if Path(new_path).is_dir():
template_dirs.append(new_path)
return tuple(template_dirs)