mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-09 21:46:43 +08:00
Allow form.save() in CreateView / UpdateView (#374)
This commit is contained in:
@@ -1,28 +1,35 @@
|
||||
from typing import Any, Callable, Dict, Optional, Sequence, Type, Union
|
||||
|
||||
from django.forms.forms import BaseForm
|
||||
from django.forms.models import BaseModelForm
|
||||
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
||||
from django.views.generic.detail import BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin
|
||||
from typing_extensions import Literal
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
class FormMixin(ContextMixin):
|
||||
class AbstractFormMixin(ContextMixin):
|
||||
initial: Dict[str, Any] = ...
|
||||
form_class: Optional[Type[BaseForm]] = ...
|
||||
success_url: Optional[Union[str, Callable[..., Any]]] = ...
|
||||
prefix: Optional[str] = ...
|
||||
def get_initial(self) -> Dict[str, Any]: ...
|
||||
def get_prefix(self) -> Optional[str]: ...
|
||||
def get_form_class(self) -> Type[BaseForm]: ...
|
||||
def get_form(self, form_class: Optional[Type[BaseForm]] = ...) -> BaseForm: ...
|
||||
def get_form_kwargs(self) -> Dict[str, Any]: ...
|
||||
def get_success_url(self) -> str: ...
|
||||
|
||||
class FormMixin(AbstractFormMixin):
|
||||
def get_form_class(self) -> Type[BaseForm]: ...
|
||||
def get_form(self, form_class: Optional[Type[BaseForm]] = ...) -> BaseForm: ...
|
||||
def form_valid(self, form: BaseForm) -> HttpResponse: ...
|
||||
def form_invalid(self, form: BaseForm) -> HttpResponse: ...
|
||||
|
||||
class ModelFormMixin(FormMixin, SingleObjectMixin):
|
||||
class ModelFormMixin(AbstractFormMixin, SingleObjectMixin):
|
||||
fields: Optional[Union[Sequence[str], Literal["__all__"]]] = ...
|
||||
def get_form_class(self) -> Type[BaseModelForm]: ...
|
||||
def get_form(self, form_class: Optional[Type[BaseModelForm]] = ...) -> BaseModelForm: ...
|
||||
def form_valid(self, form: BaseModelForm) -> HttpResponse: ...
|
||||
def form_invalid(self, form: BaseModelForm) -> HttpResponse: ...
|
||||
|
||||
class ProcessFormView(View):
|
||||
def get(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
|
||||
|
||||
@@ -46,6 +46,18 @@
|
||||
reveal_type(self.get_form(form_class)) # N: Revealed type is 'main.MyForm'
|
||||
reveal_type(self.get_form(MyForm2)) # N: Revealed type is 'main.MyForm2'
|
||||
|
||||
- case: updateview_form_valid_has_form_save
|
||||
main: |
|
||||
from django import forms
|
||||
from django.views.generic.edit import UpdateView
|
||||
|
||||
class MyForm(forms.ModelForm):
|
||||
pass
|
||||
class MyView(UpdateView):
|
||||
form_class = MyForm
|
||||
def form_valid(self, form: forms.BaseModelForm):
|
||||
reveal_type(form.save) # N: Revealed type is 'def (commit: builtins.bool =) -> Any'
|
||||
|
||||
- case: successmessagemixin_compatible_with_formmixin
|
||||
main: |
|
||||
from django.views.generic.edit import FormMixin
|
||||
|
||||
Reference in New Issue
Block a user