From 21a787f449002883ceff57a3b382d13f2309545d Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Fri, 8 Nov 2024 11:53:05 +0100 Subject: [PATCH] Implement DJP: Django Plugins. --- docs/references/plugins.md | 9 +++++++++ hypha/settings/base.py | 4 ++++ hypha/urls.py | 3 +++ requirements.txt | 1 + 4 files changed, 17 insertions(+) create mode 100644 docs/references/plugins.md diff --git a/docs/references/plugins.md b/docs/references/plugins.md new file mode 100644 index 0000000000..b24e04349b --- /dev/null +++ b/docs/references/plugins.md @@ -0,0 +1,9 @@ +Hypha implements DJP: Django Plugins. A plugin system for Django. + +See https://djp.readthedocs.io/ for more information. + +## Some tips + +You can set the `DJP_PLUGINS_DIR` environment variable to point to a directory which contains *.py files implementing plugins. Good for development and when you do not want to publish the plugin on PyPI. + +Since DJP allow a plugin to override any setting you can tell Hypha to look for templates in a directory inside your plugin. This allows the plugin to override any template in Hypha. diff --git a/hypha/settings/base.py b/hypha/settings/base.py index 5e438b945b..37efac3224 100644 --- a/hypha/settings/base.py +++ b/hypha/settings/base.py @@ -5,6 +5,7 @@ import os import dj_database_url +import djp from environs import Env from .django import * # noqa @@ -623,3 +624,6 @@ debug=SENTRY_DEBUG, integrations=[DjangoIntegration()], ) + +# Load settings from any djp plugins. +djp.settings(globals()) diff --git a/hypha/urls.py b/hypha/urls.py index 3d86d9cfc7..7331b1bc8d 100644 --- a/hypha/urls.py +++ b/hypha/urls.py @@ -1,3 +1,4 @@ +import djp from django.conf import settings from django.contrib import admin from django.urls import include, path, re_path @@ -104,6 +105,8 @@ path("", include(wagtail_urls)), ] +# Load urls from any djp plugins. +urlpatterns += djp.urlpatterns() if settings.DEBUG: import debug_toolbar diff --git a/requirements.txt b/requirements.txt index 6380c70f60..4fee662c6c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,6 +35,7 @@ django-web-components==0.2.0 django==4.2.16 djangorestframework-api-key==3.0.0 djangorestframework==3.15.2 +djp==0.3.1 drf-nested-routers==0.93.5 environs==11.0.0 gunicorn==22.0.0