Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use Django Debug Toolbar if it's installed.

  • Loading branch information...
commit 981fe4b779fc597d339d7fe9b3f58ec66c2bc171 1 parent 6be1e52
Jacob Kaplan-Moss authored
10  django_website/settings/docs.py
@@ -2,13 +2,17 @@
2 2
 
3 3
 PREPEND_WWW = False
4 4
 APPEND_SLASH = True
  5
+TEMPLATE_CONTEXT_PROCESSORS += ["django.core.context_processors.request"]
  6
+ROOT_URLCONF = 'django_website.urls.docs'
  7
+CACHE_MIDDLEWARE_KEY_PREFIX = 'djangodocs'
  8
+
  9
+_has_ddt = 'debug_toolbar' in INSTALLED_APPS
5 10
 INSTALLED_APPS = [
6 11
     'django_website.docs',
7 12
     'haystack',
8 13
 ]
9  
-TEMPLATE_CONTEXT_PROCESSORS += ["django.core.context_processors.request"]
10  
-ROOT_URLCONF = 'django_website.urls.docs'
11  
-CACHE_MIDDLEWARE_KEY_PREFIX = 'djangodocs'
  14
+if _has_ddt:
  15
+    INSTALLED_APPS.append('debug_toolbar')
12 16
 
13 17
 # Where to store the build Sphinx docs.
14 18
 if PRODUCTION:
27  django_website/settings/www.py
@@ -45,7 +45,7 @@
45 45
 
46 46
 SITE_ID = 1
47 47
 ROOT_URLCONF = 'django_website.urls.www'
48  
-INSTALLED_APPS = (
  48
+INSTALLED_APPS = [
49 49
     'django.contrib.sites',
50 50
     'django.contrib.auth',
51 51
     'django.contrib.admin',
@@ -61,22 +61,24 @@
61 61
     'django_website.docs',
62 62
     'registration',
63 63
     'south',
64  
-)
  64
+]
65 65
 
66 66
 CACHE_MIDDLEWARE_SECONDS = 60 * 5 # 5 minutes
67 67
 CACHE_MIDDLEWARE_KEY_PREFIX = 'djangoproject'
68 68
 CACHE_MIDDLEWARE_GZIP = True
69 69
 CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
70 70
 
71  
-MIDDLEWARE_CLASSES = (
72  
-    'django.middleware.cache.UpdateCacheMiddleware',
  71
+MIDDLEWARE_CLASSES = [
73 72
     'django.contrib.sessions.middleware.SessionMiddleware',
74 73
     'django.contrib.auth.middleware.AuthenticationMiddleware',
75 74
     'django.middleware.common.CommonMiddleware',
76 75
     'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
77 76
     'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
78  
-    'django.middleware.cache.FetchFromCacheMiddleware',
79  
-)
  77
+]
  78
+if PRODUCTION:
  79
+    MIDDLEWARE_CLASSES.insert(0, 'django.middleware.cache.UpdateCacheMiddleware')
  80
+    MIDDLEWARE_CLASSES.append('django.middleware.cache.FetchFromCacheMiddleware')
  81
+
80 82
 TEMPLATE_LOADERS = (
81 83
     'django.template.loaders.filesystem.load_template_source',
82 84
     'django.template.loaders.app_directories.load_template_source',
@@ -103,3 +105,16 @@
103 105
 
104 106
 # XXX What's this for?
105 107
 DJANGO_SVN_ROOT = "http://code.djangoproject.com/svn/django/"
  108
+
  109
+# If django-debug-toolbar is installed enable it.
  110
+if not PRODUCTION:
  111
+    try:
  112
+        import debug_toolbar
  113
+    except ImportError:
  114
+        pass
  115
+    else:
  116
+        # Insert DDT after the common middleware
  117
+        common_index = MIDDLEWARE_CLASSES.index('django.middleware.common.CommonMiddleware')
  118
+        MIDDLEWARE_CLASSES.insert(common_index+1, 'debug_toolbar.middleware.DebugToolbarMiddleware')
  119
+        INTERNAL_IPS = ['127.0.0.1']
  120
+        INSTALLED_APPS.append('debug_toolbar')

0 notes on commit 981fe4b

Please sign in to comment.
Something went wrong with that request. Please try again.