Ticket #5720: 5720_newforms_admin_legacy_code_removal.diff

File 5720_newforms_admin_legacy_code_removal.diff, 5.4 KB (added by Brian Rosner, 17 years ago)
  • django/contrib/admin/options.py

    === django/contrib/admin/options.py
    ==================================================================
     
    11from django import oldforms, template
    22from django import newforms as forms
    33from django.newforms.formsets import all_valid
     4from django.contrib.contenttypes.models import ContentType
    45from django.contrib.admin import widgets
    56from django.contrib.admin.util import get_deleted_objects
    67from django.core.exceptions import ImproperlyConfigured, PermissionDenied
     
    448449        else:
    449450            request.user.message_set.create(message=msg)
    450451            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)
    451475
    452476    def add_view(self, request, form_url=''):
    453477        "The 'add' admin view for this model."
    454         from django.contrib.admin.views.main import render_change_form
    455478        model = self.model
    456479        opts = model._meta
    457480        app_label = opts.app_label
     
    500523            'media': media,
    501524            'inline_admin_formsets': inline_admin_formsets,
    502525        })
    503         return render_change_form(self, model, model.AddManipulator(), c, add=True)
    504 
     526        return self.render_change_form(model, c, add=True)
     527   
    505528    def change_view(self, request, object_id):
    506529        "The 'change' admin view for this model."
    507         from django.contrib.admin.views.main import render_change_form
    508530        model = self.model
    509531        opts = model._meta
    510532        app_label = opts.app_label
     
    576598            'media': media,
    577599            'inline_admin_formsets': inline_admin_formsets,
    578600        })
    579         return render_change_form(self, model, model.ChangeManipulator(object_id), c, change=True)
     601        return self.render_change_form(model, c, change=True)
    580602
    581603    def changelist_view(self, request):
    582604        "The 'change list' admin view for this model."
  • django/contrib/admin/views/main.py

    === django/contrib/admin/views/main.py
    ==================================================================
     
    33from django.contrib.admin.options import IncorrectLookupParameters
    44from django.contrib.admin.views.decorators import staff_member_required
    55from django.views.decorators.cache import never_cache
    6 from django.contrib.contenttypes.models import ContentType
    76from django.core.paginator import ObjectPaginator, InvalidPage
    87from django.shortcuts import render_to_response
    98from django.db import models
     
    110109                return url_method()
    111110        return ''
    112111
    113 def render_change_form(model_admin, model, manipulator, context, add=False, change=False, form_url=''):
    114     opts = model._meta
    115     app_label = opts.app_label
    116     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 
    144112class ChangeList(object):
    145113    def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, model_admin):
    146114        self.model = model
Back to Top