Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1399 -- Added template_object_name hook to generic views. Than…

…ks, ChaosKCW

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2453 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6330e286c3b739f9e6e2210d6568865cf08cf3e1 1 parent ace1406
Adrian Holovaty authored March 01, 2006
1  AUTHORS
@@ -45,6 +45,7 @@ answer newbie questions, and generally made Django that much better:
45 45
     Antonio Cavedoni <http://cavedoni.com/>
46 46
     C8E
47 47
     Amit Chakradeo <http://amit.chakradeo.net/>
  48
+    ChaosKCW
48 49
     Matt Croydon <http://www.postneo.com/>
49 50
     Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
50 51
     Jason Davies (Esaj) <http://www.jasondavies.com/>
9  django/views/generic/create_update.py
@@ -73,7 +73,8 @@ def create_object(request, app_label, module_name, template_name=None,
73 73
 def update_object(request, app_label, module_name, object_id=None, slug=None,
74 74
         slug_field=None, template_name=None, template_loader=loader,
75 75
         extra_lookup_kwargs={}, extra_context={}, post_save_redirect=None,
76  
-        login_required=False, follow=None, context_processors=None):
  76
+        login_required=False, follow=None, context_processors=None,
  77
+        template_object_name='object'):
77 78
     """
78 79
     Generic object-update function.
79 80
 
@@ -133,7 +134,7 @@ def update_object(request, app_label, module_name, object_id=None, slug=None,
133 134
     t = template_loader.get_template(template_name)
134 135
     c = DjangoContext(request, {
135 136
         'form': form,
136  
-        'object': object,
  137
+        template_object_name: object,
137 138
     }, context_processors)
138 139
     for key, value in extra_context.items():
139 140
         if callable(value):
@@ -147,7 +148,7 @@ def update_object(request, app_label, module_name, object_id=None, slug=None,
147 148
 def delete_object(request, app_label, module_name, post_delete_redirect,
148 149
         object_id=None, slug=None, slug_field=None, template_name=None,
149 150
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
150  
-        login_required=False, context_processors=None):
  151
+        login_required=False, context_processors=None, template_object_name='object'):
151 152
     """
152 153
     Generic object-delete function.
153 154
 
