mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
refactor plugin urls into plugin dir
This commit is contained in:
parent
a95b298c62
commit
000adb357d
@ -871,8 +871,6 @@ MAINTENANCE_MODE_RETRY_AFTER = 60
|
||||
|
||||
|
||||
# Plugins
|
||||
PLUGIN_URL = 'plugin'
|
||||
|
||||
PLUGIN_DIRS = ['plugin.builtin', ]
|
||||
|
||||
if not TESTING:
|
||||
|
@ -18,6 +18,7 @@ from part.urls import part_urls
|
||||
from stock.urls import stock_urls
|
||||
from build.urls import build_urls
|
||||
from order.urls import order_urls
|
||||
from plugin.urls import plugin_urls, PLUGIN_BASE
|
||||
|
||||
from barcodes.api import barcode_api_urls
|
||||
from common.api import common_api_urls
|
||||
@ -124,25 +125,6 @@ translated_javascript_urls = [
|
||||
url(r'^table_filters.js', DynamicJsView.as_view(template_name='js/translated/table_filters.js'), name='table_filters.js'),
|
||||
]
|
||||
|
||||
# Integration plugin urls
|
||||
integration_urls = []
|
||||
|
||||
|
||||
def get_integration_urls():
|
||||
urls = []
|
||||
for plugin in settings.INTEGRATION_PLUGINS.values():
|
||||
if plugin.mixin_enabled('urls'):
|
||||
urls.append(plugin.urlpatterns)
|
||||
return urls
|
||||
|
||||
|
||||
try:
|
||||
if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_URL'):
|
||||
integration_urls = get_integration_urls()
|
||||
except (OperationalError, ProgrammingError):
|
||||
# Exception if the database has not been migrated yet
|
||||
pass
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^part/', include(part_urls)),
|
||||
url(r'^manufacturer-part/', include(manufacturer_part_urls)),
|
||||
@ -181,8 +163,9 @@ urlpatterns = [
|
||||
url(r'^api/', include(apipatterns)),
|
||||
url(r'^api-doc/', include_docs_urls(title='InvenTree API')),
|
||||
|
||||
# plugins
|
||||
url(f'^{settings.PLUGIN_URL}/', include((integration_urls, 'plugin'))),
|
||||
# plugin urls
|
||||
url(r'^plugins/', include(plugin_urls)),
|
||||
url(f'^{PLUGIN_BASE}/', include(([], 'plugin'))), # on startup we do not have any plugins enabled
|
||||
|
||||
url(r'^markdownx/', include('markdownx.urls')),
|
||||
|
||||
|
@ -25,6 +25,7 @@ from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode
|
||||
from plugin import plugins as inventree_plugins
|
||||
from plugin.integration import IntegrationPluginBase
|
||||
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
@ -315,7 +316,8 @@ class PluginAppConfig(AppConfig):
|
||||
self._update_urls()
|
||||
|
||||
def _update_urls(self):
|
||||
from InvenTree.urls import urlpatterns, get_integration_urls
|
||||
from InvenTree.urls import urlpatterns
|
||||
from plugin.urls import PLUGIN_BASE, get_integration_urls
|
||||
|
||||
for index, a in enumerate(urlpatterns):
|
||||
if hasattr(a, 'app_name'):
|
||||
@ -323,7 +325,7 @@ class PluginAppConfig(AppConfig):
|
||||
urlpatterns[index] = url(r'^admin/', admin.site.urls, name='inventree-admin')
|
||||
elif a.app_name == 'plugin':
|
||||
integ_urls = get_integration_urls()
|
||||
urlpatterns[index] = url(f'^{settings.PLUGIN_URL}/', include((integ_urls, 'plugin')))
|
||||
urlpatterns[index] = url(f'^{PLUGIN_BASE}/', include((integ_urls, 'plugin')))
|
||||
clear_url_caches()
|
||||
|
||||
def _reload_apps(self, populate: bool = False):
|
||||
|
@ -2,6 +2,8 @@
|
||||
from django.conf import settings
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from plugin.urls import PLUGIN_BASE
|
||||
|
||||
|
||||
class GlobalSettingsMixin:
|
||||
"""Mixin that enables global settings for the plugin"""
|
||||
@ -77,7 +79,7 @@ class UrlsMixin:
|
||||
"""
|
||||
returns base url for this plugin
|
||||
"""
|
||||
return f'{settings.PLUGIN_URL}/{self.slug}/'
|
||||
return f'{PLUGIN_BASE}/{self.slug}/'
|
||||
|
||||
@property
|
||||
def internal_name(self):
|
||||
|
@ -9,6 +9,7 @@ from datetime import datetime
|
||||
|
||||
from plugin.integration import IntegrationPluginBase
|
||||
from plugin.builtin.integration.mixins import AppMixin, GlobalSettingsMixin, UrlsMixin, NavigationMixin
|
||||
from plugin.urls import PLUGIN_BASE
|
||||
|
||||
|
||||
class BaseMixinDefinition:
|
||||
@ -82,7 +83,7 @@ class UrlsMixinTest(BaseMixinDefinition, TestCase):
|
||||
plg_name = self.mixin.plugin_name()
|
||||
|
||||
# base_url
|
||||
target_url = f'{settings.PLUGIN_URL}/{plg_name}/'
|
||||
target_url = f'{PLUGIN_BASE}/{plg_name}/'
|
||||
self.assertEqual(self.mixin.base_url, target_url)
|
||||
|
||||
# urlpattern
|
||||
|
21
InvenTree/plugin/urls.py
Normal file
21
InvenTree/plugin/urls.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""
|
||||
URL lookup for plugin app
|
||||
"""
|
||||
|
||||
from django.conf.urls import url, include
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
PLUGIN_BASE = 'plugin' # Constant for links
|
||||
|
||||
|
||||
def get_integration_urls():
|
||||
urls = []
|
||||
for plugin in settings.INTEGRATION_PLUGINS.values():
|
||||
if plugin.mixin_enabled('urls'):
|
||||
urls.append(plugin.urlpatterns)
|
||||
return urls
|
||||
|
||||
|
||||
plugin_urls = [
|
||||
]
|
Loading…
Reference in New Issue
Block a user