You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/10/14 15:37:34 UTC

[airavata-django-portal] branch master updated: AIRAVATA-3531 Make sure to import custom code last so that settings take affect

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/master by this push:
     new bac19ab  AIRAVATA-3531 Make sure to import custom code last so that settings take affect
bac19ab is described below

commit bac19ab232b3fe1fd25356b05c408accc35f22b4
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Oct 14 11:36:30 2021 -0400

    AIRAVATA-3531 Make sure to import custom code last so that settings take affect
    
    Specifically this makes sure that Django REST Framework settings apply to all views, both custom and imported ones.
---
 django_airavata/settings.py | 72 ++++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 34 deletions(-)

diff --git a/django_airavata/settings.py b/django_airavata/settings.py
index 3bae1dd..90f0ef4 100644
--- a/django_airavata/settings.py
+++ b/django_airavata/settings.py
@@ -85,35 +85,6 @@ INSTALLED_APPS = [
 # For example: HIDDEN_AIRAVATA_APPS = ['django_airavata_dataparsers']
 HIDDEN_AIRAVATA_APPS = []
 
-# AppConfig instances from custom Django apps
-CUSTOM_DJANGO_APPS = []
-
-# Add any custom apps installed in the virtual environment
-# Essentially this looks for the entry_points metadata in all installed Python packages. The format of the metadata in setup.py is the following:
-#
-#    setuptools.setup(
-#        ...
-#        entry_points="""
-#    [airavata.djangoapp]
-#    dynamic_djangoapp = dynamic_djangoapp.apps:DynamicDjangoAppConfig
-#    """,
-#        ...
-#    )
-#
-for entry_point in iter_entry_points(group='airavata.djangoapp'):
-    custom_app_class = entry_point.load()
-    custom_app_instance = custom_app_class(
-        entry_point.name, import_module(entry_point.module_name))
-    CUSTOM_DJANGO_APPS.append(custom_app_instance)
-    # Create path to AppConfig class (otherwise the ready() method doesn't get
-    # called)
-    INSTALLED_APPS.append("{}.{}".format(entry_point.module_name,
-                                         entry_point.attrs[0]))
-
-OUTPUT_VIEW_PROVIDERS = {}
-for entry_point in iter_entry_points(group='airavata.output_view_providers'):
-    OUTPUT_VIEW_PROVIDERS[entry_point.name] = entry_point.load()()
-
 MIDDLEWARE = [
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
@@ -625,6 +596,41 @@ WAGTAIL_CODE_BLOCK_LANGUAGES = (
 )
 
 
+# Allow all settings to be overridden by settings_local.py file
+try:
+    from django_airavata.settings_local import *  # noqa
+except ImportError:
+    pass
+
+# NOTE: custom code must be loaded last so that the above settings take effect
+# for any views, etc. defined or imported by custom code
+
+# AppConfig instances from custom Django apps
+CUSTOM_DJANGO_APPS = []
+
+# Add any custom apps installed in the virtual environment
+# Essentially this looks for the entry_points metadata in all installed Python packages. The format of the metadata in setup.py is the following:
+#
+#    setuptools.setup(
+#        ...
+#        entry_points="""
+#    [airavata.djangoapp]
+#    dynamic_djangoapp = dynamic_djangoapp.apps:DynamicDjangoAppConfig
+#    """,
+#        ...
+#    )
+#
+for entry_point in iter_entry_points(group='airavata.djangoapp'):
+    custom_app_class = entry_point.load()
+    custom_app_instance = custom_app_class(
+        entry_point.name, import_module(entry_point.module_name))
+    CUSTOM_DJANGO_APPS.append(custom_app_instance)
+    # Create path to AppConfig class (otherwise the ready() method doesn't get
+    # called)
+    INSTALLED_APPS.append("{}.{}".format(entry_point.module_name,
+                                         entry_point.attrs[0]))
+
+
 def merge_setting(default, custom_setting):
     # FIXME: only handles dict settings, doesn't handle lists
     if isinstance(custom_setting, dict):
@@ -643,8 +649,6 @@ for custom_django_app in CUSTOM_DJANGO_APPS:
         s = custom_django_app.settings
         merge_setting(WEBPACK_LOADER, getattr(s, 'WEBPACK_LOADER', {}))
 
-# Allow all settings to be overridden by settings_local.py file
-try:
-    from django_airavata.settings_local import *  # noqa
-except ImportError:
-    pass
+OUTPUT_VIEW_PROVIDERS = {}
+for entry_point in iter_entry_points(group='airavata.output_view_providers'):
+    OUTPUT_VIEW_PROVIDERS[entry_point.name] = entry_point.load()()