Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Converted django.views.admin.doc to use load_and_render

git-svn-id: http://code.djangoproject.com/svn/django/trunk@660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4175aec30fbc32622de25f3f8b65bc25842d1f89 1 parent aec3e32
Adrian Holovaty authored September 22, 2005

Showing 1 changed file with 24 additions and 55 deletions. Show diff stats Hide diff stats

  1. 79  django/views/admin/doc.py
79  django/views/admin/doc.py
@@ -2,9 +2,8 @@
2 2
 from django import templatetags
3 3
 from django.conf import settings
4 4
 from django.models.core import sites
5  
-from django.core.extensions import DjangoContext as Context
  5
+from django.core.extensions import DjangoContext, load_and_render
6 6
 from django.core.exceptions import Http404, ViewDoesNotExist
7  
-from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
8 7
 from django.core import template, template_loader, defaulttags, defaultfilters, urlresolvers
9 8
 try:
10 9
     from django.parts.admin import doc
@@ -18,17 +17,12 @@
18 17
 def doc_index(request):
19 18
     if not doc:
20 19
         return missing_docutils_page(request)
21  
-
22  
-    t = template_loader.get_template('doc/index')
23  
-    c = Context(request, {})
24  
-    return HttpResponse(t.render(c))
  20
+    return load_and_render('doc/index', context_instance=DjangoContext(request))
25 21
 
26 22
 def bookmarklets(request):
27  
-    t = template_loader.get_template('doc/bookmarklets')
28  
-    c = Context(request, {
  23
+    return load_and_render('doc/bookmarklets', {
29 24
         'admin_url' : "%s://%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', request.META['HTTP_HOST']),
30  
-    })
31  
-    return HttpResponse(t.render(c))
  25
+    }, context_instance=DjangoContext(request))
32 26
 
33 27
 def template_tag_index(request):
34 28
     import sys
@@ -65,11 +59,7 @@ def template_tag_index(request):
65 59
     # Fix registered_tags
66 60
     template.registered_tags, template.registered_filters = saved_tagset
67 61
 
68  
-    t = template_loader.get_template('doc/template_tag_index')
69  
-    c = Context(request, {
70  
-        'tags' : tags,
71  
-    })
72  
-    return HttpResponse(t.render(c))
  62
+    return load_and_render('doc/template_tag_index', {'tags': tags}, context_instance=DjangoContext(request))
73 63
 
74 64
 def template_filter_index(request):
75 65
     if not doc:
@@ -101,11 +91,7 @@ def template_filter_index(request):
101 91
 
102 92
     template.registered_tags, template.registered_filters = saved_tagset
103 93
 
104  
-    t = template_loader.get_template('doc/template_filter_index')
105  
-    c = Context(request, {
106  
-        'filters' : filters,
107  
-    })
108  
-    return HttpResponse(t.render(c))
  94
+    return load_and_render('doc/template_filter_index', {'filters': filters}, context_instance=DjangoContext(request))
109 95
 
110 96
 def view_index(request):
111 97
     if not doc:
@@ -124,11 +110,7 @@ def view_index(request):
124 110
                 'site'   : sites.get_object(pk=settings_mod.SITE_ID),
125 111
                 'url'    : simplify_regex(regex),
126 112
             })
127  
-    t = template_loader.get_template('doc/view_index')
128  
-    c = Context(request, {
129  
-        'views' : views,
130  
-    })
131  
-    return HttpResponse(t.render(c))
  113
+    return load_and_render('doc/view_index', {'views': views}, context_instance=DjangoContext(request))
132 114
 
133 115
 def view_detail(request, view):
134 116
     if not doc:
@@ -146,14 +128,12 @@ def view_detail(request, view):
146 128
         body = doc.parse_rst(body, 'view', 'view:' + view)
147 129
     for key in metadata:
148 130
         metadata[key] = doc.parse_rst(metadata[key], 'model', 'view:' + view)
149  
-    t = template_loader.get_template('doc/view_detail')
150  
-    c = Context(request, {
151  
-        'name'      : view,
152  
-        'summary'   : title,
153  
-        'body'      : body,
154  
-        'meta'      : metadata,
155  
-    })
156  
-    return HttpResponse(t.render(c))
  131
+    return load_and_render('doc/view_detail', {
  132
+        'name': view,
  133
+        'summary': title,
  134
+        'body': body,
  135
+        'meta': metadata,
  136
+    }, context_instance=DjangoContext(request))
157 137
 
158 138
 def model_index(request):
159 139
     if not doc:
@@ -168,11 +148,7 @@ def model_index(request):
168 148
                 'module' : opts.app_label,
169 149
                 'class'  : opts.module_name,
170 150
             })
171  
-    t = template_loader.get_template('doc/model_index')
172  
-    c = Context(request, {
173  
-        'models' : models,
174  
-    })
175  
-    return HttpResponse(t.render(c))
  151
+    return load_and_render('doc/model_index', {'models': models}, context_instance=DjangoContext(request))
176 152
 
177 153
 def model_detail(request, model):
178 154
     if not doc:
@@ -209,14 +185,11 @@ def model_detail(request, model):
209 185
                 'data_type' : get_return_data_type(func_name),
210 186
                 'verbose'   : verbose,
211 187
             })
212  
-
213  
-    t = template_loader.get_template('doc/model_detail')
214  
-    c = Context(request, {
215  
-        'name'    : '%s.%s' % (opts.app_label, opts.module_name),
216  
-        'summary' : "Fields on %s objects" % opts.verbose_name,
217  
-        'fields'  : fields,
218  
-    })
219  
-    return HttpResponse(t.render(c))
  188
+    return load_and_render('doc/model_detail', {
  189
+        'name': '%s.%s' % (opts.app_label, opts.module_name),
  190
+        'summary': "Fields on %s objects" % opts.verbose_name,
  191
+        'fields': fields,
  192
+    }, context_instance=DjangoContext(request))
220 193
 
221 194
 def template_detail(request, template):
222 195
     templates = []
@@ -232,12 +205,10 @@ def template_detail(request, template):
232 205
                 'site'      : sites.get_object(pk=settings_mod.SITE_ID),
233 206
                 'order'     : list(settings_mod.TEMPLATE_DIRS).index(dir),
234 207
             })
235  
-    t = template_loader.get_template('doc/template_detail')
236  
-    c = Context(request, {
237  
-        'name'      : template,
238  
-        'templates' : templates,
239  
-    })
240  
-    return HttpResponse(t.render(c))
  208
+    return load_and_render('doc/template_detail', {
  209
+        'name': template,
  210
+        'templates': templates,
  211
+    }, context_instance=DjangoContext(request))
241 212
 
242 213
 ####################
243 214
 # Helper functions #
@@ -245,9 +216,7 @@ def template_detail(request, template):
245 216
 
246 217
 def missing_docutils_page(request):
247 218
     """Display an error message for people without docutils"""
248  
-    t = template_loader.get_template('doc/missing_docutils')
249  
-    c = Context(request, {})
250  
-    return HttpResponse(t.render(c))
  219
+    return load_and_render('doc/missing_docutils')
251 220
 
252 221
 def load_all_installed_template_libraries():
253 222
     # Clear out and reload default tags

0 notes on commit 4175aec

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