Update static files on config change

This commit is contained in:
Oliver Walters 2024-08-13 07:33:46 +00:00
parent 69057d98f7
commit 163ecab44b
3 changed files with 14 additions and 1 deletions

View File

@ -337,7 +337,7 @@ def uninstall_plugin(cfg: plugin.models.PluginConfig, user=None, delete_config=T
cfg.delete()
# Remove static files associated with this plugin
plugin.staticfiles.clear_static_dir(f'plugins/{cfg.key}/', recursive=True)
plugin.staticfiles.clear_plugin_static_files(cfg.key)
# Reload the plugin registry
registry.reload_plugins(full_reload=True, force_reload=True, collect=True)

View File

@ -154,6 +154,14 @@ class PluginConfig(InvenTree.models.MetadataMixin, models.Model):
warnings.warn('A reload was triggered', stacklevel=2)
registry.reload_plugins()
# Update static files for this plugin
if self.active:
plugin.staticfiles.copy_plugin_static_files(
self.key, check_reload=False
)
else:
plugin.staticfiles.clear_plugin_static_files(self.key)
@admin.display(boolean=True, description=_('Installed'))
def is_installed(self) -> bool:
"""Simple check to determine if this plugin is installed.

View File

@ -115,3 +115,8 @@ def copy_plugin_static_files(slug, check_reload=True):
copied += 1
logger.info("Copied %s static files for plugin '%s'.", copied, slug)
def clear_plugin_static_files(slug: str, recursive: bool = True):
"""Clear static files for the specified plugin."""
clear_static_dir(f'plugins/{slug}/', recursive=recursive)