@@ -189,7 +190,7 @@ def delete_object(request, app_label, module_name, post_delete_redirect,
189 190
             template_name = "%s/%s_confirm_delete" % (app_label, module_name)
190 191
         t = template_loader.get_template(template_name)
191 192
         c = DjangoContext(request, {
192  
-            'object': object,
  193
+            template_object_name: object,
193 194
         }, context_processors)
194 195
         for key, value in extra_context.items():
195 196
             if callable(value):
12  django/views/generic/date_based.py
@@ -89,7 +89,7 @@ def archive_year(request, year, app_label, module_name, date_field,
89 89
 def archive_month(request, year, month, app_label, module_name, date_field,
90 90
         month_format='%b', template_name=None, template_loader=loader,
91 91
         extra_lookup_kwargs={}, extra_context={}, allow_empty=False,
92  
-        context_processors=None):
  92
+        context_processors=None, template_object_name='object'):
93 93
     """
94 94
     Generic monthly archive view.
95 95
 
@@ -129,7 +129,7 @@ def archive_month(request, year, month, app_label, module_name, date_field,
129 129
         template_name = "%s/%s_archive_month" % (app_label, module_name)
130 130
     t = template_loader.get_template(template_name)
131 131
     c = DjangoContext(request, {
132  
-        'object_list': object_list,
  132
+        '%s_list' % template_object_name: object_list,
133 133
         'month': date,
134 134
         'next_month': (last_day < datetime.date.today()) and (last_day + datetime.timedelta(days=1)) or None,
135 135
         'previous_month': first_day - datetime.timedelta(days=1),
@@ -144,7 +144,7 @@ def archive_month(request, year, month, app_label, module_name, date_field,
144 144
 def archive_day(request, year, month, day, app_label, module_name, date_field,
145 145
         month_format='%b', day_format='%d', template_name=None,
146 146
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
147  
-        allow_empty=False, context_processors=None):
  147
+        allow_empty=False, context_processors=None, template_object_name='object'):
148 148
     """
149 149
     Generic daily archive view.
150 150
 
@@ -180,7 +180,7 @@ def archive_day(request, year, month, day, app_label, module_name, date_field,
180 180
         template_name = "%s/%s_archive_day" % (app_label, module_name)
181 181
     t = template_loader.get_template(template_name)
182 182
     c = DjangoContext(request, {
183  
-        'object_list': object_list,
  183
+        '%s_list' % template_object_name: object_list,
184 184
         'day': date,
185 185
         'previous_day': date - datetime.timedelta(days=1),
186 186
         'next_day': (date < datetime.date.today()) and (date + datetime.timedelta(days=1)) or None,
@@ -208,7 +208,7 @@ def object_detail(request, year, month, day, app_label, module_name, date_field,
208 208
         month_format='%b', day_format='%d', object_id=None, slug=None,
209 209
         slug_field=None, template_name=None, template_name_field=None,
210 210
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
211  
-        context_processors=None):
  211
+        context_processors=None, template_object_name='object'):
212 212
     """
213 213
     Generic detail view from year/month/day/slug or year/month/day/id structure.
214 214
 
@@ -249,7 +249,7 @@ def object_detail(request, year, month, day, app_label, module_name, date_field,
249 249
     else:
250 250
         t = template_loader.get_template(template_name)
251 251
     c = DjangoContext(request, {
252  
-        'object': object,
  252
+        template_object_name: object,
253 253
     }, context_processors)
254 254
     for key, value in extra_context.items():
255 255
         if callable(value):
10  django/views/generic/list_detail.py
@@ -8,7 +8,7 @@
8 8
 
9 9
 def object_list(request, app_label, module_name, paginate_by=None, allow_empty=False,
10 10
         template_name=None, template_loader=loader, extra_lookup_kwargs={},
11  
-        extra_context={}, context_processors=None):
  11
+        extra_context={}, context_processors=None, template_object_name='object'):
12 12
     """
13 13
     Generic list of objects.
14 14
 
@@ -49,7 +49,7 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F
49 49
             else:
50 50
                 raise Http404
51 51
         c = DjangoContext(request, {
52  
-            'object_list': object_list,
  52
+            '%s_list' % template_object_name: object_list,
53 53
             'is_paginated': paginator.pages > 1,
54 54
             'results_per_page': paginate_by,
55 55
             'has_next': paginator.has_next_page(page - 1),
@@ -63,7 +63,7 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F
63 63
     else:
64 64
         object_list = mod.get_list(**lookup_kwargs)
65 65
         c = DjangoContext(request, {
66  
-            'object_list': object_list,
  66
+            '%s_list' % template_object_name: object_list,
67 67
             'is_paginated': False
68 68
         }, context_processors)
69 69
         if len(object_list) == 0 and not allow_empty:
@@ -81,7 +81,7 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F
81 81
 def object_detail(request, app_label, module_name, object_id=None, slug=None,
82 82
         slug_field=None, template_name=None, template_name_field=None,
83 83
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
84  
-        context_processors=None):
  84
+        context_processors=None, template_object_name='object'):
85 85
     """
86 86
     Generic list of objects.
87 87
 
@@ -111,7 +111,7 @@ def object_detail(request, app_label, module_name, object_id=None, slug=None,
111 111
     else:
112 112
         t = template_loader.get_template(template_name)
113 113
     c = DjangoContext(request, {
114  
-        'object': object,
  114
+        template_object_name: object,
115 115
     }, context_processors)
116 116
     for key, value in extra_context.items():
117 117
         if callable(value):
51  docs/generic_views.txt
@@ -193,6 +193,10 @@ The date-based generic functions are:
193 193
     **New in Django development version:** Takes an optional ``allow_empty``
194 194
     parameter, as ``archive_index``.
195 195
 
  196
+    **New in Django development version:** Takes an optional
  197
+    ``template_object_name`` parameter, which designates the name of the
  198
+    template variable to use. Default is ``'object'``.
  199
+
196 200
     Uses the template ``app_label/module_name_archive_month`` by default.
197 201
 
198 202
     Has the following template context:
@@ -207,7 +211,11 @@ The date-based generic functions are:
207 211
             **New in Django development version.** The first day of the
208 212
             previous month (a datetime.date object)
209 213
         ``object_list``
210  
-            List of objects published in the given month
  214
+            List of objects published in the given month.
  215
+            In the Django development version, you can change this variable
  216
+            name from ``object_list`` by using the ``template_object_name``
  217
+            parameter. (See above.) For example, if ``template_object_name`` is
  218
+            ``foo``, the variable will be ``foo_list``.
211 219
 
212 220
 ``archive_day``
213 221
     Daily archive. Requires that ``year``, ``month``, and ``day`` arguments be
@@ -217,12 +225,20 @@ The date-based generic functions are:
217 225
     also pass ``day_format``, which defaults to ``"%d"`` (day of the month as a
218 226
     decimal number, 1-31).
219 227
 
  228
+    **New in Django development version:** Takes an optional
  229
+    ``template_object_name`` parameter, which designates the name of the
  230
+    template variable to use. Default is ``'object'``.
  231
+
220 232
     Uses the template ``app_label/module_name_archive_day`` by default.
221 233
 
222 234
     Has the following template context:
223 235
 
224 236
         ``object_list``
225  
-            List of objects published this day
  237
+            List of objects published on the given day.
  238
+            In the Django development version, you can change this variable
  239
+            name from ``object_list`` by using the ``template_object_name``
  240
+            parameter. (See above.) For example, if ``template_object_name`` is
  241
+            ``foo``, the variable will be ``foo_list``.
226 242
         ``day``
227 243
             The given day (a datetime.datetime object)
228 244
         ``previous_day``
@@ -254,6 +270,10 @@ The date-based generic functions are:
254 270
     As in ``archive_day``, ``object_detail`` takes optional ``month_format``
255 271
     and ``day_format`` parameters.
256 272
 
  273
+    **New in Django development version:** Takes an optional
  274
+    ``template_object_name`` parameter, which designates the name of the
  275
+    template variable to use. Default is ``'object'``.
  276
+
257 277
 .. _strftime docs: http://www.python.org/doc/current/lib/module-time.html#l2h-1941
258 278
 
259 279
 Using list/detail generic views
@@ -285,6 +305,9 @@ Individual views are:
285 305
         ``allow_empty``          If ``False`` and there are no objects to display,
286 306
                                  the view will raise a 404 instead of displaying
287 307
                                  an empty index page. ``False`` is default.
  308
+        ``template_object_name`` **New in Django development version.** Designates
  309
+                                 the name of the object template variable. Default
  310
+                                 is ``'object'``.
288 311
         =======================  =================================================
289 312
 
290 313
     Uses the template ``app_label/module_name_list`` by default.
@@ -292,7 +315,11 @@ Individual views are:
292 315
     Has the following template context:
293 316
 
294 317
         ``object_list``
295  
-            List of objects
  318
+            List of objects. In the Django development version, you can change
  319
+            this variable name from ``object_list`` by using the
  320
+            ``template_object_name`` parameter. (See above.) For example, if
  321
+            ``template_object_name`` is ``foo``, the variable will be
  322
+            ``foo_list``.
296 323
         ``is_paginated``
297 324
             Are the results paginated? Either True or False
298 325
 
@@ -362,6 +389,10 @@ The create/update/delete views are:
362 389
     ``list_detail.object_detail`` does (see above), and the same
363 390
     ``post_save_redirect`` as ``create_object`` does.
364 391
 
  392
+    **New in Django development version:** Takes an optional
  393
+    ``template_object_name`` parameter, which designates the name of the
  394
+    template variable to use. Default is ``'object'``.
  395
+
365 396
     Uses the template ``app_label/module_name_form`` by default.
366 397
 
367 398
     Has the following template context:
@@ -369,7 +400,11 @@ The create/update/delete views are:
369 400
         form
370 401
             The form wrapper for the object
371 402
         object
372  
-            The original object being edited
  403
+            The original object being edited.
  404
+            In the Django development version, you can change this variable
  405
+            name from ``object`` by using the ``template_object_name``
  406
+            parameter. (See above.) For example, if ``template_object_name`` is
  407
+            ``foo``, the variable will be ``foo`` instead of ``object``.
373 408
 
374 409
 ``delete_object``
375 410
     Delete an existing object. The given object will only actually be deleted
@@ -384,7 +419,15 @@ The create/update/delete views are:
384 419
     ``app_label/module_name_confirm_delete`` by default. It uses no template
385 420
     if POSTed -- it simply deletes the object and redirects.
386 421
 
  422
+    **New in Django development version:** Takes an optional
  423
+    ``template_object_name`` parameter, which designates the name of the
  424
+    template variable to use. Default is ``'object'``.
  425
+
387 426
     Has the following template context:
388 427
 
389 428
         object
390 429
             The object about to be deleted
  430
+            In the Django development version, you can change this variable
  431
+            name from ``object`` by using the ``template_object_name``
  432
+            parameter. (See above.) For example, if ``template_object_name`` is
  433
+            ``foo``, the variable will be ``foo`` instead of ``object``.

0 notes on commit 6330e28

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