Skip to content

Commit

Permalink
Add very basic automatic url configuration. Fixes #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebryant committed Mar 4, 2014
1 parent 48f14be commit 177b242
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions django_autoconfig/autourlconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''This module can be set as a ROOT_URLCONF (or included into one).'''

from django.conf import settings
from django.conf.urls import include, patterns, url

urlpatterns = patterns('')

for app_name in settings.INSTALLED_APPS:
try:
urlpatterns += patterns(
'',
url(
r'^%s/' % app_name.replace("_","-"),
include("%s.urls" % app_name),
),
)
except ImportError:
pass
11 changes: 11 additions & 0 deletions django_autoconfig/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import copy
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import resolve
from django import test
from django.test.utils import override_settings

class ConfigureSettingsTestCase(test.TestCase):
'''Test the configure_settings method.'''
Expand Down Expand Up @@ -90,3 +92,12 @@ def test_relationship(self):
self.settings_dict['INSTALLED_APPS'],
['django_autoconfig.tests.app_relationship', 'app1', 'app3', 'app2'],
)

class ConfigureUrlsTestCase(test.TestCase):
'''Test the autoconfiguration of the urlconf.'''
urls = 'django_autoconfig.autourlconf'

@override_settings(INSTALLED_APPS=['django_autoconfig.tests.app_urls'])
def test_urls(self):
'''Test a simple url autoconfiguration.'''
resolve('/django-autoconfig.tests.app-urls/index/')
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions django_autoconfig/tests/app_urls/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.conf.urls import patterns, url

urlpatterns = patterns('',
url(r'^index/$', 'django_autoconfig.tests.app_urls.views.index'),
)
2 changes: 2 additions & 0 deletions django_autoconfig/tests/app_urls/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def index(_request):
return

0 comments on commit 177b242

Please sign in to comment.