Ticket #5720: 5720_newforms_admin_legacy_code_removal.diff
File 5720_newforms_admin_legacy_code_removal.diff, 5.4 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
=== django/contrib/admin/options.py ==================================================================
1 1 from django import oldforms, template 2 2 from django import newforms as forms 3 3 from django.newforms.formsets import all_valid 4 from django.contrib.contenttypes.models import ContentType 4 5 from django.contrib.admin import widgets 5 6 from django.contrib.admin.util import get_deleted_objects 6 7 from django.core.exceptions import ImproperlyConfigured, PermissionDenied … … 448 449 else: 449 450 request.user.message_set.create(message=msg) 450 451 return HttpResponseRedirect("../") 452 453 def render_change_form(self, model, context, add=False, change=False, form_url=''): 454 opts = model._meta 455 app_label = opts.app_label 456 ordered_objects = opts.get_ordered_objects() 457 extra_context = { 458 'add': add, 459 'change': change, 460 'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()], 461 'has_change_permission': context['perms'][app_label][opts.get_change_permission()], 462 'has_file_field': True, # FIXME - this should check if form or formsets have a FileField, 463 'has_absolute_url': hasattr(model, 'get_absolute_url'), 464 'ordered_objects': ordered_objects, 465 'form_url': form_url, 466 'opts': opts, 467 'content_type_id': ContentType.objects.get_for_model(model).id, 468 'save_on_top': self.save_on_top, 469 } 470 context.update(extra_context) 471 return render_to_response([ 472 "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), 473 "admin/%s/change_form.html" % app_label, 474 "admin/change_form.html"], context_instance=context) 451 475 452 476 def add_view(self, request, form_url=''): 453 477 "The 'add' admin view for this model." 454 from django.contrib.admin.views.main import render_change_form455 478 model = self.model 456 479 opts = model._meta 457 480 app_label = opts.app_label … … 500 523 'media': media, 501 524 'inline_admin_formsets': inline_admin_formsets, 502 525 }) 503 return render_change_form(self, model, model.AddManipulator(), c, add=True)504 526 return self.render_change_form(model, c, add=True) 527 505 528 def change_view(self, request, object_id): 506 529 "The 'change' admin view for this model." 507 from django.contrib.admin.views.main import render_change_form508 530 model = self.model 509 531 opts = model._meta 510 532 app_label = opts.app_label … … 576 598 'media': media, 577 599 'inline_admin_formsets': inline_admin_formsets, 578 600 }) 579 return render_change_form(self, model, model.ChangeManipulator(object_id), c, change=True)601 return self.render_change_form(model, c, change=True) 580 602 581 603 def changelist_view(self, request): 582 604 "The 'change list' admin view for this model." -
django/contrib/admin/views/main.py
=== django/contrib/admin/views/main.py ==================================================================
3 3 from django.contrib.admin.options import IncorrectLookupParameters 4 4 from django.contrib.admin.views.decorators import staff_member_required 5 5 from django.views.decorators.cache import never_cache 6 from django.contrib.contenttypes.models import ContentType7 6 from django.core.paginator import ObjectPaginator, InvalidPage 8 7 from django.shortcuts import render_to_response 9 8 from django.db import models … … 110 109 return url_method() 111 110 return '' 112 111 113 def render_change_form(model_admin, model, manipulator, context, add=False, change=False, form_url=''):114 opts = model._meta115 app_label = opts.app_label116 original = getattr(manipulator, 'original_object', None)117 ordered_objects = opts.get_ordered_objects()118 inline_related_objects = opts.get_followed_related_objects(manipulator.follow)119 extra_context = {120 'add': add,121 'change': change,122 'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],123 'has_change_permission': context['perms'][app_label][opts.get_change_permission()],124 'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,125 'has_absolute_url': hasattr(model, 'get_absolute_url'),126 'ordered_objects': ordered_objects,127 'inline_related_objects': inline_related_objects,128 'form_url': form_url,129 'opts': opts,130 'content_type_id': ContentType.objects.get_for_model(model).id,131 'save_on_top': model_admin.save_on_top,132 }133 context.update(extra_context)134 return render_to_response([135 "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),136 "admin/%s/change_form.html" % app_label,137 "admin/change_form.html"], context_instance=context)138 139 def index(request):140 return render_to_response('admin/index.html', {'title': ugettext('Site administration')}, context_instance=template.RequestContext(request))141 index = staff_member_required(never_cache(index))142 143 144 112 class ChangeList(object): 145 113 def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, model_admin): 146 114 self.model = model