Skip to content

Commit 861c665

Browse files
PeterJCLawmkurnikov
authored andcommitted
Make SuccessMessageMixin fully compatible with FormMixin (#86)
This ensures that the order in which these mixins are included into a derrived class does not matter and ends up more accurately reflecting the return type of SuccessMessageMixin in the process (its code doesn't appear to enforce that the returned response is a redirect). This provides a fix to a secondary aspect of https://github.com/mkurnikov/django-stubs/issues/79.
1 parent db7b465 commit 861c665

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Any, Dict, Optional
22

33
from django.forms.forms import BaseForm
4-
from django.http.response import HttpResponseRedirect
4+
from django.http.response import HttpResponse
55

66
class SuccessMessageMixin:
77
success_message: str = ...
8-
def form_valid(self, form: BaseForm) -> HttpResponseRedirect: ...
8+
def form_valid(self, form: BaseForm) -> HttpResponse: ...
99
def get_success_message(self, cleaned_data: Dict[str, str]) -> str: ...

test-data/typecheck/messages.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[CASE successmessagemixin_compatible_with_formmixin]
2+
from django.views.generic.edit import FormMixin
3+
from django.contrib.messages.views import SuccessMessageMixin
4+
5+
class FormFirstView(FormMixin, SuccessMessageMixin):
6+
pass
7+
8+
class SuccessMessageFirstView(FormMixin, SuccessMessageMixin):
9+
pass
10+
[/CASE]

0 commit comments

Comments
 (0)