mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 04:34:29 +08:00
rework django.views
This commit is contained in:
@@ -1,3 +1 @@
|
||||
from django.views.generic.base import View
|
||||
|
||||
__all__ = ["View"]
|
||||
from .generic.base import View as View
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.http.request import HttpRequest
|
||||
from django.http.response import HttpResponseForbidden
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ class SafeExceptionReporterFilter(ExceptionReporterFilter):
|
||||
class ExceptionReporter:
|
||||
request: Optional[HttpRequest] = ...
|
||||
filter: ExceptionReporterFilter = ...
|
||||
exc_type: None = ...
|
||||
exc_type: Optional[Type[BaseException]] = ...
|
||||
exc_value: Optional[str] = ...
|
||||
tb: None = ...
|
||||
tb: Optional[TracebackType] = ...
|
||||
is_email: bool = ...
|
||||
template_info: None = ...
|
||||
template_does_not_exist: bool = ...
|
||||
@@ -59,7 +59,7 @@ class ExceptionReporter:
|
||||
lineno: int,
|
||||
context_lines: int,
|
||||
loader: Optional[SourceLoader] = ...,
|
||||
module_name: Optional[str] = None,
|
||||
module_name: Optional[str] = ...,
|
||||
): ...
|
||||
|
||||
def technical_404_response(request: HttpRequest, exception: Http404) -> HttpResponse: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Callable
|
||||
|
||||
def xframe_options_deny(view_func: Callable) -> Callable: ...
|
||||
def xframe_options_sameorigin(view_func: Callable) -> Callable: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Any, Callable
|
||||
|
||||
from django.middleware.csrf import CsrfViewMiddleware
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Any, Callable
|
||||
|
||||
def sensitive_variables(*variables: Any) -> Callable: ...
|
||||
def sensitive_post_parameters(*parameters: Any) -> Callable: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Any, Callable
|
||||
|
||||
def vary_on_headers(*headers: Any) -> Callable: ...
|
||||
def vary_on_cookie(func: Callable) -> Callable: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Optional
|
||||
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.http.response import (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.views.generic.base import RedirectView as RedirectView, TemplateView as TemplateView, View as View
|
||||
from django.views.generic.dates import (
|
||||
from .base import RedirectView as RedirectView, TemplateView as TemplateView, View as View
|
||||
from .dates import (
|
||||
ArchiveIndexView as ArchiveIndexView,
|
||||
DateDetailView as DateDetailView,
|
||||
DayArchiveView as DayArchiveView,
|
||||
@@ -8,13 +8,8 @@ from django.views.generic.dates import (
|
||||
WeekArchiveView as WeekArchiveView,
|
||||
YearArchiveView as YearArchiveView,
|
||||
)
|
||||
from django.views.generic.detail import DetailView as DetailView
|
||||
from django.views.generic.edit import (
|
||||
CreateView as CreateView,
|
||||
DeleteView as DeleteView,
|
||||
FormView as FormView,
|
||||
UpdateView as UpdateView,
|
||||
)
|
||||
from django.views.generic.list import ListView as ListView
|
||||
from .detail import DetailView as DetailView
|
||||
from .edit import CreateView as CreateView, DeleteView as DeleteView, FormView as FormView, UpdateView as UpdateView
|
||||
from .list import ListView as ListView
|
||||
|
||||
class GenericViewError(Exception): ...
|
||||
|
||||
@@ -38,7 +38,6 @@ class RedirectView(View):
|
||||
def get(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: ...
|
||||
def head(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: ...
|
||||
def post(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: ...
|
||||
def options(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: ...
|
||||
def delete(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: ...
|
||||
def put(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: ...
|
||||
def patch(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> http.HttpResponse: ...
|
||||
|
||||
@@ -8,49 +8,49 @@ from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResp
|
||||
from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin
|
||||
|
||||
class YearMixin:
|
||||
year_format = ... # type: str
|
||||
year = ... # type: Optional[str]
|
||||
kwargs = ... # type: Dict[str, object]
|
||||
request = ... # type: HttpRequest
|
||||
year_format: str = ...
|
||||
year: Optional[str] = ...
|
||||
kwargs: Dict[str, Any] = ...
|
||||
request: HttpRequest = ...
|
||||
def get_year_format(self) -> str: ...
|
||||
def get_year(self) -> str: ...
|
||||
def get_next_year(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
def get_previous_year(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
|
||||
class MonthMixin:
|
||||
month_format = ... # type: str
|
||||
month = ... # type: Optional[str]
|
||||
request = ... # type: HttpRequest
|
||||
kwargs = ... # type: Dict[str, object]
|
||||
month_format: str = ...
|
||||
month: Optional[str] = ...
|
||||
request: HttpRequest = ...
|
||||
kwargs: Dict[str, Any] = ...
|
||||
def get_month_format(self) -> str: ...
|
||||
def get_month(self) -> str: ...
|
||||
def get_next_month(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
def get_previous_month(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
|
||||
class DayMixin:
|
||||
day_format = ... # type: str
|
||||
day = ... # type: Optional[str]
|
||||
request = ... # type: HttpRequest
|
||||
kwargs = ... # type: Dict[str, object]
|
||||
day_format: str = ...
|
||||
day: Optional[str] = ...
|
||||
request: HttpRequest = ...
|
||||
kwargs: Dict[str, Any] = ...
|
||||
def get_day_format(self) -> str: ...
|
||||
def get_day(self) -> str: ...
|
||||
def get_next_day(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
def get_previous_day(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
|
||||
class WeekMixin:
|
||||
week_format = ... # type: str
|
||||
week = ... # type: Optional[str]
|
||||
request = ... # type: HttpRequest
|
||||
kwargs = ... # type: Dict[str, object]
|
||||
week_format: str = ...
|
||||
week: Optional[str] = ...
|
||||
request: HttpRequest = ...
|
||||
kwargs: Dict[str, Any] = ...
|
||||
def get_week_format(self) -> str: ...
|
||||
def get_week(self) -> str: ...
|
||||
def get_next_week(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
def get_previous_week(self, date: datetime.date) -> Optional[datetime.date]: ...
|
||||
|
||||
class DateMixin:
|
||||
date_field = ... # type: Optional[str]
|
||||
allow_future = ... # type: bool
|
||||
model = ... # type: Optional[Type[models.Model]]
|
||||
date_field: Optional[str] = ...
|
||||
allow_future: bool = ...
|
||||
model: Optional[Type[models.Model]] = ...
|
||||
def get_date_field(self) -> str: ...
|
||||
def get_allow_future(self) -> bool: ...
|
||||
def uses_datetime_field(self) -> bool: ...
|
||||
@@ -58,63 +58,33 @@ class DateMixin:
|
||||
DatedItems = Tuple[Optional[Sequence[datetime.date]], Sequence[object], Dict[str, Any]]
|
||||
|
||||
class BaseDateListView(MultipleObjectMixin, DateMixin, View):
|
||||
allow_empty = ... # type: bool
|
||||
date_list_period = ... # type: str
|
||||
def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ...
|
||||
def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ...
|
||||
date_list_period: str = ...
|
||||
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
|
||||
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
def get_dated_items(self) -> DatedItems: ...
|
||||
def get_ordering(self) -> Sequence[str]: ...
|
||||
def get_dated_queryset(self, **lookup: object) -> models.query.QuerySet: ...
|
||||
def get_dated_queryset(self, **lookup: Any) -> models.query.QuerySet: ...
|
||||
def get_date_list_period(self) -> str: ...
|
||||
def get_date_list(
|
||||
self, queryset: models.query.QuerySet, date_type: str = None, ordering: str = ...
|
||||
self, queryset: models.query.QuerySet, date_type: Optional[str] = ..., ordering: str = ...
|
||||
) -> models.query.QuerySet: ...
|
||||
|
||||
class BaseArchiveIndexView(BaseDateListView):
|
||||
context_object_name = ... # type: str
|
||||
def get_dated_items(self) -> DatedItems: ...
|
||||
|
||||
class ArchiveIndexView(MultipleObjectTemplateResponseMixin, BaseArchiveIndexView):
|
||||
template_name_suffix = ... # type: str
|
||||
class BaseArchiveIndexView(BaseDateListView): ...
|
||||
class ArchiveIndexView(MultipleObjectTemplateResponseMixin, BaseArchiveIndexView): ...
|
||||
|
||||
class BaseYearArchiveView(YearMixin, BaseDateListView):
|
||||
date_list_period = ... # type: str
|
||||
make_object_list = ... # type: bool
|
||||
def get_dated_items(self) -> DatedItems: ...
|
||||
make_object_list: bool = ...
|
||||
def get_make_object_list(self) -> bool: ...
|
||||
|
||||
class YearArchiveView(MultipleObjectTemplateResponseMixin, BaseYearArchiveView):
|
||||
template_name_suffix = ... # type: str
|
||||
|
||||
class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView):
|
||||
date_list_period = ... # type: str
|
||||
def get_dated_items(self) -> DatedItems: ...
|
||||
|
||||
class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView):
|
||||
template_name_suffix = ... # type: str
|
||||
|
||||
class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView):
|
||||
def get_dated_items(self) -> DatedItems: ...
|
||||
|
||||
class WeekArchiveView(MultipleObjectTemplateResponseMixin, BaseWeekArchiveView):
|
||||
template_name_suffix = ... # type: str
|
||||
|
||||
class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView):
|
||||
def get_dated_items(self) -> DatedItems: ...
|
||||
|
||||
class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView):
|
||||
template_name_suffix = ... # type: str
|
||||
|
||||
class BaseTodayArchiveView(BaseDayArchiveView):
|
||||
def get_dated_items(self) -> DatedItems: ...
|
||||
|
||||
class TodayArchiveView(MultipleObjectTemplateResponseMixin, BaseTodayArchiveView):
|
||||
template_name_suffix = ... # type: str
|
||||
|
||||
class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailView):
|
||||
def get_object(self, queryset: models.query.QuerySet = None) -> models.Model: ...
|
||||
|
||||
class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView):
|
||||
template_name_suffix = ... # type: str
|
||||
class YearArchiveView(MultipleObjectTemplateResponseMixin, BaseYearArchiveView): ...
|
||||
class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView): ...
|
||||
class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView): ...
|
||||
class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView): ...
|
||||
class WeekArchiveView(MultipleObjectTemplateResponseMixin, BaseWeekArchiveView): ...
|
||||
class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView): ...
|
||||
class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView): ...
|
||||
class BaseTodayArchiveView(BaseDayArchiveView): ...
|
||||
class TodayArchiveView(MultipleObjectTemplateResponseMixin, BaseTodayArchiveView): ...
|
||||
class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailView): ...
|
||||
class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView): ...
|
||||
|
||||
def timezone_today() -> datetime.date: ...
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from typing import Any, Dict, List, Optional, Type
|
||||
from typing import Any, Dict, Optional, Type
|
||||
|
||||
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
||||
|
||||
from django.db import models
|
||||
from django.http import HttpResponse, HttpRequest
|
||||
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
class SingleObjectMixin(ContextMixin):
|
||||
model: Optional[Type[models.Model]] = ...
|
||||
@@ -14,11 +15,10 @@ class SingleObjectMixin(ContextMixin):
|
||||
query_pk_and_slug: bool = ...
|
||||
object: models.Model = ...
|
||||
kwargs: Dict[str, Any] = ...
|
||||
def get_object(self, queryset: Optional[models.query.QuerySet] = None) -> models.Model: ...
|
||||
def get_object(self, queryset: Optional[models.query.QuerySet] = ...) -> models.Model: ...
|
||||
def get_queryset(self) -> models.query.QuerySet: ...
|
||||
def get_slug_field(self) -> str: ...
|
||||
def get_context_object_name(self, obj: Any) -> Optional[str]: ...
|
||||
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
|
||||
|
||||
class BaseDetailView(SingleObjectMixin, View):
|
||||
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
|
||||
@@ -29,6 +29,5 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
|
||||
template_name_suffix: str = ...
|
||||
model: Optional[Type[models.Model]] = ...
|
||||
object: models.Model = ...
|
||||
def get_template_names(self) -> List[str]: ...
|
||||
|
||||
class DetailView(SingleObjectTemplateResponseMixin, BaseDetailView): ...
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Type
|
||||
from typing import Any, Dict, Optional, Sequence, Tuple, Type
|
||||
|
||||
from django.db.models import Model
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models.query import QuerySet
|
||||
from django.core.paginator import Paginator # type: ignore # This will be fixed when adding the paginator module
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
||||
|
||||
from django.db.models import Model
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
class MultipleObjectMixin(ContextMixin):
|
||||
allow_empty = ... # type: bool
|
||||
queryset = ... # type: Optional[QuerySet]
|
||||
model = ... # type: Optional[Type[Model]]
|
||||
paginate_by = ... # type: Optional[int]
|
||||
paginate_orphans = ... # type: int
|
||||
context_object_name = ... # type: Optional[str]
|
||||
paginator_class = ... # type: Type[Paginator]
|
||||
page_kwarg = ... # type: str
|
||||
ordering = ... # type: Sequence[str]
|
||||
request = ... # type: HttpRequest
|
||||
kwargs = ... # type: Dict[str, object]
|
||||
object_list = ... # type: QuerySet
|
||||
allow_empty: bool = ...
|
||||
queryset: Optional[QuerySet] = ...
|
||||
model: Optional[Type[Model]] = ...
|
||||
paginate_by: Optional[int] = ...
|
||||
paginate_orphans: int = ...
|
||||
context_object_name: Optional[str] = ...
|
||||
paginator_class: Type[Paginator] = ...
|
||||
page_kwarg: str = ...
|
||||
ordering: Sequence[str] = ...
|
||||
request: HttpRequest = ...
|
||||
kwargs: Dict[str, Any] = ...
|
||||
object_list: QuerySet = ...
|
||||
def get_queryset(self) -> QuerySet: ...
|
||||
def get_ordering(self) -> Sequence[str]: ...
|
||||
def paginate_queryset(self, queryset: QuerySet, page_size: int) -> Tuple[Paginator, int, QuerySet, bool]: ...
|
||||
@@ -29,16 +30,13 @@ class MultipleObjectMixin(ContextMixin):
|
||||
def get_paginate_orphans(self) -> int: ...
|
||||
def get_allow_empty(self) -> bool: ...
|
||||
def get_context_object_name(self, object_list: QuerySet) -> Optional[str]: ...
|
||||
def get_context_data(self, **kwargs: object) -> Dict[str, Any]: ...
|
||||
|
||||
class BaseListView(MultipleObjectMixin, View):
|
||||
object_list = ... # type: QuerySet
|
||||
def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ...
|
||||
def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ...
|
||||
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
|
||||
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
|
||||
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
||||
template_name_suffix = ... # type: str
|
||||
object_list = ... # type: QuerySet
|
||||
def get_template_names(self) -> List[str]: ...
|
||||
template_name_suffix: str = ...
|
||||
object_list: QuerySet = ...
|
||||
|
||||
class ListView(MultipleObjectTemplateResponseMixin, BaseListView): ...
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from typing import Any, Callable, Dict, List, Optional, Union
|
||||
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.http.request import HttpRequest
|
||||
from django.http.response import HttpResponse
|
||||
from django.utils.translation.trans_real import DjangoTranslation
|
||||
|
||||
from django.views.generic import View
|
||||
|
||||
LANGUAGE_QUERY_PARAMETER: str
|
||||
|
||||
def set_language(request: WSGIRequest) -> HttpResponse: ...
|
||||
def set_language(request: HttpRequest) -> HttpResponse: ...
|
||||
def get_formats() -> Dict[str, Union[List[str], int, str]]: ...
|
||||
|
||||
js_catalog_template: str
|
||||
@@ -15,21 +17,15 @@ def render_javascript_catalog(catalog: Optional[Any] = ..., plural: Optional[Any
|
||||
def null_javascript_catalog(request: Any, domain: Optional[Any] = ..., packages: Optional[Any] = ...): ...
|
||||
|
||||
class JavaScriptCatalog(View):
|
||||
args: Tuple
|
||||
head: Callable
|
||||
kwargs: Dict[Any, Any]
|
||||
request: WSGIRequest
|
||||
domain: str = ...
|
||||
packages: List[str] = ...
|
||||
translation: django.utils.translation.trans_real.DjangoTranslation = ...
|
||||
def get(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
translation: DjangoTranslation = ...
|
||||
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
def get_paths(self, packages: List[str]) -> List[str]: ...
|
||||
def get_plural(self) -> None: ...
|
||||
def get_catalog(self) -> Dict[str, Union[List[str], str]]: ...
|
||||
def get_context_data(self, **kwargs: Any) -> Dict[str, Optional[Dict[str, Union[List[str], int, str]]]]: ...
|
||||
def render_to_response(
|
||||
self, context: Dict[str, Optional[Dict[str, Union[List[str], int, str]]]], **response_kwargs: Any
|
||||
) -> HttpResponse: ...
|
||||
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
|
||||
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any) -> HttpResponse: ...
|
||||
|
||||
class JSONCatalog(JavaScriptCatalog):
|
||||
def render_to_response(self, context: Any, **response_kwargs: Any): ...
|
||||
class JSONCatalog(JavaScriptCatalog): ...
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.http.request import HttpRequest
|
||||
from django.http.response import FileResponse
|
||||
|
||||
def serve(request: WSGIRequest, path: str, document_root: str = ..., show_indexes: bool = ...) -> FileResponse: ...
|
||||
def serve(request: HttpRequest, path: str, document_root: str = ..., show_indexes: bool = ...) -> FileResponse: ...
|
||||
|
||||
DEFAULT_DIRECTORY_INDEX_TEMPLATE: str
|
||||
template_translatable: Any
|
||||
|
||||
Reference in New Issue
Block a user