diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index dcbb4be052..49e2a38d1e 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -320,7 +320,6 @@ TEMPLATES = [ os.path.join(MEDIA_ROOT, 'report'), os.path.join(MEDIA_ROOT, 'label'), ], - 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', @@ -333,6 +332,13 @@ TEMPLATES = [ 'InvenTree.context.status_codes', 'InvenTree.context.user_roles', ], + 'loaders': [( + 'django.template.loaders.cached.Loader', [ + 'django.template.loaders.app_directories.Loader', + 'django.template.loaders.filesystem.Loader', + 'plugins.loader.PluginTemplateLoader', + ]) + ], }, }, ] diff --git a/InvenTree/plugins/integration.py b/InvenTree/plugins/integration.py index 5e926e7ff1..194c974939 100644 --- a/InvenTree/plugins/integration.py +++ b/InvenTree/plugins/integration.py @@ -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""" diff --git a/InvenTree/plugins/loader.py b/InvenTree/plugins/loader.py new file mode 100644 index 0000000000..82680d534d --- /dev/null +++ b/InvenTree/plugins/loader.py @@ -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)