Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

newforms-admin: Fixed #5720. render_change_form now belongs to ModelA…

…dmin and no longer uses manipulators. Thanks Brian Rosner.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6470 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 534d059e9545bf24e458121799b20ad9ff8b7247 1 parent 6104f6b
@jkocherhans jkocherhans authored
Showing with 27 additions and 32 deletions.
  1. +27 −5 django/contrib/admin/options.py
  2. +0 −27 django/contrib/admin/views/main.py
View
32 django/contrib/admin/options.py
@@ -1,6 +1,7 @@
from django import oldforms, template
from django import newforms as forms
from django.newforms.formsets import all_valid
+from django.contrib.contenttypes.models import ContentType
from django.contrib.admin import widgets
from django.contrib.admin.util import get_deleted_objects
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
@@ -449,9 +450,31 @@ def save_change(self, request, model, form, formsets=None):
request.user.message_set.create(message=msg)
return HttpResponseRedirect("../")
+ def render_change_form(self, model, context, add=False, change=False, form_url=''):
+ opts = model._meta
+ app_label = opts.app_label
+ ordered_objects = opts.get_ordered_objects()
+ extra_context = {
+ 'add': add,
+ 'change': change,
+ 'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
+ 'has_change_permission': context['perms'][app_label][opts.get_change_permission()],
+ 'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
+ 'has_absolute_url': hasattr(model, 'get_absolute_url'),
+ 'ordered_objects': ordered_objects,
+ 'form_url': form_url,
+ 'opts': opts,
+ 'content_type_id': ContentType.objects.get_for_model(model).id,
+ 'save_on_top': self.save_on_top,
+ }
+ context.update(extra_context)
+ return render_to_response([
+ "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
+ "admin/%s/change_form.html" % app_label,
+ "admin/change_form.html"], context_instance=context)
+
def add_view(self, request, form_url=''):
"The 'add' admin view for this model."
- from django.contrib.admin.views.main import render_change_form
model = self.model
opts = model._meta
app_label = opts.app_label
@@ -500,11 +523,10 @@ def add_view(self, request, form_url=''):
'media': media,
'inline_admin_formsets': inline_admin_formsets,
})
- return render_change_form(self, model, model.AddManipulator(), c, add=True)
-
+ return self.render_change_form(model, c, add=True)
+
def change_view(self, request, object_id):
"The 'change' admin view for this model."
- from django.contrib.admin.views.main import render_change_form
model = self.model
opts = model._meta
app_label = opts.app_label
@@ -576,7 +598,7 @@ def change_view(self, request, object_id):
'media': media,
'inline_admin_formsets': inline_admin_formsets,
})
- return render_change_form(self, model, model.ChangeManipulator(object_id), c, change=True)
+ return self.render_change_form(model, c, change=True)
def changelist_view(self, request):
"The 'change list' admin view for this model."
View
27 django/contrib/admin/views/main.py
@@ -3,7 +3,6 @@
from django.contrib.admin.options import IncorrectLookupParameters
from django.contrib.admin.views.decorators import staff_member_required
from django.views.decorators.cache import never_cache
-from django.contrib.contenttypes.models import ContentType
from django.core.paginator import ObjectPaginator, InvalidPage
from django.shortcuts import render_to_response
from django.db import models
@@ -110,32 +109,6 @@ def original_url(self):
return url_method()
return ''
-def render_change_form(model_admin, model, manipulator, context, add=False, change=False, form_url=''):
- opts = model._meta
- app_label = opts.app_label
- original = getattr(manipulator, 'original_object', None)
- ordered_objects = opts.get_ordered_objects()
- inline_related_objects = opts.get_followed_related_objects(manipulator.follow)
- extra_context = {
- 'add': add,
- 'change': change,
- 'has_delete_permission': context['perms'][app_label][opts.get_delete_permission()],
- 'has_change_permission': context['perms'][app_label][opts.get_change_permission()],
- 'has_file_field': True, # FIXME - this should check if form or formsets have a FileField,
- 'has_absolute_url': hasattr(model, 'get_absolute_url'),
- 'ordered_objects': ordered_objects,
- 'inline_related_objects': inline_related_objects,
- 'form_url': form_url,
- 'opts': opts,
- 'content_type_id': ContentType.objects.get_for_model(model).id,
- 'save_on_top': model_admin.save_on_top,
- }
- context.update(extra_context)
- return render_to_response([
- "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
- "admin/%s/change_form.html" % app_label,
- "admin/change_form.html"], context_instance=context)
-
def index(request):
return render_to_response('admin/index.html', {'title': ugettext('Site administration')}, context_instance=template.RequestContext(request))
index = staff_member_required(never_cache(index))
Please sign in to comment.
Something went wrong with that request. Please try again.