Ticket #18180: admin_common_context.diff
File admin_common_context.diff, 6.8 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/options.py
212 212 """ 213 213 return self.prepopulated_fields 214 214 215 def get_context_data(self, **kwargs): 216 return kwargs 217 215 218 def queryset(self, request): 216 219 """ 217 220 Returns a QuerySet of all model instances that can be edited by the … … 736 739 opts = self.model._meta 737 740 app_label = opts.app_label 738 741 ordered_objects = opts.get_ordered_objects() 742 context = self.get_context_data(**context) 739 743 context.update({ 740 744 'add': add, 741 745 'change': change, … … 994 998 inline_admin_formsets.append(inline_admin_formset) 995 999 media = media + inline_admin_formset.media 996 1000 997 context = {1001 context = self.get_context_data(**{ 998 1002 'title': _('Add %s') % force_unicode(opts.verbose_name), 999 1003 'adminform': adminForm, 1000 1004 'is_popup': "_popup" in request.REQUEST, … … 1003 1007 'inline_admin_formsets': inline_admin_formsets, 1004 1008 'errors': helpers.AdminErrorList(form, formsets), 1005 1009 'app_label': opts.app_label, 1006 } 1010 }) 1007 1011 context.update(extra_context or {}) 1008 1012 return self.render_change_form(request, context, form_url=form_url, add=True) 1009 1013 … … 1085 1089 inline_admin_formsets.append(inline_admin_formset) 1086 1090 media = media + inline_admin_formset.media 1087 1091 1088 context = {1092 context = self.get_context_data(**{ 1089 1093 'title': _('Change %s') % force_unicode(opts.verbose_name), 1090 1094 'adminform': adminForm, 1091 1095 'object_id': object_id, … … 1095 1099 'inline_admin_formsets': inline_admin_formsets, 1096 1100 'errors': helpers.AdminErrorList(form, formsets), 1097 1101 'app_label': opts.app_label, 1098 } 1102 }) 1099 1103 context.update(extra_context or {}) 1100 1104 return self.render_change_form(request, context, change=True, obj=obj, form_url=form_url) 1101 1105 … … 1228 1232 selection_note_all = ungettext('%(total_count)s selected', 1229 1233 'All %(total_count)s selected', cl.result_count) 1230 1234 1231 context = {1235 context = self.get_context_data(**{ 1232 1236 'module_name': force_unicode(opts.verbose_name_plural), 1233 1237 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 1234 1238 'selection_note_all': selection_note_all % {'total_count': cl.result_count}, … … 1242 1246 'actions_on_top': self.actions_on_top, 1243 1247 'actions_on_bottom': self.actions_on_bottom, 1244 1248 'actions_selection_counter': self.actions_selection_counter, 1245 } 1249 }) 1246 1250 context.update(extra_context or {}) 1247 1251 1248 1252 return TemplateResponse(request, self.change_list_template or [ … … 1296 1300 else: 1297 1301 title = _("Are you sure?") 1298 1302 1299 context = {1303 context = self.get_context_data(**{ 1300 1304 "title": title, 1301 1305 "object_name": object_name, 1302 1306 "object": obj, … … 1305 1309 "protected": protected, 1306 1310 "opts": opts, 1307 1311 "app_label": app_label, 1308 } 1312 }) 1309 1313 context.update(extra_context or {}) 1310 1314 1311 1315 return TemplateResponse(request, self.delete_confirmation_template or [ … … 1326 1330 ).select_related().order_by('action_time') 1327 1331 # If no history was found, see whether this object even exists. 1328 1332 obj = get_object_or_404(model, pk=unquote(object_id)) 1329 context = {1333 context = self.get_context_data(**{ 1330 1334 'title': _('Change history: %s') % force_unicode(obj), 1331 1335 'action_list': action_list, 1332 1336 'module_name': capfirst(force_unicode(opts.verbose_name_plural)), 1333 1337 'object': obj, 1334 1338 'app_label': app_label, 1335 1339 'opts': opts, 1336 } 1340 }) 1337 1341 context.update(extra_context or {}) 1338 1342 return TemplateResponse(request, self.object_history_template or [ 1339 1343 "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()), -
django/contrib/admin/sites.py
128 128 """ 129 129 return self._global_actions[name] 130 130 131 def get_context_data(self, **kwargs): 132 return kwargs 133 131 134 @property 132 135 def actions(self): 133 136 """ … … 270 273 from django.contrib.auth.views import password_change_done 271 274 defaults = { 272 275 'current_app': self.name, 273 'extra_context': extra_context or {},276 'extra_context': self.get_context_data(**(extra_context or {})), 274 277 } 275 278 if self.password_change_done_template is not None: 276 279 defaults['template_name'] = self.password_change_done_template … … 299 302 from django.contrib.auth.views import logout 300 303 defaults = { 301 304 'current_app': self.name, 302 'extra_context': extra_context or {},305 'extra_context': self.get_context_data(**(extra_context or {})), 303 306 } 304 307 if self.logout_template is not None: 305 308 defaults['template_name'] = self.logout_template … … 311 314 Displays the login form for the given HttpRequest. 312 315 """ 313 316 from django.contrib.auth.views import login 314 context = {317 context = self.get_context_data(**{ 315 318 'title': _('Log in'), 316 319 'app_path': request.get_full_path(), 317 320 REDIRECT_FIELD_NAME: request.get_full_path(), 318 } 321 }) 319 322 context.update(extra_context or {}) 320 323 defaults = { 321 324 'extra_context': context, … … 376 379 for app in app_list: 377 380 app['models'].sort(key=lambda x: x['name']) 378 381 379 context = {382 context = self.get_context_data(**{ 380 383 'title': _('Site administration'), 381 384 'app_list': app_list, 382 } 385 }) 383 386 context.update(extra_context or {}) 384 387 return TemplateResponse(request, [ 385 388 self.index_template or 'admin/index.html', … … 428 431 raise Http404('The requested admin page does not exist.') 429 432 # Sort the models alphabetically within each app. 430 433 app_dict['models'].sort(key=lambda x: x['name']) 431 context = {434 context = self.get_context_data(**{ 432 435 'title': _('%s administration') % capfirst(app_label), 433 436 'app_list': [app_dict], 434 } 437 }) 435 438 context.update(extra_context or {}) 436 439 437 440 return TemplateResponse(request, self.app_index_template or [