diff --git a/coldfront/config/urls.py b/coldfront/config/urls.py index 78d958977..86bcb0bd9 100644 --- a/coldfront/config/urls.py +++ b/coldfront/config/urls.py @@ -6,6 +6,8 @@ ColdFront URL Configuration """ +import environ +import split_settings from django.conf import settings from django.contrib import admin from django.core import serializers @@ -14,6 +16,7 @@ from django.views.generic import TemplateView import coldfront.core.portal.views as portal_views +from coldfront.config.env import ENV, PROJECT_ROOT admin.site.site_header = "ColdFront Administration" admin.site.site_title = "ColdFront Administration" @@ -60,3 +63,20 @@ def export_as_json(modeladmin, request, queryset): admin.site.add_action(export_as_json, "export_as_json") + +# Local urls overrides +local_urls = [ + # Local urls relative to coldfront.config package + "local_urls.py", + # System wide urls for production deployments + "/etc/coldfront/local_urls.py", + # Local urls relative to coldfront project root + PROJECT_ROOT("local_urls.py"), +] + +if ENV.str("COLDFRONT_URLS", default="") != "": + # Local urls from path specified via environment variable + local_urls.append(environ.Path(ENV.str("COLDFRONT_URLS"))()) + +for lu in local_urls: + split_settings.tools.include(split_settings.tools.optional(lu)) diff --git a/docs/pages/config.md b/docs/pages/config.md index 9649dbe57..53a6f0d52 100644 --- a/docs/pages/config.md +++ b/docs/pages/config.md @@ -34,6 +34,19 @@ You can also specify the path to `local_settings.py` using the COLDFRONT_CONFIG=/opt/coldfront/mysettings.py ``` +For [URL configurations](https://docs.djangoproject.com/en/dev/topics/http/urls/), you can create a python file to override ColdFront URLs: + +- `local_urls.py` relative to coldfront.config package +- `/etc/coldfront/local_urls.py` +- `local_urls.py` in the ColdFront project root + +You can also specify the path to `local_urls.py` using the +`COLDFRONT_URLS` environment variable. For example: + +``` +COLDFRONT_URLS=/opt/coldfront/myurls.py +``` + ## Simple Example Here's a very simple example demonstrating how to configure ColdFront using