mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	enable templates for plugins
This commit is contained in:
		@@ -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',
 | 
			
		||||
                ])
 | 
			
		||||
            ],
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
@@ -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"""
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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)
 | 
			
		||||
		Reference in New Issue
	
	Block a user