<commit_before>from django.core.exceptions import PermissionDenied
from django.db import transaction, router
from django.http import Http404, HttpResponseRedirect
from django.template.response import TemplateResponse
from django import VERSION as django_version
from django.utils import six
from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.translation import ugettext as _
from django.contrib.admin.utils import get_deleted_objects

from xadmin.util import unquote
from xadmin.views.edit import UpdateAdminView
from xadmin.views.detail import DetailAdminView
from xadmin.views.base import ModelAdminView, filter_hook, csrf_protect_m


class DeleteAdminView(ModelAdminView):
    delete_confirmation_template = None

    def __init__(self, request, *args, **kwargs):
        if django_version > (2, 0):
            admin_site_registry = self.admin_site._registry
            for model in admin_site_registry:
                if not hasattr(admin_site_registry[model], 'has_delete_permission'):
                    setattr(admin_site_registry[model], 'has_delete_permission', self.has_delete_permission)
        super(DeleteAdminView, self).__init__(request, *args, **kwargs)

    def init_request(self, object_id, *args, **kwargs):
        """The 'delete' admin view for this model."""
        self.obj = self.get_object(unquote(object_id))

        if not self.has_delete_permission(self.obj):
            raise PermissionDenied

        if self.obj is None:
            raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.opts.verbose_name), 'key': escape(object_id)})

        using = router.db_for_write(self.model)

        # Populate deleted_objects, a data structure of all related objects that
        # will also be deleted.
        self.deleted_objects, model_count, self.perms_needed, self.protected = get_deleted_objects(
            [self.obj], self, self.admin_site)<commit_msg>Exposing 'get_deleted_objects' as a hook for plugins.<commit_after>from django.core.exceptions import PermissionDenied
from django.db import transaction, router
from django.http import Http404, HttpResponseRedirect
from django.template.response import TemplateResponse
from django import VERSION as django_version
from django.utils import six
from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.translation import ugettext as _
from django.contrib.admin.utils import get_deleted_objects

from xadmin.util import unquote
from xadmin.views.edit import UpdateAdminView
from xadmin.views.detail import DetailAdminView
from xadmin.views.base import ModelAdminView, filter_hook, csrf_protect_m


class DeleteAdminView(ModelAdminView):
    delete_confirmation_template = None

    def __init__(self, request, *args, **kwargs):
        if django_version > (2, 0):
            admin_site_registry = self.admin_site._registry
            for model in admin_site_registry:
                if not hasattr(admin_site_registry[model], 'has_delete_permission'):
                    setattr(admin_site_registry[model], 'has_delete_permission', self.has_delete_permission)
        super(DeleteAdminView, self).__init__(request, *args, **kwargs)

    def init_request(self, object_id, *args, **kwargs):
        """The 'delete' admin view for this model."""
        self.obj = self.get_object(unquote(object_id))

        if not self.has_delete_permission(self.obj):
            raise PermissionDenied

        if self.obj is None:
            raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.opts.verbose_name), 'key': escape(object_id)})

        using = router.db_for_write(self.model)

        # Populate deleted_objects, a data structure of all related objects that
        # will also be deleted.
        self.deleted_objects, model_count, self.perms_needed, self.protected = self.get_deleted_objects()

    @filter_hook
    def get_deleted_objects(self):
        # Populate deleted_objects, a data structure of all related objects that
        # will also be deleted.
        deleted_objects, model_count, perms_needed, protected = \
            get_deleted_objects([self.obj], self, self.admin_site)
        return deleted_objects, model_count, perms_needed, protected
{'fraction_non_alphanumeric': 0.08090094231211216, 'fraction_numerical': 0.0036773155596414617, 'mean_word_length': 3.8898876404494382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3270839', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1182, 'n_words': 339}