Skip to content

Commit

Permalink
Merge pull request #35 from benbacardi/exclude-urls
Browse files Browse the repository at this point in the history
Added setting to exclude URLs from autourlconf
  • Loading branch information
mikebryant authored Dec 1, 2016
2 parents b95b67b + ae7fb29 commit 563e0bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions django_autoconfig/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#: Extra URLs for autourlconf
AUTOCONFIG_EXTRA_URLS = getattr(settings, 'AUTOCONFIG_EXTRA_URLS', ())

#: A list/tuple of apps to exclude from the autourlconf
AUTOCONFIG_URLCONF_EXCLUDE_APPS = getattr(settings, 'AUTOCONFIG_URLCONF_EXCLUDE_APPS', ())

#: A view name (suitable for reverse()) that the base / will redirect to.
AUTOCONFIG_INDEX_VIEW = getattr(settings, 'AUTOCONFIG_INDEX_VIEW', None)

Expand Down
7 changes: 5 additions & 2 deletions django_autoconfig/autourlconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from django.conf import settings

from .app_settings import AUTOCONFIG_EXTRA_URLS, AUTOCONFIG_INDEX_VIEW, AUTOCONFIG_URL_PREFIXES
from .app_settings import AUTOCONFIG_EXTRA_URLS, AUTOCONFIG_INDEX_VIEW, AUTOCONFIG_URL_PREFIXES, AUTOCONFIG_URLCONF_EXCLUDE_APPS

from .autoconfig import configure_urls

apps = [app for app in settings.INSTALLED_APPS if app not in AUTOCONFIG_URLCONF_EXCLUDE_APPS]

urlpatterns = configure_urls( # pylint: disable=C0103
list(settings.INSTALLED_APPS) + list(AUTOCONFIG_EXTRA_URLS),
apps + list(AUTOCONFIG_EXTRA_URLS),
index_view=AUTOCONFIG_INDEX_VIEW,
prefixes=AUTOCONFIG_URL_PREFIXES,
)
Expand Down
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ This can be used as follows::

ROOT_URLCONF = 'django_autoconfig.autourlconf'

This will result in each application being included under it's import path, e.g. ``INSTALLED_APPs = ['app']`` will result in ``/app/`` being mapped to ``app.urls``
This will result in each application being included under it's import path, e.g. ``INSTALLED_APPS = ['app']`` will result in ``/app/`` being mapped to ``app.urls``

In addition you may define ``AUTOCONFIG_INDEX_VIEW`` in your settings file, this may be anything that can be passed to ``reverse()``. This will create a redirect at the top of the url conf (``/``)

If you don't want a particular app to be included in the automatic urlconf, you can include the setting ``AUTOCONFIG_URLCONF_EXCLUDE_APPS``, which should be a list of app names that should not be included. These apps will be skipped when the automatic urlconf is generated.

Inconsistent States
-------------------

Expand Down

0 comments on commit 563e0bb

Please sign in to comment.