mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 05:26:45 +00:00
enable templates for plugins
This commit is contained in:
parent
04eee50653
commit
9695d50bf4
@ -320,7 +320,6 @@ TEMPLATES = [
|
|||||||
os.path.join(MEDIA_ROOT, 'report'),
|
os.path.join(MEDIA_ROOT, 'report'),
|
||||||
os.path.join(MEDIA_ROOT, 'label'),
|
os.path.join(MEDIA_ROOT, 'label'),
|
||||||
],
|
],
|
||||||
'APP_DIRS': True,
|
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
'django.template.context_processors.debug',
|
'django.template.context_processors.debug',
|
||||||
@ -333,6 +332,13 @@ TEMPLATES = [
|
|||||||
'InvenTree.context.status_codes',
|
'InvenTree.context.status_codes',
|
||||||
'InvenTree.context.user_roles',
|
'InvenTree.context.user_roles',
|
||||||
],
|
],
|
||||||
|
'loaders': [(
|
||||||
|
'django.template.loaders.cached.Loader', [
|
||||||
|
'django.template.loaders.app_directories.Loader',
|
||||||
|
'django.template.loaders.filesystem.Loader',
|
||||||
|
'plugins.loader.PluginTemplateLoader',
|
||||||
|
])
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -214,6 +214,8 @@ class IntegrationPlugin(MixinBase, plugin.InvenTreePlugin):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.add_mixin('base')
|
self.add_mixin('base')
|
||||||
|
self.def_path = inspect.getfile(self.__class__)
|
||||||
|
self.path = os.path.dirname(self.def_path)
|
||||||
|
|
||||||
self.set_sign_values()
|
self.set_sign_values()
|
||||||
|
|
||||||
@ -230,8 +232,7 @@ class IntegrationPlugin(MixinBase, plugin.InvenTreePlugin):
|
|||||||
|
|
||||||
def get_plugin_commit(self):
|
def get_plugin_commit(self):
|
||||||
"""get last git commit for plugin"""
|
"""get last git commit for plugin"""
|
||||||
path = inspect.getfile(self.__class__)
|
return get_git_log(self.def_path)
|
||||||
return get_git_log(path)
|
|
||||||
|
|
||||||
def set_sign_values(self):
|
def set_sign_values(self):
|
||||||
"""add the last commit of the plugins class file into plugins context"""
|
"""add the last commit of the plugins class file into plugins context"""
|
||||||
|
19
InvenTree/plugins/loader.py
Normal file
19
InvenTree/plugins/loader.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user