1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Removed using argument from admin's get_deleted_objects().

This commit is contained in:
Tim Graham 2018-02-23 12:47:36 -05:00
parent 0fa6ab8c18
commit 9822d88ca0
3 changed files with 10 additions and 9 deletions

View File

@ -6,7 +6,6 @@ from django.contrib import messages
from django.contrib.admin import helpers from django.contrib.admin import helpers
from django.contrib.admin.utils import get_deleted_objects, model_ngettext from django.contrib.admin.utils import get_deleted_objects, model_ngettext
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.db import router
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.translation import gettext as _, gettext_lazy from django.utils.translation import gettext as _, gettext_lazy
@ -28,12 +27,10 @@ def delete_selected(modeladmin, request, queryset):
if not modeladmin.has_delete_permission(request): if not modeladmin.has_delete_permission(request):
raise PermissionDenied raise PermissionDenied
using = router.db_for_write(modeladmin.model)
# Populate deletable_objects, a data structure of all related objects that # Populate deletable_objects, a data structure of all related objects that
# will also be deleted. # will also be deleted.
deletable_objects, model_count, perms_needed, protected = get_deleted_objects( deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, request.user, modeladmin.admin_site, using, queryset, request.user, modeladmin.admin_site,
) )
# The user has already confirmed the deletion. # The user has already confirmed the deletion.

View File

@ -1750,12 +1750,10 @@ class ModelAdmin(BaseModelAdmin):
if obj is None: if obj is None:
return self._get_obj_does_not_exist_redirect(request, opts, object_id) return self._get_obj_does_not_exist_redirect(request, opts, object_id)
using = router.db_for_write(self.model)
# 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.
deleted_objects, model_count, perms_needed, protected = get_deleted_objects( deleted_objects, model_count, perms_needed, protected = get_deleted_objects(
[obj], request.user, self.admin_site, using, [obj], request.user, self.admin_site,
) )
if request.POST and not protected: # The user has confirmed the deletion. if request.POST and not protected: # The user has confirmed the deletion.

View File

@ -4,7 +4,7 @@ from collections import defaultdict
from django.contrib.auth import get_permission_codename from django.contrib.auth import get_permission_codename
from django.core.exceptions import FieldDoesNotExist from django.core.exceptions import FieldDoesNotExist
from django.db import models from django.db import models, router
from django.db.models.constants import LOOKUP_SEP from django.db.models.constants import LOOKUP_SEP
from django.db.models.deletion import Collector from django.db.models.deletion import Collector
from django.forms.utils import pretty_name from django.forms.utils import pretty_name
@ -117,7 +117,7 @@ def flatten_fieldsets(fieldsets):
return field_names return field_names
def get_deleted_objects(objs, user, admin_site, using): def get_deleted_objects(objs, user, admin_site):
""" """
Find all objects related to ``objs`` that should also be deleted. ``objs`` Find all objects related to ``objs`` that should also be deleted. ``objs``
must be a homogeneous iterable of objects (e.g. a QuerySet). must be a homogeneous iterable of objects (e.g. a QuerySet).
@ -125,6 +125,12 @@ def get_deleted_objects(objs, user, admin_site, using):
Return a nested list of strings suitable for display in the Return a nested list of strings suitable for display in the
template with the ``unordered_list`` filter. template with the ``unordered_list`` filter.
""" """
try:
obj = objs[0]
except IndexError:
return [], {}, set(), []
else:
using = router.db_for_write(obj._meta.model)
collector = NestedObjects(using=using) collector = NestedObjects(using=using)
collector.collect(objs) collector.collect(objs)
perms_needed = set() perms_needed = set()