general: support apps registering URLs
This commit is contained in:
parent
a025f8c93d
commit
b2e2671294
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue