From 003081468e28db5af4d7c983f4d8df4c74c20607 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 13 Jan 2023 09:55:34 +0100 Subject: [PATCH] Refs #33263 -- Removed warning in BaseDeleteView when delete() method is overridden. --- django/views/generic/edit.py | 20 -------------------- tests/generic_views/test_edit.py | 26 +------------------------- 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py index e1f37bc593..97934f58cb 100644 --- a/django/views/generic/edit.py +++ b/django/views/generic/edit.py @@ -1,5 +1,3 @@ -import warnings - from django.core.exceptions import ImproperlyConfigured from django.forms import Form from django.forms import models as model_forms @@ -240,11 +238,6 @@ class DeletionMixin: raise ImproperlyConfigured("No URL to redirect to. Provide a success_url.") -# RemovedInDjango50Warning. -class DeleteViewCustomDeleteWarning(Warning): - pass - - class BaseDeleteView(DeletionMixin, FormMixin, BaseDetailView): """ Base view for deleting an object. @@ -254,19 +247,6 @@ class BaseDeleteView(DeletionMixin, FormMixin, BaseDetailView): form_class = Form - def __init__(self, *args, **kwargs): - # RemovedInDjango50Warning. - if self.__class__.delete is not DeletionMixin.delete: - warnings.warn( - f"DeleteView uses FormMixin to handle POST requests. As a " - f"consequence, any custom deletion logic in " - f"{self.__class__.__name__}.delete() handler should be moved " - f"to form_valid().", - DeleteViewCustomDeleteWarning, - stacklevel=2, - ) - super().__init__(*args, **kwargs) - def post(self, request, *args, **kwargs): # Set self.object before the usual form processing flow. # Inlined because having DeletionMixin as the first base, for diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py index 6200dd08d5..09d887ae92 100644 --- a/tests/generic_views/test_edit.py +++ b/tests/generic_views/test_edit.py @@ -4,13 +4,7 @@ from django.test import SimpleTestCase, TestCase, override_settings from django.test.client import RequestFactory from django.urls import reverse from django.views.generic.base import View -from django.views.generic.edit import ( - CreateView, - DeleteView, - DeleteViewCustomDeleteWarning, - FormMixin, - ModelFormMixin, -) +from django.views.generic.edit import CreateView, FormMixin, ModelFormMixin from . import views from .forms import AuthorForm @@ -476,21 +470,3 @@ class DeleteViewTests(TestCase): res.context_data["form"].errors["confirm"], ["This field is required."], ) - - # RemovedInDjango50Warning. - def test_delete_with_custom_delete(self): - class AuthorDeleteView(DeleteView): - model = Author - - def delete(self, request, *args, **kwargs): - # Custom logic. - pass - - msg = ( - "DeleteView uses FormMixin to handle POST requests. As a " - "consequence, any custom deletion logic in " - "AuthorDeleteView.delete() handler should be moved to " - "form_valid()." - ) - with self.assertWarnsMessage(DeleteViewCustomDeleteWarning, msg): - AuthorDeleteView()