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 2022/11/01 16:28:56 UTC

[airavata-django-portal-commons] branch main updated (dc40a2f -> 2da373b)

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

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


    from dc40a2f  initial commit - this code comes from airavata-django-portal
     new 15eed96  Simplify merging of settings
     new 2da373b  Updated README with getting started and pointer to documentation

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md                                          | 63 +++++++++++++++++++++-
 .../dynamic_apps/__init__.py                       | 21 ++++----
 2 files changed, 74 insertions(+), 10 deletions(-)


[airavata-django-portal-commons] 02/02: Updated README with getting started and pointer to documentation

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2da373b2a4f78c1da9783ec1802e276cfc49beb0
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Nov 1 12:28:47 2022 -0400

    Updated README with getting started and pointer to documentation
---
 README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 48cd3b0..0cbda17 100644
--- a/README.md
+++ b/README.md
@@ -4,4 +4,65 @@ Utilities for working with dynamically loaded Django apps.
 
 ## Getting Started
 
-TODO
+Install this package with pip
+
+```
+pip install airavata-django-portal-commons
+```
+
+### Dynamically loaded Django apps
+
+1. At the end of your Django server's settings.py file add
+
+```python
+import sys
+from airavata_django_portal_commons import dynamic_apps
+
+# Add any dynamic apps installed in the virtual environment
+dynamic_apps.load(INSTALLED_APPS)
+
+# (Optional) merge WEBPACK_LOADER settings from custom Django apps
+settings_module = sys.modules[__name__]
+dynamic_apps.merge_settings(settings_module)
+```
+
+2. Also add
+   `'airavata_django_portal_commons.dynamic_apps.context_processors.custom_app_registry'`
+   to the context_processors list:
+
+```python
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': ...
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                ...
+                'airavata_django_portal_commons.dynamic_apps.context_processors.custom_app_registry',
+            ],
+        },
+    },
+]
+```
+
+3. In your urls.py file add the following to the urlpatterns
+
+```python
+urlpatterns = [
+    # ...
+    path('', include('airavata_django_portal_commons.dynamic_apps.urls')),
+]
+```
+
+## Creating a dynamically loaded Django app
+
+See
+https://apache-airavata-django-portal.readthedocs.io/en/latest/dev/custom_django_app/
+for the latest information.
+
+Note that by default the
+[cookiecutter template](https://github.com/machristie/cookiecutter-airavata-django-app)
+registers Django apps under the entry_point group name of `airavata.djangoapp`,
+but you can change this. Just make sure that when you call `dynamic_apps.load`
+that you pass as the second argument the name of the entry_point group.


[airavata-django-portal-commons] 01/02: Simplify merging of settings

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 15eed96dd874bbb25c7948388f8bbb62df5836af
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Nov 1 12:28:23 2022 -0400

    Simplify merging of settings
---
 .../dynamic_apps/__init__.py                        | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/airavata_django_portal_commons/dynamic_apps/__init__.py b/airavata_django_portal_commons/dynamic_apps/__init__.py
index 2c8692e..1e535d4 100644
--- a/airavata_django_portal_commons/dynamic_apps/__init__.py
+++ b/airavata_django_portal_commons/dynamic_apps/__init__.py
@@ -37,16 +37,19 @@ def merge_setting_dict(default, custom_setting):
                 )
 
 
-def merge_setting(settings_module, setting_name):
-    # Merge settings from custom Django apps
-    # FIXME: only handles WEBPACK_LOADER additions
+def merge_settings(settings_module):
     for custom_django_app in CUSTOM_DJANGO_APPS:
-        if hasattr(custom_django_app, "settings"):
+        if hasattr(custom_django_app, "merge_settings"):
+            custom_django_app.merge_settings(settings_module)
+        elif hasattr(custom_django_app, "settings"):
+            # This approach is deprecated, use 'merge_settings' instead
+            # Merge settings from custom Django apps
+            # NOTE: only handles WEBPACK_LOADER additions
+            print(
+                f"{type(custom_django_app).__name__}.settings attr is deprecated, use merge_settings instead"
+            )
             s = custom_django_app.settings
             merge_setting_dict(
-                getattr(settings_module, setting_name), getattr(s, setting_name, {})
+                getattr(settings_module, "WEBPACK_LOADER"),
+                getattr(s, "WEBPACK_LOADER", {}),
             )
-
-
-def merge_webpack_loader(settings_module):
-    merge_setting(settings_module, "WEBPACK_LOADER")