Changed django.views.admin.main to use get_object_or_404 and render_to_response, to cut on code
git-svn-id: http://code.djangoproject.com/svn/django/trunk@674 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
58641f8068
commit
a089b8f620
|
@ -3,6 +3,7 @@
|
||||||
from django.core import formfields, meta, template_loader
|
from django.core import formfields, meta, template_loader
|
||||||
from django.core.exceptions import Http404, ObjectDoesNotExist, PermissionDenied
|
from django.core.exceptions import Http404, ObjectDoesNotExist, PermissionDenied
|
||||||
from django.core.extensions import DjangoContext as Context
|
from django.core.extensions import DjangoContext as Context
|
||||||
|
from django.core.extensions import get_object_or_404, render_to_response
|
||||||
from django.models.auth import log
|
from django.models.auth import log
|
||||||
from django.utils.html import strip_tags
|
from django.utils.html import strip_tags
|
||||||
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
|
||||||
|
@ -46,9 +47,7 @@ def get_query_string(original_params, new_params={}, remove=[]):
|
||||||
return '?' + '&'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')
|
return '?' + '&'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
t = template_loader.get_template('index')
|
return render_to_response('index', {'title': 'Site administration'}, context_instance=Context(request))
|
||||||
c = Context(request, {'title': 'Site administration'})
|
|
||||||
return HttpResponse(t.render(c))
|
|
||||||
|
|
||||||
def change_list(request, app_label, module_name):
|
def change_list(request, app_label, module_name):
|
||||||
from django.core import paginator
|
from django.core import paginator
|
||||||
|
@ -1065,10 +1064,7 @@ def delete_stage(request, app_label, module_name, object_id):
|
||||||
mod, opts = _get_mod_opts(app_label, module_name)
|
mod, opts = _get_mod_opts(app_label, module_name)
|
||||||
if not request.user.has_perm(app_label + '.' + opts.get_delete_permission()):
|
if not request.user.has_perm(app_label + '.' + opts.get_delete_permission()):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
try:
|
obj = get_object_or_404(mod, pk=object_id)
|
||||||
obj = mod.get_object(pk=object_id)
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
# Populate deleted_objects, a data structure of all related objects that
|
# Populate deleted_objects, a data structure of all related objects that
|
||||||
# will also be deleted.
|
# will also be deleted.
|
||||||
|
@ -1084,30 +1080,23 @@ def delete_stage(request, app_label, module_name, object_id):
|
||||||
log.log_action(request.user.id, opts.get_content_type_id(), object_id, obj_repr, log.DELETION)
|
log.log_action(request.user.id, opts.get_content_type_id(), object_id, obj_repr, log.DELETION)
|
||||||
request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr))
|
request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr))
|
||||||
return HttpResponseRedirect("../../")
|
return HttpResponseRedirect("../../")
|
||||||
t = template_loader.get_template("delete_confirmation_generic")
|
return render_to_response('delete_confirmation_generic', {
|
||||||
c = Context(request, {
|
|
||||||
"title": "Are you sure?",
|
"title": "Are you sure?",
|
||||||
"object_name": opts.verbose_name,
|
"object_name": opts.verbose_name,
|
||||||
"object": obj,
|
"object": obj,
|
||||||
"deleted_objects": deleted_objects,
|
"deleted_objects": deleted_objects,
|
||||||
"perms_lacking": perms_needed,
|
"perms_lacking": perms_needed,
|
||||||
})
|
}, context_instance=Context(request))
|
||||||
return HttpResponse(t.render(c))
|
|
||||||
|
|
||||||
def history(request, app_label, module_name, object_id):
|
def history(request, app_label, module_name, object_id):
|
||||||
mod, opts = _get_mod_opts(app_label, module_name)
|
mod, opts = _get_mod_opts(app_label, module_name)
|
||||||
action_list = log.get_list(object_id__exact=object_id, content_type__id__exact=opts.get_content_type_id(),
|
action_list = log.get_list(object_id__exact=object_id, content_type__id__exact=opts.get_content_type_id(),
|
||||||
order_by=("action_time",), select_related=True)
|
order_by=("action_time",), select_related=True)
|
||||||
# If no history was found, see whether this object even exists.
|
# If no history was found, see whether this object even exists.
|
||||||
try:
|
obj = get_object_or_404(mod, pk=object_id)
|
||||||
obj = mod.get_object(pk=object_id)
|
return render_to_response('admin_object_history', {
|
||||||
except ObjectDoesNotExist:
|
|
||||||
raise Http404
|
|
||||||
t = template_loader.get_template('admin_object_history')
|
|
||||||
c = Context(request, {
|
|
||||||
'title': 'Change history: %r' % obj,
|
'title': 'Change history: %r' % obj,
|
||||||
'action_list': action_list,
|
'action_list': action_list,
|
||||||
'module_name': capfirst(opts.verbose_name_plural),
|
'module_name': capfirst(opts.verbose_name_plural),
|
||||||
'object': obj,
|
'object': obj,
|
||||||
})
|
}, context_instance=Context(request))
|
||||||
return HttpResponse(t.render(c))
|
|
||||||
|
|
Loading…
Reference in New Issue