forms, generic views fixes

This commit is contained in:
Maxim Kurnikov
2019-02-20 22:24:26 +03:00
parent 14ea848dd7
commit 2bd018951b
2 changed files with 33 additions and 59 deletions

View File

@@ -5,31 +5,30 @@ from django.http import HttpResponse, HttpRequest
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
class SingleObjectMixin(ContextMixin): class SingleObjectMixin(ContextMixin):
model = ... # type: Optional[Type[models.Model]] model: Optional[Type[models.Model]] = ...
queryset = ... # type: Optional[models.query.QuerySet] queryset: Optional[models.query.QuerySet] = ...
slug_field = ... # type: str slug_field: str = ...
context_object_name = ... # type: Optional[str] context_object_name: Optional[str] = ...
slug_url_kwarg = ... # type: str slug_url_kwarg: str = ...
pk_url_kwarg = ... # type: str pk_url_kwarg: str = ...
query_pk_and_slug = ... # type: bool query_pk_and_slug: bool = ...
object = ... # type: models.Model object: models.Model = ...
kwargs = ... # type: Dict[str, object] kwargs: Dict[str, Any] = ...
def get_object(self, queryset: models.query.QuerySet = None) -> models.Model: ... def get_object(self, queryset: Optional[models.query.QuerySet] = None) -> models.Model: ...
def get_queryset(self) -> models.query.QuerySet: ... def get_queryset(self) -> models.query.QuerySet: ...
def get_slug_field(self) -> str: ... def get_slug_field(self) -> str: ...
def get_context_object_name(self, obj: Any) -> Optional[str]: ... def get_context_object_name(self, obj: Any) -> Optional[str]: ...
def get_context_data(self, **kwargs: object) -> Dict[str, Any]: ... def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
class BaseDetailView(SingleObjectMixin, View): class BaseDetailView(SingleObjectMixin, View):
def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ... def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
object = ... # type: models.Model def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ...
class SingleObjectTemplateResponseMixin(TemplateResponseMixin): class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
template_name_field = ... # type: Optional[str] template_name_field: Optional[str] = ...
template_name_suffix = ... # type: str template_name_suffix: str = ...
model = ... # type: Optional[Type[models.Model]] model: Optional[Type[models.Model]] = ...
object = ... # type: models.Model object: models.Model = ...
def get_template_names(self) -> List[str]: ... def get_template_names(self) -> List[str]: ...
class DetailView(SingleObjectTemplateResponseMixin, BaseDetailView): ... class DetailView(SingleObjectTemplateResponseMixin, BaseDetailView): ...

View File

@@ -1,14 +1,12 @@
from typing import Any, Callable, Dict, Optional, Sequence, Type, Union from typing import Any, Callable, Dict, Optional, Sequence, Type, Union
from django.db import models
from django.forms.forms import BaseForm from django.forms.forms import BaseForm
from django.http import HttpRequest, HttpResponse
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
from django.views.generic.detail import BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin from django.views.generic.detail import BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin
from typing_extensions import Literal from typing_extensions import Literal
from django.db import models
from django.forms import Form
from django.http import HttpRequest, HttpResponse
class FormMixin(ContextMixin): class FormMixin(ContextMixin):
initial: Dict[str, Any] = ... initial: Dict[str, Any] = ...
form_class: Optional[Type[BaseForm]] = ... form_class: Optional[Type[BaseForm]] = ...
@@ -18,61 +16,38 @@ class FormMixin(ContextMixin):
def render_to_response(self, context: Dict[str, Any], **response_kwargs: object) -> HttpResponse: ... def render_to_response(self, context: Dict[str, Any], **response_kwargs: object) -> HttpResponse: ...
def get_initial(self) -> Dict[str, Any]: ... def get_initial(self) -> Dict[str, Any]: ...
def get_prefix(self) -> Optional[str]: ... def get_prefix(self) -> Optional[str]: ...
def get_form_class(self) -> Type[Form]: ... def get_form_class(self) -> Type[BaseForm]: ...
def get_form(self, form_class: Type[Form] = None) -> Form: ... def get_form(self, form_class: Optional[Type[BaseForm]] = None) -> BaseForm: ...
def get_form_kwargs(self) -> Dict[str, Any]: ... def get_form_kwargs(self) -> Dict[str, Any]: ...
def get_success_url(self) -> str: ... def get_success_url(self) -> str: ...
def form_valid(self, form: Form) -> HttpResponse: ... def form_valid(self, form: BaseForm) -> HttpResponse: ...
def form_invalid(self, form: Form) -> HttpResponse: ... def form_invalid(self, form: BaseForm) -> HttpResponse: ...
def get_context_data(self, **kwargs: object) -> Dict[str, Any]: ...
class ModelFormMixin(FormMixin, SingleObjectMixin): class ModelFormMixin(FormMixin, SingleObjectMixin):
fields: Optional[Union[Sequence[str], Literal["__all__"]]] = ... fields: Optional[Union[Sequence[str], Literal["__all__"]]] = ...
object: models.Model = ...
def get_form_class(self) -> Type[Form]: ...
def get_form_kwargs(self) -> Dict[str, object]: ...
def get_success_url(self) -> str: ...
def form_valid(self, form: Form) -> HttpResponse: ...
class ProcessFormView(View): class ProcessFormView(View):
def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ... def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
def get_context_data(self, **kwargs: object) -> Dict[str, Any]: ... def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
def get_form(self, form_class: Type[Form] = None) -> Form: ...
def form_valid(self, form: Form) -> HttpResponse: ...
def form_invalid(self, form: Form) -> HttpResponse: ...
def get(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ... def get(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ... def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def put(self, *args: str, **kwargs: Any) -> HttpResponse: ... def put(self, *args: str, **kwargs: Any) -> HttpResponse: ...
class BaseFormView(FormMixin, ProcessFormView): ... class BaseFormView(FormMixin, ProcessFormView): ...
class FormView(TemplateResponseMixin, BaseFormView): ... class FormView(TemplateResponseMixin, BaseFormView): ...
class BaseCreateView(ModelFormMixin, ProcessFormView): ...
class BaseCreateView(ModelFormMixin, ProcessFormView): class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView): ...
object = ... # type: models.Model class BaseUpdateView(ModelFormMixin, ProcessFormView): ...
def get(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ... class UpdateView(SingleObjectTemplateResponseMixin, BaseUpdateView): ...
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView):
template_name_suffix = ... # type: str
class BaseUpdateView(ModelFormMixin, ProcessFormView):
object = ... # type: models.Model
def get(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
class UpdateView(SingleObjectTemplateResponseMixin, BaseUpdateView):
template_name_suffix = ... # type: str
_object = object _object = object
class DeletionMixin: class DeletionMixin:
success_url = ... # type: Optional[str] success_url: Optional[str] = ...
object = ... # type: models.Model object: models.Model = ...
def delete(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ... def post(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def delete(self, request: HttpRequest, *args: str, **kwargs: Any) -> HttpResponse: ...
def get_success_url(self) -> str: ... def get_success_url(self) -> str: ...
class BaseDeleteView(DeletionMixin, BaseDetailView): ... class BaseDeleteView(DeletionMixin, BaseDetailView): ...
class DeleteView(SingleObjectTemplateResponseMixin, BaseDeleteView): ...
class DeleteView(SingleObjectTemplateResponseMixin, BaseDeleteView):
template_name_suffix = ... # type: str