Code

Ticket #5720: 5720_newforms_admin_legacy_code_removal.diff

File 5720_newforms_admin_legacy_code_removal.diff, 5.4 KB (added by brosner, 7 years ago)
Line 
1=== django/contrib/admin/options.py
2==================================================================
3--- django/contrib/admin/options.py     (revision 6598)
4+++ django/contrib/admin/options.py     (local)
5@@ -1,6 +1,7 @@
6 from django import oldforms, template
7 from django import newforms as forms
8 from django.newforms.formsets import all_valid
9+from django.contrib.contenttypes.models import ContentType
10 from django.contrib.admin import widgets
11 from django.contrib.admin.util import get_deleted_objects
12 from django.core.exceptions import ImproperlyConfigured, PermissionDenied
13@@ -448,10 +449,32 @@
14         else:
15             request.user.message_set.create(message=msg)
16             return HttpResponseRedirect("../")
17+   
18+    def render_change_form(self, model, context, add=False, change=False, form_url=''):
19+        opts = model._meta
20+        app_label = opts.app_label
21+        ordered_objects = opts.get_ordered_objects()
22+        extra_context = {
23+            'add': add,
24+            'change': change,
25+            'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
26+            'has_change_permission': context['perms'][app_label][opts.get_change_permission()],
27+            'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
28+            'has_absolute_url': hasattr(model, 'get_absolute_url'),
29+            'ordered_objects': ordered_objects,
30+            'form_url': form_url,
31+            'opts': opts,
32+            'content_type_id': ContentType.objects.get_for_model(model).id,
33+            'save_on_top': self.save_on_top,
34+        }
35+        context.update(extra_context)
36+        return render_to_response([
37+            "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
38+            "admin/%s/change_form.html" % app_label,
39+            "admin/change_form.html"], context_instance=context)
40 
41     def add_view(self, request, form_url=''):
42         "The 'add' admin view for this model."
43-        from django.contrib.admin.views.main import render_change_form
44         model = self.model
45         opts = model._meta
46         app_label = opts.app_label
47@@ -500,11 +523,10 @@
48             'media': media,
49             'inline_admin_formsets': inline_admin_formsets,
50         })
51-        return render_change_form(self, model, model.AddManipulator(), c, add=True)
52-
53+        return self.render_change_form(model, c, add=True)
54+   
55     def change_view(self, request, object_id):
56         "The 'change' admin view for this model."
57-        from django.contrib.admin.views.main import render_change_form
58         model = self.model
59         opts = model._meta
60         app_label = opts.app_label
61@@ -576,7 +598,7 @@
62             'media': media,
63             'inline_admin_formsets': inline_admin_formsets,
64         })
65-        return render_change_form(self, model, model.ChangeManipulator(object_id), c, change=True)
66+        return self.render_change_form(model, c, change=True)
67 
68     def changelist_view(self, request):
69         "The 'change list' admin view for this model."
70=== django/contrib/admin/views/main.py
71==================================================================
72--- django/contrib/admin/views/main.py  (revision 6598)
73+++ django/contrib/admin/views/main.py  (local)
74@@ -3,7 +3,6 @@
75 from django.contrib.admin.options import IncorrectLookupParameters
76 from django.contrib.admin.views.decorators import staff_member_required
77 from django.views.decorators.cache import never_cache
78-from django.contrib.contenttypes.models import ContentType
79 from django.core.paginator import ObjectPaginator, InvalidPage
80 from django.shortcuts import render_to_response
81 from django.db import models
82@@ -110,37 +109,6 @@
83                 return url_method()
84         return ''
85 
86-def render_change_form(model_admin, model, manipulator, context, add=False, change=False, form_url=''):
87-    opts = model._meta
88-    app_label = opts.app_label
89-    original = getattr(manipulator, 'original_object', None)
90-    ordered_objects = opts.get_ordered_objects()
91-    inline_related_objects = opts.get_followed_related_objects(manipulator.follow)
92-    extra_context = {
93-        'add': add,
94-        'change': change,
95-        'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
96-        'has_change_permission': context['perms'][app_label][opts.get_change_permission()],
97-        'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
98-        'has_absolute_url': hasattr(model, 'get_absolute_url'),
99-        'ordered_objects': ordered_objects,
100-        'inline_related_objects': inline_related_objects,
101-        'form_url': form_url,
102-        'opts': opts,
103-        'content_type_id': ContentType.objects.get_for_model(model).id,
104-        'save_on_top': model_admin.save_on_top,
105-    }
106-    context.update(extra_context)
107-    return render_to_response([
108-        "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
109-        "admin/%s/change_form.html" % app_label,
110-        "admin/change_form.html"], context_instance=context)
111-
112-def index(request):
113-    return render_to_response('admin/index.html', {'title': ugettext('Site administration')}, context_instance=template.RequestContext(request))
114-index = staff_member_required(never_cache(index))
115-
116-
117 class ChangeList(object):
118     def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, model_admin):
119         self.model = model