Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed Adrians change's from [1933] that I accidentally…

… undid in [1945].

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1954 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e1575ace03772d8107b9a227cebfe1106c325ca6 1 parent 9a9e273
Joseph Kocherhans authored January 13, 2006
52  django/views/generic/create_update.py
... ...
@@ -1,4 +1,3 @@
1  
-from django import models
2 1
 from django.core.xheaders import populate_xheaders
3 2
 from django.template import loader
4 3
 from django.core import formfields, meta
@@ -8,13 +7,13 @@
8 7
 from django.http import Http404, HttpResponse, HttpResponseRedirect
9 8
 from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
10 9
 
11  
-def create_object(request, app_label, module_name, template_name=None,
  10
+def create_object(request, model, template_name=None,
12 11
         template_loader=loader, extra_context={}, post_save_redirect=None,
13 12
         login_required=False, follow=None, context_processors=None):
14 13
     """
15 14
     Generic object-creation function.
16 15
 
17  
-    Templates: ``<app_label>/<module_name>_form``
  16
+    Templates: ``<app_label>/<model_name>_form``
18 17
     Context:
19 18
         form
20 19
             the form wrapper for the object
@@ -22,13 +21,12 @@ def create_object(request, app_label, module_name, template_name=None,
22 21
     if login_required and request.user.is_anonymous():
23 22
         return redirect_to_login(request.path)
24 23
 
25  
-    mod = models.get_module(app_label, module_name)
26  
-    manipulator = mod.AddManipulator(follow=follow)
  24
+    manipulator = model.AddManipulator(follow=follow)
27 25
     if request.POST:
28 26
         # If data was POSTed, we're trying to create a new object
29 27
         new_data = request.POST.copy()
30 28
 
31  
-        if mod.Klass._meta.has_field_type(meta.FileField):
  29
+        if model._meta.has_field_type(meta.FileField):
32 30
             new_data.update(request.FILES)
33 31
 
34 32
         # Check for errors
@@ -40,7 +38,7 @@ def create_object(request, app_label, module_name, template_name=None,
40 38
             new_object = manipulator.save(new_data)
41 39
 
42 40
             if not request.user.is_anonymous():
43  
-                request.user.add_message("The %s was created sucessfully." % mod.Klass._meta.verbose_name)
  41
+                request.user.add_message("The %s was created sucessfully." % model._meta.verbose_name)
44 42
 
45 43
             # Redirect to the new object: first by trying post_save_redirect,
46 44
             # then by obj.get_absolute_url; fail if neither works.
@@ -58,7 +56,7 @@ def create_object(request, app_label, module_name, template_name=None,
58 56
     # Create the FormWrapper, template, context, response
59 57
     form = formfields.FormWrapper(manipulator, new_data, errors)
60 58
     if not template_name:
61  
-        template_name = "%s/%s_form" % (app_label, module_name)
  59
+        template_name = "%s/%s_form" % (model._meta.app_label, model._meta.object_name.lower())
62 60
     t = template_loader.get_template(template_name)
63 61
     c = RequestContext(request, {
64 62
         'form': form,
@@ -70,14 +68,14 @@ def create_object(request, app_label, module_name, template_name=None,
70 68
             c[key] = value
71 69
     return HttpResponse(t.render(c))
72 70
 
73  
-def update_object(request, app_label, module_name, object_id=None, slug=None,
  71
+def update_object(request, model, object_id=None, slug=None,
74 72
         slug_field=None, template_name=None, template_loader=loader,
75 73
         extra_lookup_kwargs={}, extra_context={}, post_save_redirect=None,
76 74
         login_required=False, follow=None, context_processors=None):
77 75
     """
78 76
     Generic object-update function.
79 77
 
80  
-    Templates: ``<app_label>/<module_name>_form``
  78
+    Templates: ``<app_label>/<model_name>_form``
81 79
     Context:
82 80
         form
83 81
             the form wrapper for the object
@@ -87,23 +85,21 @@ def update_object(request, app_label, module_name, object_id=None, slug=None,
87 85
     if login_required and request.user.is_anonymous():
88 86
         return redirect_to_login(request.path)
89 87
 
90  
-    mod = models.get_module(app_label, module_name)
91  
-
92 88
     # Look up the object to be edited
93 89
     lookup_kwargs = {}
94 90
     if object_id:
95  
-        lookup_kwargs['%s__exact' % mod.Klass._meta.pk.name] = object_id
  91
+        lookup_kwargs['%s__exact' % model._meta.pk.name] = object_id
96 92
     elif slug and slug_field:
97 93
         lookup_kwargs['%s__exact' % slug_field] = slug
98 94
     else:
99 95
         raise AttributeError("Generic edit view must be called with either an object_id or a slug/slug_field")
100 96
     lookup_kwargs.update(extra_lookup_kwargs)
101 97
     try:
102  
-        object = mod.get_object(**lookup_kwargs)
  98
+        object = model._default_manager.get_object(**lookup_kwargs)
103 99
     except ObjectDoesNotExist:
104  
-        raise Http404("%s.%s does not exist for %s" % (app_label, module_name, lookup_kwargs))
  100
+        raise Http404, "No %s found for %s" % (model._meta.verbose_name, lookup_kwargs)
105 101
 
106  
-    manipulator = mod.ChangeManipulator(object.id, follow=follow)
  102
+    manipulator = model.ChangeManipulator(object.id, follow=follow)
107 103
 
108 104
     if request.POST:
109 105
         new_data = request.POST.copy()
@@ -113,7 +109,7 @@ def update_object(request, app_label, module_name, object_id=None, slug=None,
113 109
             manipulator.save(new_data)
114 110
 
115 111
             if not request.user.is_anonymous():
116  
-                request.user.add_message("The %s was updated sucessfully." % mod.Klass._meta.verbose_name)
  112
+                request.user.add_message("The %s was updated sucessfully." % model._meta.verbose_name)
117 113
 
118 114
             # Do a post-after-redirect so that reload works, etc.
119 115
             if post_save_redirect:
@@ -129,7 +125,7 @@ def update_object(request, app_label, module_name, object_id=None, slug=None,
129 125
 
130 126
     form = formfields.FormWrapper(manipulator, new_data, errors)
131 127
     if not template_name:
132  
-        template_name = "%s/%s_form" % (app_label, module_name)
  128
+        template_name = "%s/%s_form" % (model._meta.app_label, model._meta.object_name.lower())
133 129
     t = template_loader.get_template(template_name)
134 130
     c = RequestContext(request, {
135 131
         'form': form,
@@ -141,10 +137,10 @@ def update_object(request, app_label, module_name, object_id=None, slug=None,
141 137
         else:
142 138
             c[key] = value
143 139
     response = HttpResponse(t.render(c))
144  
-    populate_xheaders(request, response, app_label, module_name, getattr(object, object._meta.pk.name))
  140
+    populate_xheaders(request, response, model, getattr(object, object._meta.pk.name))
145 141
     return response
146 142
 
147  
-def delete_object(request, app_label, module_name, post_delete_redirect,
  143
+def delete_object(request, model, post_delete_redirect,
148 144
         object_id=None, slug=None, slug_field=None, template_name=None,
149 145
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
150 146
         login_required=False, context_processors=None):
@@ -155,7 +151,7 @@ def delete_object(request, app_label, module_name, post_delete_redirect,
155 151
     fetched using GET; for safty, deletion will only be performed if this
156 152
     view is POSTed.
157 153
 
158  
-    Templates: ``<app_label>/<module_name>_confirm_delete``
  154
+    Templates: ``<app_label>/<model_name>_confirm_delete``
159 155
     Context:
160 156
         object
161 157
             the original object being deleted
@@ -163,30 +159,28 @@ def delete_object(request, app_label, module_name, post_delete_redirect,
163 159
     if login_required and request.user.is_anonymous():
164 160
         return redirect_to_login(request.path)
165 161
 
166  
-    mod = models.get_module(app_label, module_name)
167  
-
168 162
     # Look up the object to be edited
169 163
     lookup_kwargs = {}
170 164
     if object_id:
171  
-        lookup_kwargs['%s__exact' % mod.Klass._meta.pk.name] = object_id
  165
+        lookup_kwargs['%s__exact' % model._meta.pk.name] = object_id
172 166
     elif slug and slug_field:
173 167
         lookup_kwargs['%s__exact' % slug_field] = slug
174 168
     else:
175 169
         raise AttributeError("Generic delete view must be called with either an object_id or a slug/slug_field")
176 170
     lookup_kwargs.update(extra_lookup_kwargs)
177 171
     try:
178  
-        object = mod.get_object(**lookup_kwargs)
  172
+        object = model._default_manager.get_object(**lookup_kwargs)
179 173
     except ObjectDoesNotExist:
180  
-        raise Http404("%s.%s does not exist for %s" % (app_label, module_name, lookup_kwargs))
  174
+        raise Http404, "No %s found for %s" % (model._meta.app_label, lookup_kwargs)
181 175
 
182 176
     if request.META['REQUEST_METHOD'] == 'POST':
183 177
         object.delete()
184 178
         if not request.user.is_anonymous():
185  
-            request.user.add_message("The %s was deleted." % mod.Klass._meta.verbose_name)
  179
+            request.user.add_message("The %s was deleted." % model._meta.verbose_name)
186 180
         return HttpResponseRedirect(post_delete_redirect)
187 181
     else:
188 182
         if not template_name:
189  
-            template_name = "%s/%s_confirm_delete" % (app_label, module_name)
  183
+            template_name = "%s/%s_confirm_delete" % (model._meta.app_label, model._meta.object_name.lower())
190 184
         t = template_loader.get_template(template_name)
191 185
         c = RequestContext(request, {
192 186
             'object': object,
@@ -197,5 +191,5 @@ def delete_object(request, app_label, module_name, post_delete_redirect,
197 191
             else:
198 192
                 c[key] = value
199 193
         response = HttpResponse(t.render(c))
200  
-        populate_xheaders(request, response, app_label, module_name, getattr(object, object._meta.pk.name))
  194
+        populate_xheaders(request, response, model, getattr(object, object._meta.pk.name))
201 195
         return response
58  django/views/generic/date_based.py
... ...
@@ -1,41 +1,39 @@
1 1
 from django.template import loader, RequestContext
2 2
 from django.core.exceptions import ObjectDoesNotExist
3 3
 from django.core.xheaders import populate_xheaders
4  
-from django.models import get_module
5 4
 from django.http import Http404, HttpResponse
6 5
 import datetime, time
7 6
 
8  
-def archive_index(request, app_label, module_name, date_field, num_latest=15,
  7
+def archive_index(request, model, date_field, num_latest=15,
9 8
         template_name=None, template_loader=loader, extra_lookup_kwargs={},
10 9
         extra_context={}, allow_empty=False, context_processors=None):
11 10
     """
12 11
     Generic top-level archive of date-based objects.
13 12
 
14  
-    Templates: ``<app_label>/<module_name>_archive``
  13
+    Templates: ``<app_label>/<model_name>_archive``
15 14
     Context:
16 15
         date_list
17 16
             List of years
18 17
         latest
19 18
             Latest N (defaults to 15) objects by date
20 19
     """
21  
-    mod = get_module(app_label, module_name)
22 20
     lookup_kwargs = {'%s__lte' % date_field: datetime.datetime.now()}
23 21
     lookup_kwargs.update(extra_lookup_kwargs)
24  
-    date_list = getattr(mod, "get_%s_list" % date_field)('year', **lookup_kwargs)[::-1]
  22
+    date_list = getattr(model._default_manager, "get_%s_list" % date_field)('year', **lookup_kwargs)[::-1]
25 23
     if not date_list and not allow_empty:
26  
-        raise Http404("No %s.%s available" % (app_label, module_name))
  24
+        raise Http404, "No %s available" % model._meta.verbose_name
27 25
 
28 26
     if date_list and num_latest:
29 27
         lookup_kwargs.update({
30 28
             'limit': num_latest,
31 29
             'order_by': ('-' + date_field,),
32 30
         })
33  
-        latest = mod.get_list(**lookup_kwargs)
  31
+        latest = model._default_manager.get_list(**lookup_kwargs)
34 32
     else:
35 33
         latest = None
36 34
 
37 35
     if not template_name:
38  
-        template_name = "%s/%s_archive" % (app_label, module_name)
  36
+        template_name = "%s/%s_archive" % (model._meta.app_label, model._meta.object_name.lower())
39 37
     t = template_loader.get_template(template_name)
40 38
     c = RequestContext(request, {
41 39
         'date_list' : date_list,
@@ -48,31 +46,30 @@ def archive_index(request, app_label, module_name, date_field, num_latest=15,
48 46
             c[key] = value
49 47
     return HttpResponse(t.render(c))
50 48
 
51  
-def archive_year(request, year, app_label, module_name, date_field,
  49
+def archive_year(request, year, model, date_field,
52 50
         template_name=None, template_loader=loader, extra_lookup_kwargs={},
53 51
         extra_context={}, context_processors=None):
54 52
     """
55 53
     Generic yearly archive view.
56 54
 
57  
-    Templates: ``<app_label>/<module_name>_archive_year``
  55
+    Templates: ``<app_label>/<model_name>_archive_year``
58 56
     Context:
59 57
         date_list
60 58
             List of months in this year with objects
61 59
         year
62 60
             This year
63 61
     """
64  
-    mod = get_module(app_label, module_name)
65 62
     now = datetime.datetime.now()
66 63
     lookup_kwargs = {'%s__year' % date_field: year}
67 64
     # Only bother to check current date if the year isn't in the past.
68 65
     if int(year) >= now.year:
69 66
         lookup_kwargs['%s__lte' % date_field] = now
70 67
     lookup_kwargs.update(extra_lookup_kwargs)
71  
-    date_list = getattr(mod, "get_%s_list" % date_field)('month', **lookup_kwargs)
  68
+    date_list = getattr(model._default_manager, "get_%s_list" % date_field)('month', **lookup_kwargs)
72 69
     if not date_list:
73 70
         raise Http404
74 71
     if not template_name:
75  
-        template_name = "%s/%s_archive_year" % (app_label, module_name)
  72
+        template_name = "%s/%s_archive_year" % (model._meta.app_label, model._meta.object_name.lower())
76 73
     t = template_loader.get_template(template_name)
77 74
     c = RequestContext(request, {
78 75
         'date_list': date_list,
@@ -85,13 +82,13 @@ def archive_year(request, year, app_label, module_name, date_field,
85 82
             c[key] = value
86 83
     return HttpResponse(t.render(c))
87 84
 
88  
-def archive_month(request, year, month, app_label, module_name, date_field,
  85
+def archive_month(request, year, month, model, date_field,
89 86
         month_format='%b', template_name=None, template_loader=loader,
90 87
         extra_lookup_kwargs={}, extra_context={}, context_processors=None):
91 88
     """
92 89
     Generic monthly archive view.
93 90
 
94  
-    Templates: ``<app_label>/<module_name>_archive_month``
  91
+    Templates: ``<app_label>/<model_name>_archive_month``
95 92
     Context:
96 93
         month:
97 94
             this month
@@ -103,7 +100,6 @@ def archive_month(request, year, month, app_label, module_name, date_field,
103 100
     except ValueError:
104 101
         raise Http404
105 102
 
106  
-    mod = get_module(app_label, module_name)
107 103
     now = datetime.datetime.now()
108 104
     # Calculate first and last day of month, for use in a date-range lookup.
109 105
     first_day = date.replace(day=1)
@@ -116,11 +112,11 @@ def archive_month(request, year, month, app_label, module_name, date_field,
116 112
     if last_day >= now.date():
117 113
         lookup_kwargs['%s__lte' % date_field] = now
118 114
     lookup_kwargs.update(extra_lookup_kwargs)
119  
-    object_list = mod.get_list(**lookup_kwargs)
  115
+    object_list = model._default_manager.get_list(**lookup_kwargs)
120 116
     if not object_list:
121 117
         raise Http404
122 118
     if not template_name:
123  
-        template_name = "%s/%s_archive_month" % (app_label, module_name)
  119
+        template_name = "%s/%s_archive_month" % (model._meta.app_label, model._meta.object_name.lower())
124 120
     t = template_loader.get_template(template_name)
125 121
     c = RequestContext(request, {
126 122
         'object_list': object_list,
@@ -133,14 +129,14 @@ def archive_month(request, year, month, app_label, module_name, date_field,
133 129
             c[key] = value
134 130
     return HttpResponse(t.render(c))
135 131
 
136  
-def archive_day(request, year, month, day, app_label, module_name, date_field,
  132
+def archive_day(request, year, month, day, model, date_field,
137 133
         month_format='%b', day_format='%d', template_name=None,
138 134
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
139 135
         allow_empty=False, context_processors=None):
140 136
     """
141 137
     Generic daily archive view.
142 138
 
143  
-    Templates: ``<app_label>/<module_name>_archive_day``
  139
+    Templates: ``<app_label>/<model_name>_archive_day``
144 140
     Context:
145 141
         object_list:
146 142
             list of objects published that day
@@ -156,7 +152,6 @@ def archive_day(request, year, month, day, app_label, module_name, date_field,
156 152
     except ValueError:
157 153
         raise Http404
158 154
 
159  
-    mod = get_module(app_label, module_name)
160 155
     now = datetime.datetime.now()
161 156
     lookup_kwargs = {
162 157
         '%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
@@ -165,11 +160,11 @@ def archive_day(request, year, month, day, app_label, module_name, date_field,
165 160
     if date >= now.date():
166 161
         lookup_kwargs['%s__lte' % date_field] = now
167 162
     lookup_kwargs.update(extra_lookup_kwargs)
168  
-    object_list = mod.get_list(**lookup_kwargs)
  163
+    object_list = model._default_manager.get_list(**lookup_kwargs)
169 164
     if not allow_empty and not object_list:
170 165
         raise Http404
171 166
     if not template_name:
172  
-        template_name = "%s/%s_archive_day" % (app_label, module_name)
  167
+        template_name = "%s/%s_archive_day" % (model._meta.app_label, model._meta.object_name.lower())
173 168
     t = template_loader.get_template(template_name)
174 169
     c = RequestContext(request, {
175 170
         'object_list': object_list,
@@ -196,7 +191,7 @@ def archive_today(request, **kwargs):
196 191
     })
197 192
     return archive_day(request, **kwargs)
198 193
 
199  
-def object_detail(request, year, month, day, app_label, module_name, date_field,
  194
+def object_detail(request, year, month, day, model, date_field,
200 195
         month_format='%b', day_format='%d', object_id=None, slug=None,
201 196
         slug_field=None, template_name=None, template_name_field=None,
202 197
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
@@ -204,7 +199,7 @@ def object_detail(request, year, month, day, app_label, module_name, date_field,
204 199
     """
205 200
     Generic detail view from year/month/day/slug or year/month/day/id structure.
206 201
 
207  
-    Templates: ``<app_label>/<module_name>_detail``
  202
+    Templates: ``<app_label>/<model_name>_detail``
208 203
     Context:
209 204
         object:
210 205
             the object to be detailed
@@ -214,7 +209,6 @@ def object_detail(request, year, month, day, app_label, module_name, date_field,
214 209
     except ValueError:
215 210
         raise Http404
216 211
 
217  
-    mod = get_module(app_label, module_name)
218 212
     now = datetime.datetime.now()
219 213
     lookup_kwargs = {
220 214
         '%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
@@ -223,18 +217,18 @@ def object_detail(request, year, month, day, app_label, module_name, date_field,
223 217
     if date >= now.date():
224 218
         lookup_kwargs['%s__lte' % date_field] = now
225 219
     if object_id:
226  
-        lookup_kwargs['%s__exact' % mod.Klass._meta.pk.name] = object_id
  220
+        lookup_kwargs['%s__exact' % model._meta.pk.name] = object_id
227 221
     elif slug and slug_field:
228 222
         lookup_kwargs['%s__exact' % slug_field] = slug
229 223
     else:
230  
-        raise AttributeError("Generic detail view must be called with either an object_id or a slug/slugfield")
  224
+        raise AttributeError, "Generic detail view must be called with either an object_id or a slug/slugfield"
231 225
     lookup_kwargs.update(extra_lookup_kwargs)
232 226
     try:
233  
-        object = mod.get_object(**lookup_kwargs)
  227
+        object = model._default_manager.get_object(**lookup_kwargs)
234 228
     except ObjectDoesNotExist:
235  
-        raise Http404("%s.%s does not exist for %s" % (app_label, module_name, lookup_kwargs))
  229
+        raise Http404, "No %s found for %s" % (model._meta.verbose_name, lookup_kwargs)
236 230
     if not template_name:
237  
-        template_name = "%s/%s_detail" % (app_label, module_name)
  231
+        template_name = "%s/%s_detail" % (model._meta.app_label, model._meta.object_name.lower())
238 232
     if template_name_field:
239 233
         template_name_list = [getattr(object, template_name_field), template_name]
240 234
         t = template_loader.select_template(template_name_list)
@@ -249,5 +243,5 @@ def object_detail(request, year, month, day, app_label, module_name, date_field,
249 243
         else:
250 244
             c[key] = value
251 245
     response = HttpResponse(t.render(c))
252  
-    populate_xheaders(request, response, app_label, module_name, getattr(object, object._meta.pk.name))
  246
+    populate_xheaders(request, response, model, getattr(object, object._meta.pk.name))
253 247
     return response
27  django/views/generic/list_detail.py
... ...
@@ -1,17 +1,16 @@
1  
-from django import models
2 1
 from django.template import loader, RequestContext
3 2
 from django.http import Http404, HttpResponse
4 3
 from django.core.xheaders import populate_xheaders
5 4
 from django.core.paginator import ObjectPaginator, InvalidPage
6 5
 from django.core.exceptions import ObjectDoesNotExist
7 6
 
8  
-def object_list(request, app_label, module_name, paginate_by=None, allow_empty=False,
  7
+def object_list(request, model, paginate_by=None, allow_empty=False,
9 8
         template_name=None, template_loader=loader, extra_lookup_kwargs={},
10 9
         extra_context={}, context_processors=None):
11 10
     """
12 11
     Generic list of objects.
13 12
 
14  
-    Templates: ``<app_label>/<module_name>_list``
  13
+    Templates: ``<app_label>/<model_name>_list``
15 14
     Context:
16 15
         object_list
17 16
             list of objects
@@ -34,10 +33,9 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F
34 33
         hits
35 34
             number of objects, total
36 35
     """
37  
-    mod = models.get_module(app_label, module_name)
38 36
     lookup_kwargs = extra_lookup_kwargs.copy()
39 37
     if paginate_by:
40  
-        paginator = ObjectPaginator(mod, lookup_kwargs, paginate_by)
  38
+        paginator = ObjectPaginator(model, lookup_kwargs, paginate_by)
41 39
         page = request.GET.get('page', 0)
42 40
         try:
43 41
             object_list = paginator.get_page(page)
@@ -60,7 +58,7 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F
60 58
             'hits' : paginator.hits,
61 59
         }, context_processors)
62 60
     else:
63  
-        object_list = mod.get_list(**lookup_kwargs)
  61
+        object_list = model._default_manager.get_list(**lookup_kwargs)
64 62
         c = RequestContext(request, {
65 63
             'object_list': object_list,
66 64
             'is_paginated': False
@@ -73,37 +71,36 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F
73 71
         else:
74 72
             c[key] = value
75 73
     if not template_name:
76  
-        template_name = "%s/%s_list" % (app_label, module_name)
  74
+        template_name = "%s/%s_list" % (model._meta.app_label, model._meta.object_name.lower())
77 75
     t = template_loader.get_template(template_name)
78 76
     return HttpResponse(t.render(c))
79 77
 
80  
-def object_detail(request, app_label, module_name, object_id=None, slug=None,
  78
+def object_detail(request, model, object_id=None, slug=None,
81 79
         slug_field=None, template_name=None, template_name_field=None,
82 80
         template_loader=loader, extra_lookup_kwargs={}, extra_context={},
83 81
         context_processors=None):
84 82
     """
85 83
     Generic list of objects.
86 84
 
87  
-    Templates: ``<app_label>/<module_name>_detail``
  85
+    Templates: ``<app_label>/<model_name>_detail``
88 86
     Context:
89 87
         object
90 88
             the object
91 89
     """
92  
-    mod = models.get_module(app_label, module_name)
93 90
     lookup_kwargs = {}
94 91
     if object_id:
95 92
         lookup_kwargs['pk'] = object_id
96 93
     elif slug and slug_field:
97 94
         lookup_kwargs['%s__exact' % slug_field] = slug
98 95
     else:
99  
-        raise AttributeError("Generic detail view must be called with either an object_id or a slug/slug_field")
  96
+        raise AttributeError, "Generic detail view must be called with either an object_id or a slug/slug_field."
100 97
     lookup_kwargs.update(extra_lookup_kwargs)
101 98
     try:
102  
-        object = mod.get_object(**lookup_kwargs)
  99
+        object = model._default_manager.get_object(**lookup_kwargs)
103 100
     except ObjectDoesNotExist:
104  
-        raise Http404("%s.%s does not exist for %s" % (app_label, module_name, lookup_kwargs))
  101
+        raise Http404, "No %s found for %s" % (model._meta.verbose_name, lookup_kwargs)
105 102
     if not template_name:
106  
-        template_name = "%s/%s_detail" % (app_label, module_name)
  103
+        template_name = "%s/%s_detail" % (model._meta.app_label, model._meta.object_name.lower())
107 104
     if template_name_field:
108 105
         template_name_list = [getattr(object, template_name_field), template_name]
109 106
         t = template_loader.select_template(template_name_list)
@@ -118,5 +115,5 @@ def object_detail(request, app_label, module_name, object_id=None, slug=None,
118 115
         else:
119 116
             c[key] = value
120 117
     response = HttpResponse(t.render(c))
121  
-    populate_xheaders(request, response, app_label, module_name, getattr(object, object._meta.pk.name))
  118
+    populate_xheaders(request, response, model, getattr(object, object._meta.pk.name))
122 119
     return response
8  docs/generic_views.txt
@@ -121,16 +121,16 @@ arguments:
121 121
                              template's context.
122 122
 
123 123
     ``processors``           A tuple of processors to apply to the
124  
-                             ``RequestContext`` of this view's template. See the
125  
-                             `RequestContext docs`_
  124
+                             ``DjangoContext`` of this view's template. See the
  125
+                             `DjangoContext docs`_
126 126
     =======================  ==================================================
127 127
 
128 128
 .. _database API docs: http://www.djangoproject.com/documentation/db_api/
129  
-.. _RequestContext docs: http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext
  129
+.. _DjangoContext docs: http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext
130 130
 
131 131
 The date-based generic functions are:
132 132
 
133  
-``archive_index``RequestContext
  133
+``archive_index``
134 134
     A top-level index page showing the "latest" objects.
135 135
 
136 136
     Takes the following optional arguments:

0 notes on commit e1575ac

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