From 1fa91f0ef7db7f380357c2e4a04bcbd75f9b6af9 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 12 Apr 2019 01:53:06 -0400 Subject: [PATCH] Remove development URLs from main URL file Move the development URL definitions for Rosetta and Debug toolbar to a separate URL file. Convert the single urls.py to a module to allow multiple URL files to be used. Signed-off-by: Roberto Rosario --- HISTORY.rst | 3 ++- docs/releases/3.2.rst | 9 +++++++++ mayan/settings/development.py | 24 ++++++++++++++++++------ mayan/urls/__init__.py | 3 +++ mayan/{urls.py => urls/base.py} | 20 +++----------------- mayan/urls/development.py | 26 ++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 mayan/urls/__init__.py rename mayan/{urls.py => urls/base.py} (57%) create mode 100644 mayan/urls/development.py diff --git a/HISTORY.rst b/HISTORY.rst index 172c41ac32..320badd27e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -20,7 +20,8 @@ * Split trashed document views into their own module. * Show entire sys trace when an App import exception is raised. * Remove Django suit from requirements. - +* Remove development URLs from main URL file. + 3.1.11 (2019-04-XX) =================== * Fix multiple tag selection wizard step. diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index aea8feb9d8..770b886464 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -27,6 +27,15 @@ The role permission grant and revoke permissions were removed. Instead only the role edit permission is required to grant or revoke permissions to a role. +Development +^^^^^^^^^^^ +URLs: Remove development URLs from main URL file + +Move the development URL definitions for Rosetta and Debug toolbar +to a separate URL file. Convert the single urls.py to a module to +allow multiple URL files to be used. + + Other changes ^^^^^^^^^^^^^ diff --git a/mayan/settings/development.py b/mayan/settings/development.py index 41254180d1..193270208d 100644 --- a/mayan/settings/development.py +++ b/mayan/settings/development.py @@ -10,14 +10,26 @@ CELERY_ALWAYS_EAGER = True CELERY_EAGER_PROPAGATES_EXCEPTIONS = CELERY_ALWAYS_EAGER if 'rosetta' not in INSTALLED_APPS: - INSTALLED_APPS += ( - 'rosetta', - ) + try: + import rosetta + except ImportError: + pass + else: + INSTALLED_APPS += ( + 'rosetta', + ) if 'django_extensions' not in INSTALLED_APPS: - INSTALLED_APPS += ( - 'django_extensions', - ) + try: + import django_extensions + except ImportError: + pass + else: + INSTALLED_APPS += ( + 'django_extensions', + ) + +ROOT_URLCONF = 'mayan.urls.development' TEMPLATES[0]['OPTIONS']['loaders'] = ( 'django.template.loaders.filesystem.Loader', diff --git a/mayan/urls/__init__.py b/mayan/urls/__init__.py new file mode 100644 index 0000000000..a6e360465f --- /dev/null +++ b/mayan/urls/__init__.py @@ -0,0 +1,3 @@ +from __future__ import unicode_literals + +from .base import * # NOQA diff --git a/mayan/urls.py b/mayan/urls/base.py similarity index 57% rename from mayan/urls.py rename to mayan/urls/base.py index edf0b19be5..0838a37396 100644 --- a/mayan/urls.py +++ b/mayan/urls/base.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals -from django.conf import settings -from django.conf.urls import include, url +from django.conf.urls import url from django.contrib import admin from drf_yasg.views import get_schema_view @@ -9,6 +8,8 @@ from rest_framework import permissions from mayan.apps.rest_api.schemas import openapi_info +__all__ = ('urlpatterns',) + admin.autodiscover() schema_view = get_schema_view( openapi_info, @@ -23,18 +24,3 @@ urlpatterns = [ url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=None), name='schema-swagger-ui'), url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=None), name='schema-redoc'), ] - -if settings.DEBUG: - from django.conf.urls.static import static - urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) - - if 'rosetta' in settings.INSTALLED_APPS: - urlpatterns += [ - url(r'^rosetta/', include('rosetta.urls'), name='rosetta') - ] - - if 'debug_toolbar' in settings.INSTALLED_APPS: - import debug_toolbar - urlpatterns += [ - url(r'^__debug__/', include(debug_toolbar.urls)) - ] diff --git a/mayan/urls/development.py b/mayan/urls/development.py new file mode 100644 index 0000000000..2cab9fec55 --- /dev/null +++ b/mayan/urls/development.py @@ -0,0 +1,26 @@ +from __future__ import unicode_literals + +from django.conf import settings +from django.conf.urls import include, url + +from .base import * # NOQA + +if 'rosetta' in settings.INSTALLED_APPS: + try: + import rosetta # NOQA + except ImportError: + pass + else: + urlpatterns += [ # NOQA + url(r'^rosetta/', include('rosetta.urls'), name='rosetta') + ] + +if 'debug_toolbar' in settings.INSTALLED_APPS: + try: + import debug_toolbar + except ImportError: + pass + else: + urlpatterns += [ # NOQA + url(r'^__debug__/', include(debug_toolbar.urls)) + ]