2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 03:56:43 +00:00
Lukas 577185cd98
Fix urls loading for plugin testing (#6383)
* Fix urls for plugin testing

* Fix pre-commit

* Only load urls if testing setup is true
2024-02-02 06:16:47 +11:00

28 lines
789 B
Python

"""URL lookup for plugin app."""
from django.conf import settings
from django.urls import include, re_path
PLUGIN_BASE = 'plugin' # Constant for links
def get_plugin_urls():
"""Returns a urlpattern that can be integrated into the global urls."""
from common.models import InvenTreeSetting
from plugin import registry
urls = []
# Only allow custom routing if the setting is enabled
if (
InvenTreeSetting.get_setting(
'ENABLE_PLUGINS_URL', False, create=False, cache=False
)
or settings.PLUGIN_TESTING_SETUP
):
for plugin in registry.plugins.values():
if plugin.mixin_enabled('urls'):
urls.append(plugin.urlpatterns)
return re_path(f'^{PLUGIN_BASE}/', include((urls, 'plugin')))