Skip to content

Commit

Permalink
changed plugins url handling
Browse files Browse the repository at this point in the history
the url settings of pyscada plugins will be added to the global urls
config automaticly
  • Loading branch information
trombastic authored and clavay committed Jun 22, 2023
1 parent 1015f31 commit fd61fe6
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 56 deletions.
2 changes: 1 addition & 1 deletion docs/django_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Open the urls configuration file and add the necessary rewrite rule to the djang

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('pyscada.hmi.urls')),
url(r'^', include('pyscada.core.urls')),
]
...

Expand Down
1 change: 1 addition & 0 deletions extras/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'pyscada',
'pyscada.core',
'pyscada.hmi',
'pyscada.export',
]
Expand Down
27 changes: 0 additions & 27 deletions extras/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,6 @@
from django.urls import path, include
from django.contrib import admin

from pkgutil import iter_modules
from importlib.util import find_spec
import pyscada


def list_submodules(module):
submodules = []
for submodule in iter_modules(module.__path__):
submodules.append(submodule)
return submodules


urlpatterns = [
path('admin/', admin.site.urls),
]


lsm = list_submodules(pyscada)
for m in lsm:
try:
if m.name != 'hmi' and find_spec('pyscada.' + m.name + '.urls'):
urlpatterns += [
path('', include('pyscada.' + m.name + '.urls')),
]
except:
pass

urlpatterns += [
path('', include('pyscada.hmi.urls')),
]
20 changes: 20 additions & 0 deletions pyscada/core/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.apps import apps
import logging

logger = logging.getLogger(__name__)

urlpatterns = []

for app in apps.app_configs.values():
if app.name.startswith('pyscada.') and app.name != "pyscada.core":

try:
m = __import__(f"{app.name}.urls", fromlist=[str('a')])
urlpatterns += m.urlpatterns

except Exception as e:
logger.warning(e, exc_info=True)

1 change: 1 addition & 0 deletions tests/project_template/project_name/settings.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'pyscada',
'pyscada.core',
'pyscada.hmi',
'pyscada.export',
{{ additional_apps }}
Expand Down
29 changes: 1 addition & 28 deletions tests/project_template/project_name/urls.py-tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,6 @@ Including another URLconf
from django.urls import path, include
from django.contrib import admin

from pkgutil import iter_modules
from importlib.util import find_spec
import pyscada


def list_submodules(module):
submodules = []
for submodule in iter_modules(module.__path__):
submodules.append(submodule)
return submodules


urlpatterns = [
path('admin/', admin.site.urls),
]


lsm = list_submodules(pyscada)
for m in lsm:
try:
if m.name != 'hmi' and find_spec('pyscada.' + m.name + '.urls'):
urlpatterns += [
path('', include('pyscada.' + m.name + '.urls')),
]
except:
pass

urlpatterns += [
path('', include('pyscada.hmi.urls')),
path('', include('pyscada.core.urls')),
]
Binary file modified tests/project_template_stand-alone.zip
Binary file not shown.
Binary file modified tests/project_template_with_plugins.zip
Binary file not shown.
Binary file modified tests/project_template_with_plugins_modbus.zip
Binary file not shown.

0 comments on commit fd61fe6

Please sign in to comment.