mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Plugin static files (#7763)
* add plugin_static template tag * don't load plugins for collectstatic anymore as they are now collected seperatly * fix clear plugin staic files bug with nested folder path
This commit is contained in:
parent
e3ccd3a682
commit
648cb12b5c
@ -115,6 +115,7 @@ def canAppAccessDatabase(
|
||||
'makemessages',
|
||||
'compilemessages',
|
||||
'spectactular',
|
||||
'collectstatic',
|
||||
]
|
||||
|
||||
if not allow_shell:
|
||||
@ -125,7 +126,7 @@ def canAppAccessDatabase(
|
||||
excluded_commands.append('test')
|
||||
|
||||
if not allow_plugins:
|
||||
excluded_commands.extend(['collectstatic', 'collectplugins'])
|
||||
excluded_commands.extend(['collectplugins'])
|
||||
|
||||
for cmd in excluded_commands:
|
||||
if cmd in sys.argv:
|
||||
|
@ -1,7 +1,6 @@
|
||||
"""Static files management for InvenTree plugins."""
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
|
||||
@ -23,12 +22,15 @@ def clear_static_dir(path, recursive=True):
|
||||
dirs, files = staticfiles_storage.listdir(path)
|
||||
|
||||
for f in files:
|
||||
staticfiles_storage.delete(f'{path}/{f}')
|
||||
staticfiles_storage.delete(f'{path}{f}')
|
||||
|
||||
if recursive:
|
||||
for d in dirs:
|
||||
clear_static_dir(f'{path}/{d}', recursive=True)
|
||||
staticfiles_storage.delete(d)
|
||||
clear_static_dir(f'{path}{d}/', recursive=True)
|
||||
staticfiles_storage.delete(f'{path}{d}')
|
||||
|
||||
# Finally, delete the directory itself to remove orphan folders when uninstalling a plugin
|
||||
staticfiles_storage.delete(path)
|
||||
|
||||
|
||||
def collect_plugins_static_files():
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
from django import template
|
||||
from django.conf import settings as djangosettings
|
||||
from django.templatetags.static import static
|
||||
from django.urls import reverse
|
||||
|
||||
from common.notifications import storage
|
||||
@ -96,3 +97,27 @@ def notification_list(context, *args, **kwargs):
|
||||
}
|
||||
for a in storage.liste
|
||||
]
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def plugin_static(context, file: str, **kwargs):
|
||||
"""Return the URL for a static file within a plugin.
|
||||
|
||||
Arguments:
|
||||
file: The path to the file within the plugin static directory
|
||||
|
||||
Keyword Arguments:
|
||||
plugin: The plugin slug (optional, will be inferred from the context if not provided)
|
||||
|
||||
"""
|
||||
plugin = context.get('plugin', None)
|
||||
|
||||
if plugin:
|
||||
plugin = plugin.slug
|
||||
else:
|
||||
plugin = kwargs.get('plugin', None)
|
||||
|
||||
if not plugin:
|
||||
return file
|
||||
|
||||
return static(f'plugins/{plugin}/{file}')
|
||||
|
Loading…
x
Reference in New Issue
Block a user