mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #33263 -- Removed warning in BaseDeleteView when delete() method is overridden.
This commit is contained in:
parent
94ad46e9d8
commit
003081468e
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user