summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2015-07-03 09:03:25 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2015-09-29 16:12:39 (GMT)
commitb2e267129426a61158005b76735ce6f89da6faed (patch)
tree07fee2e413c73de12272aca2eca9583ac4932a17
parenta025f8c93db6f14aff9fdc0fd684717fd3580986 (diff)
downloadwelco-b2e267129426a61158005b76735ce6f89da6faed.zip
welco-b2e267129426a61158005b76735ce6f89da6faed.tar.gz
welco-b2e267129426a61158005b76735ce6f89da6faed.tar.bz2
general: support apps registering URLs
-rw-r--r--welco/apps.py34
-rw-r--r--welco/urls.py4
2 files changed, 38 insertions, 0 deletions
diff --git a/welco/apps.py b/welco/apps.py
new file mode 100644
index 0000000..5b19def
--- /dev/null
+++ b/welco/apps.py
@@ -0,0 +1,34 @@
+# welco - multichannel request processing
+# Copyright (C) 2015 Entr'ouvert
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from django.apps import apps
+from django.conf.urls import patterns, include, url
+
+def register_urls(urlpatterns):
+ pre_urls = []
+ post_urls = []
+ for app in apps.get_app_configs():
+ if hasattr(app, 'get_before_urls'):
+ urls = app.get_before_urls()
+ if urls:
+ pre_urls.append(url('^', include(urls)))
+ if hasattr(app, 'get_after_urls'):
+ urls = app.get_after_urls()
+ if urls:
+ post_urls.append(url('^', include(urls)))
+ pre_patterns = patterns('', *pre_urls)
+ post_patterns = patterns('', *post_urls)
+ return pre_patterns + urlpatterns + post_patterns
diff --git a/welco/urls.py b/welco/urls.py
index c13b9d3..ba7262d 100644
--- a/welco/urls.py
+++ b/welco/urls.py
@@ -17,6 +17,8 @@
from django.conf.urls import patterns, url
from django.conf import settings
+from . import apps
+
urlpatterns = patterns('',
url(r'^$', 'welco.views.home', name='home'),
)
@@ -27,3 +29,5 @@ urlpatterns += staticfiles_urlpatterns()
from django.conf.urls.static import static
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+
+urlpatterns = apps.register_urls(urlpatterns)