Large update (#909)

* Make module declaration precise.

* Make settings match real file.

* Replace `include` with import.

* Make types more specific.

* Replace `WSGIRequest` with `HttpRequest` where possible.

* Replace all `OrderedDict` occurrences with plain `Dict` (it is not used in Django 3.2 and later)

* Add fake datastructures for convenience: _PropertyDescriptor and _ListOrTuple now can live here. Added _IndexableCollection (often useful as alias for 'sequence or queryset')

* Actualize other datastructures.

* Rework MultiValueDict to reflect the fact that some methods can return empty list instead of value.

* Deprecate SafeText in favor of SafeString.

* Minor improvements to utils

* Disallow using str in TimeFormat and DateFormat, drop removed fmt `B`

* Do not let classproperty expect classmethod, make return value covariant.

* Sync with real file.

* Improve types for timezone.

* Sync deprecated, new and removed features in translation utils.

* Drop removed files, sync huge deprecations.

* Fix incompatible decorators (properties, contextmanagers)

* Rework pagination.

* Sync validators with real code. Add _ValidatorCallable for any external use (field validation etc.)

* Add shared type definitions (for fields of both forms and models). Actualize model fields. Mark keyword-only args explicitly in stubs (where code uses **kwargs). Disallow bytes for verbose_name.

* Make all checks return Sequence[CheckMessage] or subclass to be covariant.

* Add bidirectional references between backend.base and other files. Replace some Any's with specific types.

* Actualize db.migrations: remove removed methods, replace "None" annotations in wrong places, improve some wrong annotations.

* Actualize db.utils to match real file.

* Replace FileResponse and TemplateResponse with HttpResponse(Base) where needed: at least HttpResponseNotModified/HttpResponseRedirect can be returned instead of it, so annotation was wrong.

* Replace Any in forms where possible. Actualize class bases and method arguments.

* Improve typing of serializers.

* Actualize views, rename variable bound to Model to _M for consistency.

* Make types of file-related code consistent. Disallow using bytes as path, because many methods expect str-only paths. Make File inherit from IO[AnyStr] instead of IO[Any]: it makes impossible to instantiate file of union type, but allows precise types for some methods.

* Minor improvements: stop using None as annotation in wrong places, replace obvious Any's with precise types, actualize methods (missing/renamed/signature changed).

* Allow less specific containers, replace Any's with specific types.

* Improve types for requests and responses.

* Use AbstractBaseUser instead of User in auth.

* Use broader type for permission_required

* Use wider container types. Add 'type: ignore' to avoid issues with mypy.stubtest.

* Disallow using backend class as argument (it is passed to import_string).

* Add required methods to PasseordValidator.

* Allow using Path instance as argument.

* Actualize methods.

* Add 'type: ignore' to avoid issues with mypy.stubtest.

* Replace Any's with specific types and BaseForm with ModelForm.

* Actualize contrib.postgres

* Remove render_to_response, add 'get_absolute_url' to corresponding protocol.

* Actualize signers.

* Use precise types for handlers. Disallow str as stream type for LimitedStream.

* Exact types for ValidationError

* Replace wrong used Union with Sequence.

* Actualize static handlers.

* More specific types for admin. Fixes #874.

* Improve types and replace 'Tags' with str (it isn't Enum, so annotation was wrong).

* Replace Any with specific types, actualize signatures.

* Add async variants of handlers and clients. Use fake class to distinguish between request types in RequestFactory and AsyncRequestFactory.

* Fix signature, minor improvements.

* Actualize signatures and class names, replace Any with more specific types.

* Fix signature.

* Add some missing methods to Collector

* Combinable rarely returns Self type: almost always it's CombinedExpression.

* No Random in source anymore.

* Drop removed SimpleCol.

* Replace _OutputField with Field: nothing in docs about strings.

* Introduce reusable types, add missing methods. Remove strange types (probably created by stubgen). Remove RawQuery from Compiler: it obviously doesn't work with RawQuery.

* Use literal constants.

* Actualize base classes.

* Callable is not accepted by get_field.

* Add precise types.

* Use property and broader containers where possible. Add missing methods.

* Actualize indexes.

* More specific types for signals.

* Fix signatures, drop missing methods.

* Actualize window functions to match source.

* Actualize text functions, add missing methods, use type aliases for consistency.

* Add missing property decorators, methods and attributes. Use type aliases. Remove absent YearComparisonLookup and any SafeText references (they aren't related to lookups at all).

* Use bound TypeVar, mark all BuiltinLookup descendants as generic explicitly. Remove strange Union from Lookup.__init__

* Apply type alias, fix base class and argument name.

* Actualize BaseExpression methods.

* Fix imports.

* Add missing class and fix incompatible bases.

* Use same types in __init__ and attribute.

* OrderBy accepts F or Expression.

* Non-expressions are converted to Values.

* Add missing attributes.

* Add missing methods, fix 'None' argument type.

* Define properties where possible, remove 'None' argument annotations, remove inadequate type in make_immutable_fields_list.

* Remove absent QueryWrapper. Replace some Any with precise types.

* Fix wrong types and actualize signatures. Deny ManagerDescriptor.__get__ on model instances.

* Use more specific types.

* Arity can be None in subclasses.

* Reformat with black

* Make DeletionMixin generic.

* Fix wrong type variable in _RequestFactory.

* Fix variable name in signature.

* Disallow returning None from Form.clean()

* Allow again returning None from Form.clean

* Drop some unused imports.

* Add tests for MultiValueDict.

* Add tests for utils.timezone.

* Fix #834.

* Add more files to import_all test

* Allow None for `context_object_name`

* Fix CI

* Fix test to work on python 3.8
This commit is contained in:
sterliakov
2022-04-04 00:41:41 +03:00
committed by GitHub
parent dc4c0d9ee4
commit f69e0639c7
322 changed files with 5740 additions and 3465 deletions

View File

@@ -12,7 +12,6 @@ from .filters import ListFilter as ListFilter
from .filters import RelatedFieldListFilter as RelatedFieldListFilter
from .filters import RelatedOnlyFieldListFilter as RelatedOnlyFieldListFilter
from .filters import SimpleListFilter as SimpleListFilter
from .helpers import ACTION_CHECKBOX_NAME as ACTION_CHECKBOX_NAME
from .options import HORIZONTAL as HORIZONTAL
from .options import VERTICAL as VERTICAL
from .options import ModelAdmin as ModelAdmin

View File

@@ -1,8 +1,8 @@
from typing import Optional
from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.query import QuerySet
from django.http.request import HttpRequest
from django.template.response import TemplateResponse
def delete_selected(modeladmin: ModelAdmin, request: WSGIRequest, queryset: QuerySet) -> Optional[TemplateResponse]: ...
def delete_selected(modeladmin: ModelAdmin, request: HttpRequest, queryset: QuerySet) -> Optional[TemplateResponse]: ...

View File

@@ -1,18 +1,21 @@
from typing import Any, List, Optional, Sequence
from typing import Any, Optional, Sequence
from django.apps.config import AppConfig
from django.contrib.admin.options import BaseModelAdmin
from django.core.checks.messages import CheckMessage, Error
def check_admin_app(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[Error]: ...
def check_dependencies(app_configs: Optional[Sequence[AppConfig]] = ..., **kwargs: Any) -> List[Error]: ...
def check_admin_app(app_configs: Optional[Sequence[AppConfig]], **kwargs: Any) -> Sequence[CheckMessage]: ...
def check_dependencies(**kwargs: Any) -> Sequence[CheckMessage]: ...
class BaseModelAdminChecks:
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> List[CheckMessage]: ...
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> Sequence[CheckMessage]: ...
class ModelAdminChecks(BaseModelAdminChecks): ...
class InlineModelAdminChecks(BaseModelAdminChecks): ...
class ModelAdminChecks(BaseModelAdminChecks):
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> Sequence[CheckMessage]: ...
class InlineModelAdminChecks(BaseModelAdminChecks):
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> Sequence[CheckMessage]: ... # type: ignore
def must_be(type: Any, option: Any, obj: Any, id: Any): ...
def must_inherit_from(parent: Any, option: Any, obj: Any, id: Any): ...
def refer_to_missing_field(field: Any, option: Any, model: Any, obj: Any, id: Any): ...
def refer_to_missing_field(field: Any, option: Any, obj: Any, id: Any): ...

View File

@@ -1,38 +1,39 @@
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type
from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.fields import Field
from django.db.models.fields.related import RelatedField
from django.db.models.query import QuerySet
from django.http.request import HttpRequest
class ListFilter:
title: Any = ...
title: str = ...
template: str = ...
used_parameters: Any = ...
def __init__(
self, request: WSGIRequest, params: Dict[str, str], model: Type[Model], model_admin: ModelAdmin
self, request: HttpRequest, params: Dict[str, str], model: Type[Model], model_admin: ModelAdmin
) -> None: ...
def has_output(self) -> bool: ...
def choices(self, changelist: Any) -> Optional[Iterator[Dict[str, Any]]]: ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...
def queryset(self, request: Any, queryset: QuerySet) -> Optional[QuerySet]: ...
def expected_parameters(self) -> Optional[List[str]]: ...
class SimpleListFilter(ListFilter):
parameter_name: Any = ...
parameter_name: str = ...
lookup_choices: Any = ...
def value(self) -> Optional[str]: ...
def lookups(self, request: Any, model_admin: Any) -> List[Tuple[Any, str]]: ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...
class FieldListFilter(ListFilter):
field: Field = ...
field_path: Any = ...
title: Any = ...
field_path: str = ...
title: str = ...
def __init__(
self,
field: Field,
request: WSGIRequest,
request: HttpRequest,
params: Dict[str, str],
model: Type[Model],
model_admin: ModelAdmin,
@@ -44,7 +45,7 @@ class FieldListFilter(ListFilter):
def create(
cls,
field: Field,
request: WSGIRequest,
request: HttpRequest,
params: Dict[str, str],
model: Type[Model],
model_admin: ModelAdmin,
@@ -55,32 +56,34 @@ class RelatedFieldListFilter(FieldListFilter):
used_parameters: Dict[Any, Any]
lookup_kwarg: str = ...
lookup_kwarg_isnull: str = ...
lookup_val: None = ...
lookup_val_isnull: None = ...
lookup_val: Any = ...
lookup_val_isnull: Any = ...
lookup_choices: Any = ...
lookup_title: Any = ...
lookup_title: str = ...
title: str = ...
empty_value_display: Any = ...
@property
def include_empty_choice(self) -> bool: ...
def field_choices(
self, field: RelatedField, request: WSGIRequest, model_admin: ModelAdmin
self, field: RelatedField, request: HttpRequest, model_admin: ModelAdmin
) -> List[Tuple[str, str]]: ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...
class BooleanFieldListFilter(FieldListFilter):
lookup_kwarg: Any = ...
lookup_kwarg2: Any = ...
lookup_kwarg: str = ...
lookup_kwarg2: str = ...
lookup_val: Any = ...
lookup_val2: Any = ...
def choices(self, changelist: Any) -> None: ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...
class ChoicesFieldListFilter(FieldListFilter):
title: str
used_parameters: Dict[Any, Any]
lookup_kwarg: str = ...
lookup_kwarg_isnull: str = ...
lookup_val: None = ...
lookup_val_isnull: None = ...
lookup_val: Any = ...
lookup_val_isnull: Any = ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...
class DateFieldListFilter(FieldListFilter):
field_generic: Any = ...
@@ -89,25 +92,28 @@ class DateFieldListFilter(FieldListFilter):
lookup_kwarg_until: Any = ...
links: Any = ...
lookup_kwarg_isnull: Any = ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...
class AllValuesFieldListFilter(FieldListFilter):
title: str
used_parameters: Dict[Any, Any]
lookup_kwarg: str = ...
lookup_kwarg_isnull: str = ...
lookup_val: None = ...
lookup_val_isnull: None = ...
lookup_val: Any = ...
lookup_val_isnull: Any = ...
empty_value_display: str = ...
lookup_choices: QuerySet = ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...
class RelatedOnlyFieldListFilter(RelatedFieldListFilter):
lookup_kwarg: str
lookup_kwarg_isnull: str
lookup_val: None
lookup_val_isnull: None
lookup_val: Any
lookup_val_isnull: Any
title: str
used_parameters: Dict[Any, Any]
class EmptyFieldListFilter(FieldListFilter):
lookup_kwarg: str = ...
lookup_val: None = ...
lookup_val: Any = ...
def choices(self, changelist: Any) -> Iterator[Dict[str, Any]]: ...

View File

@@ -1,12 +1,20 @@
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
import sys
from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Tuple, Union
from django import forms
from django.contrib.admin.options import ModelAdmin
from django.db.models import Model
from django.db.models.fields import AutoField
from django.forms.boundfield import BoundField
from django.forms.forms import BaseForm
from django.forms.utils import ErrorDict
from django.forms.models import ModelForm
from django.forms.utils import ErrorDict, ErrorList
from django.forms.widgets import Media, Widget
from django.utils.safestring import SafeText
from django.utils.safestring import SafeString
if sys.version_info < (3, 8):
from typing_extensions import TypedDict
else:
from typing import TypedDict
ACTION_CHECKBOX_NAME: str
@@ -16,99 +24,121 @@ class ActionForm(forms.Form):
checkbox: Any
class _PrepopulatedDict(TypedDict):
field: BoundField
dependencies: List[BoundField]
class AdminForm:
prepopulated_fields: Any = ...
model_admin: Any = ...
readonly_fields: Any = ...
prepopulated_fields: List[_PrepopulatedDict]
model_admin: Optional[ModelAdmin] = ...
readonly_fields: Sequence[str] = ...
form: ModelForm
fieldsets: List[Tuple[Any, Dict[str, List[str]]]]
def __init__(
self,
form: BaseForm,
fieldsets: List[Tuple[None, Dict[str, List[str]]]],
prepopulated_fields: Dict[Any, Any],
readonly_fields: Optional[Iterable[Any]] = ...,
model_admin: Any = ...,
form: ModelForm,
fieldsets: List[Tuple[Any, Dict[str, List[str]]]],
prepopulated_fields: Mapping[str, Iterable[str]],
readonly_fields: Optional[Sequence[str]] = ...,
model_admin: Optional[ModelAdmin] = ...,
) -> None: ...
def __iter__(self) -> Iterator[Fieldset]: ...
@property
def errors(self) -> ErrorDict: ...
@property
def non_field_errors(self) -> Callable: ...
def non_field_errors(self) -> Callable[[], ErrorList]: ...
@property
def media(self) -> Media: ...
class Fieldset:
form: Any = ...
classes: Any = ...
description: Any = ...
model_admin: Any = ...
readonly_fields: Any = ...
form: ModelForm = ...
classes: str = ...
description: Optional[str] = ...
model_admin: Optional[ModelAdmin] = ...
readonly_fields: Sequence[str] = ...
def __init__(
self,
form: Any,
form: ModelForm,
name: Optional[Any] = ...,
readonly_fields: Optional[Iterable[Any]] = ...,
fields: Any = ...,
classes: Any = ...,
description: Optional[Any] = ...,
model_admin: Optional[Any] = ...,
readonly_fields: Sequence[str] = ...,
fields: Sequence[str] = ...,
classes: Iterable[str] = ...,
description: Optional[str] = ...,
model_admin: Optional[ModelAdmin] = ...,
) -> None: ...
@property
def media(self) -> Media: ...
def __iter__(self) -> Iterator[Fieldline]: ...
class Fieldline:
form: Any = ...
fields: Any = ...
has_visible_field: Any = ...
model_admin: Any = ...
readonly_fields: Any = ...
form: ModelForm = ...
fields: Sequence[str] = ...
has_visible_field: bool = ...
model_admin: Optional[ModelAdmin] = ...
readonly_fields: Sequence[str] = ...
def __init__(
self, form: Any, field: Any, readonly_fields: Optional[Iterable[Any]] = ..., model_admin: Optional[Any] = ...
self,
form: ModelForm,
field: Union[str, Sequence[str]],
readonly_fields: Optional[Sequence[str]] = ...,
model_admin: Optional[ModelAdmin] = ...,
) -> None: ...
def __iter__(self) -> Iterator[Union[AdminField, AdminReadonlyField]]: ...
def errors(self) -> SafeText: ...
def errors(self) -> SafeString: ...
class AdminField:
field: BoundField = ...
is_first: bool = ...
is_checkbox: bool = ...
is_readonly: bool = ...
def __init__(self, form: Any, field: Any, is_first: Any) -> None: ...
def label_tag(self) -> SafeText: ...
def errors(self) -> SafeText: ...
def __init__(self, form: ModelForm, field: str, is_first: bool) -> None: ...
def label_tag(self) -> SafeString: ...
def errors(self) -> SafeString: ...
class _FieldDictT(TypedDict):
name: str
label: str
help_text: str
field: Union[Callable[[Model], Any], str]
class AdminReadonlyField:
field: Any = ...
form: Any = ...
model_admin: Any = ...
is_first: Any = ...
field: _FieldDictT = ...
form: ModelForm = ...
model_admin: Optional[ModelAdmin] = ...
is_first: bool = ...
is_checkbox: bool = ...
is_readonly: bool = ...
empty_value_display: Any = ...
def __init__(self, form: Any, field: Any, is_first: Any, model_admin: Optional[Any] = ...) -> None: ...
def label_tag(self) -> SafeText: ...
def contents(self) -> SafeText: ...
def __init__(
self,
form: ModelForm,
field: Union[Callable[[Model], Any], str],
is_first: bool,
model_admin: Optional[ModelAdmin] = ...,
) -> None: ...
def label_tag(self) -> SafeString: ...
def contents(self) -> SafeString: ...
class InlineAdminFormSet:
opts: Any = ...
formset: Any = ...
fieldsets: Any = ...
model_admin: Any = ...
readonly_fields: Any = ...
prepopulated_fields: Any = ...
classes: Any = ...
has_add_permission: Any = ...
has_change_permission: Any = ...
has_delete_permission: Any = ...
has_view_permission: Any = ...
model_admin: Optional[ModelAdmin] = ...
readonly_fields: Sequence[str] = ...
prepopulated_fields: Dict[str, Any] = ...
classes: str = ...
has_add_permission: bool = ...
has_change_permission: bool = ...
has_delete_permission: bool = ...
has_view_permission: bool = ...
def __init__(
self,
inline: Any,
formset: Any,
fieldsets: Any,
prepopulated_fields: Optional[Any] = ...,
readonly_fields: Optional[Any] = ...,
model_admin: Optional[Any] = ...,
prepopulated_fields: Optional[Dict[str, Any]] = ...,
readonly_fields: Optional[Sequence[str]] = ...,
model_admin: Optional[ModelAdmin] = ...,
has_add_permission: bool = ...,
has_change_permission: bool = ...,
has_delete_permission: bool = ...,
@@ -120,26 +150,27 @@ class InlineAdminFormSet:
@property
def forms(self): ...
@property
def non_form_errors(self) -> Callable: ...
def non_form_errors(self) -> Callable[[], ErrorList]: ...
@property
def media(self) -> Media: ...
class InlineAdminForm(AdminForm):
formset: Any = ...
original: Any = ...
show_url: Any = ...
absolute_url: Any = ...
original: Optional[bool] = ...
show_url: bool = ...
absolute_url: Optional[str] = ...
def __init__(
self,
formset: Any,
form: Any,
form: ModelForm,
fieldsets: Any,
prepopulated_fields: Any,
original: Any,
readonly_fields: Optional[Any] = ...,
model_admin: Optional[Any] = ...,
view_on_site_url: Optional[Any] = ...,
original: Optional[bool],
readonly_fields: Optional[Sequence[str]] = ...,
model_admin: Optional[ModelAdmin] = ...,
view_on_site_url: Optional[str] = ...,
) -> None: ...
def __iter__(self) -> Iterator[InlineFieldset]: ...
def needs_explicit_pk_field(self) -> Union[bool, AutoField]: ...
def pk_field(self) -> AdminField: ...
def fk_field(self) -> AdminField: ...
@@ -149,6 +180,7 @@ class InlineAdminForm(AdminForm):
class InlineFieldset(Fieldset):
formset: Any = ...
def __init__(self, formset: Any, *args: Any, **kwargs: Any) -> None: ...
def __iter__(self) -> Iterator[Fieldline]: ...
class AdminErrorList(forms.utils.ErrorList):
def __init__(self, form: Any, inline_formsets: Any) -> None: ...
def __init__(self, form: ModelForm, inline_formsets: Any) -> None: ...

View File

@@ -1,9 +1,10 @@
from collections import OrderedDict
import sys
from typing import (
Any,
Callable,
Dict,
Generic,
Iterable,
Iterator,
List,
Mapping,
@@ -17,7 +18,7 @@ from typing import (
)
from django import forms
from django.contrib.admin.filters import ListFilter
from django.contrib.admin.filters import FieldListFilter, ListFilter
from django.contrib.admin.models import LogEntry
from django.contrib.admin.sites import AdminSite
from django.contrib.admin.views.main import ChangeList
@@ -25,22 +26,28 @@ from django.contrib.auth.forms import AdminPasswordChangeForm
from django.contrib.contenttypes.models import ContentType
from django.core.checks.messages import CheckMessage
from django.core.paginator import Paginator
from django.db import models
from django.db.models.base import Model
from django.db.models.fields import Field
from django.db.models.fields.related import ForeignKey, ManyToManyField, RelatedField
from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.fields import Field as FormField
from django.forms.fields import TypedChoiceField
from django.forms.forms import BaseForm
from django.forms.formsets import BaseFormSet
from django.forms.models import BaseInlineFormSet, ModelChoiceField, ModelMultipleChoiceField
from django.forms.widgets import Media
from django.http.request import HttpRequest
from django.http.response import HttpResponse, HttpResponseBase, HttpResponseRedirect, JsonResponse
from django.template.response import TemplateResponse
from django.http.response import HttpResponse, HttpResponseRedirect, JsonResponse
from django.template.response import _TemplateForResponseT
from django.urls.resolvers import URLPattern
from django.utils.safestring import SafeText
from typing_extensions import Literal, TypedDict
from django.utils.datastructures import _ListOrTuple
from django.utils.safestring import SafeString
if sys.version_info < (3, 8):
from typing_extensions import Literal, TypedDict
else:
from typing import Literal, TypedDict
IS_POPUP_VAR: str
TO_FIELD_VAR: str
@@ -57,19 +64,26 @@ class IncorrectLookupParameters(Exception): ...
FORMFIELD_FOR_DBFIELD_DEFAULTS: Any
csrf_protect_m: Any
_FieldGroups = Sequence[Union[str, Sequence[str]]]
class _OptionalFieldOpts(TypedDict, total=False):
classes: Sequence[str]
description: str
class _FieldOpts(_OptionalFieldOpts, total=True):
fields: Sequence[Union[str, Sequence[str]]]
fields: _FieldGroups
# Workaround for mypy issue, a Sequence type should be preferred here.
# https://github.com/python/mypy/issues/8921
# _FieldsetSpec = Sequence[Tuple[Optional[str], _FieldOpts]]
_T = TypeVar("_T")
_ListOrTuple = Union[Tuple[_T, ...], List[_T]]
_FieldsetSpec = _ListOrTuple[Tuple[Optional[str], _FieldOpts]]
_ListFilterT = Union[
Type[ListFilter],
Field,
str,
Tuple[Union[Field, str], Type[FieldListFilter]],
List[Union[Field, str, Type[FieldListFilter]]],
]
# Generic type specifically for models, for use in BaseModelAdmin and subclasses
# https://github.com/typeddjango/django-stubs/issues/482
@@ -78,62 +92,66 @@ _ModelT = TypeVar("_ModelT", bound=Model)
class BaseModelAdmin(Generic[_ModelT]):
autocomplete_fields: Sequence[str] = ...
raw_id_fields: Sequence[str] = ...
fields: Sequence[Union[str, Sequence[str]]] = ...
exclude: Sequence[str] = ...
fieldsets: _FieldsetSpec = ...
form: Type[BaseForm] = ...
fields: Optional[_FieldGroups] = ...
exclude: Optional[Sequence[str]] = ...
fieldsets: Optional[_FieldsetSpec] = ...
form: Type[forms.ModelForm[_ModelT]] = ...
filter_vertical: Sequence[str] = ...
filter_horizontal: Sequence[str] = ...
radio_fields: Mapping[str, _Direction] = ...
prepopulated_fields: Mapping[str, Sequence[str]] = ...
prepopulated_fields: Dict[str, Sequence[str]] = ...
formfield_overrides: Mapping[Type[Field], Mapping[str, Any]] = ...
readonly_fields: Sequence[Union[str, Callable[[_ModelT], Any]]] = ...
ordering: Sequence[str] = ...
sortable_by: Sequence[str] = ...
view_on_site: bool = ...
readonly_fields: Sequence[str] = ...
ordering: Optional[Sequence[str]] = ...
sortable_by: Optional[_ListOrTuple[str]] = ...
view_on_site: Union[bool, Callable[[_ModelT], str]] = ...
show_full_result_count: bool = ...
checks_class: Any = ...
model: Type[_ModelT]
opts: Options[_ModelT]
admin_site: AdminSite
def __init__(self) -> None: ...
def check(self, **kwargs: Any) -> List[CheckMessage]: ...
def formfield_for_dbfield(
self, db_field: models.Field, request: Optional[HttpRequest], **kwargs: Any
) -> Optional[forms.Field]: ...
def formfield_for_choice_field(
self, db_field: Field, request: Optional[HttpRequest], **kwargs: Any
) -> TypedChoiceField: ...
def formfield_for_dbfield(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> Optional[FormField]: ...
def formfield_for_choice_field(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> TypedChoiceField: ...
def get_field_queryset(
self, db: None, db_field: RelatedField, request: Optional[HttpRequest]
self, db: Optional[str], db_field: RelatedField, request: HttpRequest
) -> Optional[QuerySet]: ...
def formfield_for_foreignkey(
self, db_field: ForeignKey, request: Optional[HttpRequest], **kwargs: Any
) -> Optional[ModelChoiceField]: ...
self, db_field: ForeignKey, request: HttpRequest, **kwargs: Any
) -> ModelChoiceField: ...
def formfield_for_manytomany(
self, db_field: ManyToManyField, request: Optional[HttpRequest], **kwargs: Any
) -> ModelMultipleChoiceField: ...
def get_autocomplete_fields(self, request: HttpRequest) -> Tuple: ...
self, db_field: ManyToManyField, request: HttpRequest, **kwargs: Any
) -> Optional[ModelMultipleChoiceField]: ...
def get_autocomplete_fields(self, request: HttpRequest) -> Sequence[str]: ...
def get_view_on_site_url(self, obj: Optional[_ModelT] = ...) -> Optional[str]: ...
def get_empty_value_display(self) -> SafeText: ...
def get_exclude(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Any: ...
def get_fields(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Sequence[Union[Callable, str]]: ...
def get_fieldsets(
def get_empty_value_display(self) -> SafeString: ...
def get_exclude(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Optional[Sequence[str]]: ...
def get_fields(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> _FieldGroups: ...
def get_fieldsets(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> _FieldsetSpec: ...
def get_inlines(self, request: HttpRequest, obj: Optional[_ModelT]) -> List[Type[InlineModelAdmin]]: ...
def get_ordering(self, request: HttpRequest) -> Sequence[str]: ...
def get_readonly_fields(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Sequence[str]: ...
def get_prepopulated_fields(
self, request: HttpRequest, obj: Optional[_ModelT] = ...
) -> List[Tuple[Optional[str], Dict[str, Any]]]: ...
def get_ordering(self, request: HttpRequest) -> Union[List[str], Tuple]: ...
def get_readonly_fields(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Union[List[str], Tuple]: ...
def get_prepopulated_fields(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Dict[str, Tuple[str]]: ...
def get_queryset(self, request: HttpRequest) -> QuerySet: ...
def get_sortable_by(self, request: HttpRequest) -> Union[List[Callable], List[str], Tuple]: ...
) -> Dict[str, Sequence[str]]: ...
def get_queryset(self, request: HttpRequest) -> QuerySet[_ModelT]: ...
def get_sortable_by(self, request: HttpRequest) -> Sequence[str]: ...
def lookup_allowed(self, lookup: str, value: str) -> bool: ...
def to_field_allowed(self, request: HttpRequest, to_field: str) -> bool: ...
def has_add_permission(self, request: HttpRequest) -> bool: ...
def has_change_permission(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> bool: ...
def has_delete_permission(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> bool: ...
def has_view_permission(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> bool: ...
def has_view_or_change_permission(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> bool: ...
def has_module_permission(self, request: HttpRequest) -> bool: ...
_DisplayT = _ListOrTuple[Union[str, Callable[[_ModelT], str]]]
class ModelAdmin(BaseModelAdmin[_ModelT]):
list_display: Sequence[Union[str, Callable[[_ModelT], Any]]] = ...
list_display_links: Optional[Sequence[Union[str, Callable]]] = ...
list_filter: Sequence[Union[str, Type[ListFilter], Tuple[str, Type[ListFilter]]]] = ...
list_display: _DisplayT = ...
list_display_links: _DisplayT = ...
list_filter: _ListOrTuple[_ListFilterT] = ...
list_select_related: Union[bool, Sequence[str]] = ...
list_per_page: int = ...
list_max_show_all: int = ...
@@ -146,23 +164,22 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
paginator: Type = ...
preserve_filters: bool = ...
inlines: Sequence[Type[InlineModelAdmin]] = ...
add_form_template: str = ...
change_form_template: str = ...
change_list_template: str = ...
delete_confirmation_template: str = ...
delete_selected_confirmation_template: str = ...
object_history_template: str = ...
popup_response_template: str = ...
add_form_template: Optional[_TemplateForResponseT] = ...
change_form_template: Optional[_TemplateForResponseT] = ...
change_list_template: Optional[_TemplateForResponseT] = ...
delete_confirmation_template: Optional[_TemplateForResponseT] = ...
delete_selected_confirmation_template: Optional[_TemplateForResponseT] = ...
object_history_template: Optional[_TemplateForResponseT] = ...
popup_response_template: Optional[_TemplateForResponseT] = ...
actions: Optional[Sequence[Union[Callable[[ModelAdmin, HttpRequest, QuerySet], None], str]]] = ...
action_form: Any = ...
actions_on_top: bool = ...
actions_on_bottom: bool = ...
actions_selection_counter: bool = ...
model: Type[_ModelT] = ...
opts: Options = ...
opts: Options[_ModelT] = ...
admin_site: AdminSite = ...
def __init__(self, model: Type[_ModelT], admin_site: Optional[AdminSite]) -> None: ...
def get_inlines(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> List[Type[InlineModelAdmin]]: ...
def __init__(self, model: Type[_ModelT], admin_site: AdminSite) -> None: ...
def get_inline_instances(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> List[InlineModelAdmin]: ...
def get_urls(self) -> List[URLPattern]: ...
@property
@@ -170,11 +187,13 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
@property
def media(self) -> Media: ...
def get_model_perms(self, request: HttpRequest) -> Dict[str, bool]: ...
def get_form(self, request: Any, obj: Optional[_ModelT] = ..., change: bool = ..., **kwargs: Any): ...
def get_form(
self, request: Any, obj: Optional[_ModelT] = ..., change: bool = ..., **kwargs: Any
) -> Type[forms.ModelForm[_ModelT]]: ...
def get_changelist(self, request: HttpRequest, **kwargs: Any) -> Type[ChangeList]: ...
def get_changelist_instance(self, request: HttpRequest) -> ChangeList: ...
def get_object(
self, request: HttpRequest, object_id: str, from_field: Optional[Union[Callable[..., Any], str]] = ...
self, request: HttpRequest, object_id: str, from_field: Optional[str] = ...
) -> Optional[_ModelT]: ...
def get_changelist_form(self, request: Any, **kwargs: Any): ...
def get_changelist_formset(self, request: Any, **kwargs: Any): ...
@@ -190,25 +209,25 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
def log_addition(self, request: HttpRequest, object: _ModelT, message: Any) -> LogEntry: ...
def log_change(self, request: HttpRequest, object: _ModelT, message: Any) -> LogEntry: ...
def log_deletion(self, request: HttpRequest, object: _ModelT, object_repr: str) -> LogEntry: ...
def action_checkbox(self, obj: _ModelT) -> SafeText: ...
def get_actions(self, request: HttpRequest) -> OrderedDict: ...
def action_checkbox(self, obj: _ModelT) -> SafeString: ...
def get_actions(self, request: HttpRequest) -> Dict[str, Optional[Tuple[Callable[..., str], str, str]]]: ...
def get_action_choices(
self, request: HttpRequest, default_choices: List[Tuple[str, str]] = ...
) -> List[Tuple[str, str]]: ...
def get_action(self, action: Union[Callable, str]) -> Tuple[Callable, str, str]: ...
def get_list_display(self, request: HttpRequest) -> Sequence[str]: ...
def get_list_display_links(self, request: HttpRequest, list_display: Sequence[str]) -> Optional[Sequence[str]]: ...
def get_list_filter(self, request: HttpRequest) -> Sequence[str]: ...
def get_list_select_related(self, request: HttpRequest) -> Sequence[str]: ...
def get_search_fields(self, request: HttpRequest) -> List[str]: ...
def get_action(self, action: Union[Callable, str]) -> Optional[Tuple[Callable[..., str], str, str]]: ...
def get_list_display(self, request: HttpRequest) -> _DisplayT: ...
def get_list_display_links(self, request: HttpRequest, list_display: _DisplayT) -> _DisplayT: ...
def get_list_filter(self, request: HttpRequest) -> Sequence[_ListFilterT]: ...
def get_list_select_related(self, request: HttpRequest) -> Union[bool, Sequence[str]]: ...
def get_search_fields(self, request: HttpRequest) -> Sequence[str]: ...
def get_search_results(
self, request: HttpRequest, queryset: QuerySet, search_term: str
) -> Tuple[QuerySet, bool]: ...
) -> Tuple[QuerySet[_ModelT], bool]: ...
def get_preserved_filters(self, request: HttpRequest) -> str: ...
def _get_edited_object_pks(self, request: HttpRequest, prefix: str) -> List[str]: ...
def _get_list_editable_queryset(self, request: HttpRequest, prefix: str) -> QuerySet: ...
def _get_list_editable_queryset(self, request: HttpRequest, prefix: str) -> QuerySet[_ModelT]: ...
def construct_change_message(
self, request: HttpRequest, form: AdminPasswordChangeForm, formsets: None, add: bool = ...
self, request: HttpRequest, form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet], add: bool = ...
) -> List[Dict[str, Dict[str, List[str]]]]: ...
def message_user(
self,
@@ -239,44 +258,45 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
def response_change(self, request: HttpRequest, obj: _ModelT) -> HttpResponse: ...
def response_post_save_add(self, request: HttpRequest, obj: _ModelT) -> HttpResponseRedirect: ...
def response_post_save_change(self, request: HttpRequest, obj: _ModelT) -> HttpResponseRedirect: ...
def response_action(self, request: HttpRequest, queryset: QuerySet) -> Optional[HttpResponseBase]: ...
# Probably FileResponse cannot come from ModelAdmin views
def response_action(self, request: HttpRequest, queryset: QuerySet) -> Optional[HttpResponse]: ...
def response_delete(self, request: HttpRequest, obj_display: str, obj_id: int) -> HttpResponse: ...
def render_delete_form(self, request: Any, context: Any): ...
def get_inline_formsets(
self, request: HttpRequest, formsets: List[Any], inline_instances: List[Any], obj: Optional[_ModelT] = ...
) -> List[Any]: ...
def get_changeform_initial_data(self, request: HttpRequest) -> Dict[str, str]: ...
def get_changeform_initial_data(self, request: HttpRequest) -> Dict[str, Union[str, List[str]]]: ...
def changeform_view(
self,
request: HttpRequest,
object_id: Optional[str] = ...,
form_url: str = ...,
extra_context: Optional[Dict[str, Any]] = ...,
) -> Any: ...
def autocomplete_view(self, request: HttpRequest) -> JsonResponse: ...
) -> HttpResponse: ...
def add_view(
self, request: HttpRequest, form_url: str = ..., extra_context: Optional[Dict[str, Any]] = ...
) -> HttpResponse: ...
def change_view(
self, request: HttpRequest, object_id: str, form_url: str = ..., extra_context: Optional[Dict[str, Any]] = ...
) -> HttpResponse: ...
def changelist_view(
self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...
) -> TemplateResponse: ...
def changelist_view(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
def get_deleted_objects(
self, objs: QuerySet, request: HttpRequest
) -> Tuple[List[Any], Dict[Any, Any], Set[Any], List[Any]]: ...
self, objs: Union[Sequence[_ModelT], QuerySet[_ModelT]], request: HttpRequest
) -> Tuple[List[Model], Dict[str, int], Set[str], List[str]]: ...
def delete_view(
self, request: HttpRequest, object_id: str, extra_context: Optional[Dict[str, Any]] = ...
) -> Any: ...
) -> HttpResponse: ...
def history_view(
self, request: HttpRequest, object_id: str, extra_context: Optional[Dict[str, Any]] = ...
) -> HttpResponse: ...
class InlineModelAdmin(BaseModelAdmin[_ModelT]):
model: Type[_ModelT] = ...
fk_name: str = ...
formset: Type[BaseInlineFormSet] = ...
_ChildModelT = TypeVar("_ChildModelT", bound=Model)
_ParentModelT = TypeVar("_ParentModelT", bound=Model)
class InlineModelAdmin(Generic[_ChildModelT, _ParentModelT], BaseModelAdmin[_ChildModelT]):
model: Type[_ChildModelT] = ...
fk_name: Optional[str] = ...
formset: Type[BaseInlineFormSet[_ChildModelT, forms.ModelForm[_ChildModelT]]] = ...
extra: int = ...
min_num: Optional[int] = ...
max_num: Optional[int] = ...
@@ -287,16 +307,26 @@ class InlineModelAdmin(BaseModelAdmin[_ModelT]):
show_change_link: bool = ...
classes: Optional[Sequence[str]] = ...
admin_site: AdminSite = ...
parent_model: Any = ...
opts: Any = ...
has_registered_model: Any = ...
def __init__(self, parent_model: Union[Type[_ModelT], _ModelT], admin_site: AdminSite) -> None: ...
parent_model: Type[_ParentModelT] = ...
opts: Options[_ChildModelT] = ...
has_registered_model: bool = ...
def __init__(self, parent_model: Type[_ParentModelT], admin_site: AdminSite) -> None: ...
@property
def media(self) -> Media: ...
def get_extra(self, request: HttpRequest, obj: Optional[_ModelT] = ..., **kwargs: Any) -> int: ...
def get_min_num(self, request: HttpRequest, obj: Optional[_ModelT] = ..., **kwargs: Any) -> Optional[int]: ...
def get_max_num(self, request: HttpRequest, obj: Optional[_ModelT] = ..., **kwargs: Any) -> Optional[int]: ...
def get_formset(self, request: Any, obj: Optional[_ModelT] = ..., **kwargs: Any): ...
def get_extra(self, request: HttpRequest, obj: Optional[_ParentModelT] = ..., **kwargs: Any) -> int: ...
def get_min_num(self, request: HttpRequest, obj: Optional[_ParentModelT] = ..., **kwargs: Any) -> Optional[int]: ...
def get_max_num(self, request: HttpRequest, obj: Optional[_ParentModelT] = ..., **kwargs: Any) -> Optional[int]: ...
def get_formset(
self, request: HttpRequest, obj: Optional[_ParentModelT] = ..., **kwargs: Any
) -> Type[BaseInlineFormSet[_ChildModelT, forms.ModelForm[_ChildModelT]]]: ...
def get_queryset(self, request: HttpRequest) -> QuerySet[_ChildModelT]: ...
def has_add_permission(self, request: HttpRequest, obj: Optional[_ParentModelT]) -> bool: ... # type: ignore
def has_change_permission(self, request: HttpRequest, obj: Optional[_ParentModelT] = ...) -> bool: ... # type: ignore
def has_delete_permission(self, request: HttpRequest, obj: Optional[_ParentModelT] = ...) -> bool: ... # type: ignore
def has_view_permission(self, request: HttpRequest, obj: Optional[_ParentModelT] = ...) -> bool: ... # type: ignore
class StackedInline(InlineModelAdmin[_ModelT]): ...
class TabularInline(InlineModelAdmin[_ModelT]): ...
class StackedInline(InlineModelAdmin[_ChildModelT, _ParentModelT]):
template: str = ...
class TabularInline(InlineModelAdmin[_ChildModelT, _ParentModelT]):
template: str = ...

View File

@@ -5,9 +5,9 @@ from django.apps.config import AppConfig
from django.contrib.admin.options import ModelAdmin
from django.contrib.auth.forms import AuthenticationForm
from django.core.checks import CheckMessage
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.query import QuerySet
from django.http.request import HttpRequest
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
from django.urls import URLPattern, URLResolver
@@ -22,7 +22,7 @@ else:
all_sites: MutableSet[AdminSite]
_ActionCallback = Callable[[ModelAdmin, WSGIRequest, QuerySet], Optional[TemplateResponse]]
_ActionCallback = Callable[[ModelAdmin, HttpRequest, QuerySet], Optional[TemplateResponse]]
class AlreadyRegistered(Exception): ...
class NotRegistered(Exception): ...
@@ -41,6 +41,7 @@ class AdminSite:
password_change_done_template: Optional[str] = ...
name: str = ...
enable_nav_sidebar: bool = ...
empty_value_display: str = ...
final_catch_all_view: bool = ...
_empty_value_display: str = ...
_registry: Dict[Type[Model], ModelAdmin]
@@ -61,31 +62,29 @@ class AdminSite:
def get_action(self, name: str) -> Callable: ...
@property
def actions(self) -> Iterable[Tuple[str, _ActionCallback]]: ...
@property
def empty_value_display(self) -> str: ...
@empty_value_display.setter
def empty_value_display(self, empty_value_display: str) -> None: ...
def has_permission(self, request: WSGIRequest) -> bool: ...
def has_permission(self, request: HttpRequest) -> bool: ...
def admin_view(self, view: Callable, cacheable: bool = ...) -> Callable: ...
def get_urls(self) -> List[URLResolver]: ...
def get_urls(self) -> List[Union[URLResolver, URLPattern]]: ...
@property
def urls(self) -> Tuple[List[Union[URLResolver, URLPattern]], str, str]: ...
def each_context(self, request: WSGIRequest) -> Dict[str, Any]: ...
def each_context(self, request: HttpRequest) -> Dict[str, Any]: ...
def password_change(
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...
) -> TemplateResponse: ...
def password_change_done(
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...
) -> TemplateResponse: ...
def i18n_javascript(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
def logout(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
def login(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
def _build_app_dict(self, request: WSGIRequest, label: Optional[str] = ...) -> Dict[str, Any]: ...
def get_app_list(self, request: WSGIRequest) -> List[Any]: ...
def index(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
def i18n_javascript(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
def logout(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
def login(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
def _build_app_dict(self, request: HttpRequest, label: Optional[str] = ...) -> Dict[str, Any]: ...
def get_app_list(self, request: HttpRequest) -> List[Any]: ...
def index(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
def app_index(
self, request: WSGIRequest, app_label: str, extra_context: Optional[Dict[str, Any]] = ...
self, request: HttpRequest, app_label: str, extra_context: Optional[Dict[str, Any]] = ...
) -> TemplateResponse: ...
def autocomplete_view(self, request: HttpRequest) -> HttpResponse: ...
def catch_all_view(self, request: HttpRequest, url: str) -> HttpResponse: ...
class DefaultAdminSite(LazyObject): ...

View File

@@ -5,24 +5,25 @@ from django.contrib.admin.templatetags.base import InclusionAdminNode
from django.contrib.admin.views.main import ChangeList
from django.db.models.base import Model
from django.forms.boundfield import BoundField
from django.forms.models import ModelForm
from django.template.base import Parser, Token
from django.template.context import RequestContext
from django.utils.safestring import SafeText
from django.utils.safestring import SafeString
from .base import InclusionAdminNode
register: Any
DOT: str
def paginator_number(cl: ChangeList, i: int) -> SafeText: ...
def pagination(cl: ChangeList) -> Dict[str, Iterable[Any]]: ...
def paginator_number(cl: ChangeList, i: int) -> SafeString: ...
def pagination(cl: ChangeList) -> Dict[str, Any]: ...
def pagination_tag(parser: Parser, token: Token) -> InclusionAdminNode: ...
def result_headers(cl: ChangeList) -> Iterator[Dict[str, Optional[Union[int, str]]]]: ...
def items_for_result(cl: ChangeList, result: Model, form: None) -> Iterator[SafeText]: ...
def items_for_result(cl: ChangeList, result: Model, form: Optional[ModelForm]) -> Iterator[SafeString]: ...
class ResultList(list):
form: None = ...
def __init__(self, form: None, *items: Any) -> None: ...
form: Optional[ModelForm] = ...
def __init__(self, form: Optional[ModelForm], *items: Any) -> None: ...
def results(cl: ChangeList) -> Iterator[ResultList]: ...
def result_hidden_fields(cl: ChangeList) -> Iterator[BoundField]: ...
@@ -36,7 +37,7 @@ def date_hierarchy(cl: ChangeList) -> Optional[Dict[str, Any]]: ...
def date_hierarchy_tag(parser: Parser, token: Token) -> InclusionAdminNode: ...
def search_form(cl: ChangeList) -> Dict[str, Union[bool, ChangeList, str]]: ...
def search_form_tag(parser: Parser, token: Token) -> InclusionAdminNode: ...
def admin_list_filter(cl: ChangeList, spec: FieldListFilter) -> SafeText: ...
def admin_list_filter(cl: ChangeList, spec: FieldListFilter) -> SafeString: ...
def admin_actions(context: RequestContext) -> RequestContext: ...
def admin_actions_tag(parser: Parser, token: Token) -> InclusionAdminNode: ...
def change_list_object_tools_tag(parser: Parser, token: Token) -> InclusionAdminNode: ...

View File

@@ -1,5 +0,0 @@
from typing import Any
register: Any
def static(path: str) -> str: ...

View File

@@ -3,11 +3,11 @@ from uuid import UUID
from django.db.models.options import Options
from django.template.context import RequestContext
from django.utils.safestring import SafeText
from django.utils.safestring import SafeString
register: Any
def admin_urlname(value: Options, arg: SafeText) -> str: ...
def admin_urlname(value: Options, arg: SafeString) -> str: ...
def admin_urlquote(value: Union[int, str, UUID]) -> Union[int, str, UUID]: ...
def add_preserved_filters(
context: Union[Dict[str, Union[Options, str]], RequestContext],

View File

@@ -3,15 +3,15 @@ from typing import Any, Callable, Dict, List
from django.template.base import Parser, Token
from django.template.context import Context
from django.template.library import InclusionNode
from django.utils.safestring import SafeText
from django.utils.safestring import SafeString
class InclusionAdminNode(InclusionNode):
args: List[Any]
func: Callable
kwargs: Dict[Any, Any]
kwargs: Dict[str, Any]
takes_context: bool
template_name: str = ...
def __init__(
self, parser: Parser, token: Token, func: Callable, template_name: str, takes_context: bool = ...
) -> None: ...
def render(self, context: Context) -> SafeText: ...
def render(self, context: Context) -> SafeString: ...

View File

@@ -1,4 +1,5 @@
from typing import Any, Callable
from contextlib import contextmanager
from typing import Any, Callable, Generator
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.test.selenium import SeleniumTestCase
@@ -8,16 +9,18 @@ class CSPMiddleware(MiddlewareMixin): ...
class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
def wait_until(self, callback: Callable, timeout: int = ...) -> None: ...
def wait_for_popup(self, num_windows: int = ..., timeout: int = ...) -> None: ...
def wait_for_and_switch_to_popup(self, num_windows: int = ..., timeout: int = ...) -> None: ...
def wait_for(self, css_selector: str, timeout: int = ...) -> None: ...
def wait_for_text(self, css_selector: str, text: str, timeout: int = ...) -> None: ...
def wait_for_value(self, css_selector: str, text: str, timeout: int = ...) -> None: ...
def wait_until_visible(self, css_selector: str, timeout: int = ...) -> None: ...
def wait_until_invisible(self, css_selector: str, timeout: int = ...) -> None: ...
def wait_page_loaded(self) -> None: ...
def wait_page_ready(self, timeout: int = ...) -> None: ...
@contextmanager
def wait_page_loaded(self, timeout: int = ...) -> Generator[None, None, None]: ...
def admin_login(self, username: str, password: str, login_url: str = ...) -> None: ...
def get_css_value(self, selector: str, attribute: str) -> Any: ...
def get_select_option(self, selector: str, value: Any) -> Any: ...
def select_option(self, selector: str, value: Any) -> None: ...
def deselect_option(self, selector: str, value: Any) -> None: ...
def assertSelectOptions(self, selector: str, values: Any) -> None: ...
def assertSelectedOptions(self, selector: str, values: Any) -> None: ...
def has_css_class(self, selector: str, klass: str) -> bool: ...

View File

@@ -1,34 +1,40 @@
import collections
from datetime import datetime
from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, Type, Union
import datetime
import sys
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Type, Union, overload
from uuid import UUID
from django.contrib.admin.options import BaseModelAdmin
from django.contrib.admin.sites import AdminSite
from django.contrib.auth.forms import AdminPasswordChangeForm
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.db.models.deletion import Collector
from django.db.models.fields import Field, reverse_related
from django.db.models.fields.reverse_related import ManyToOneRel
from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.forms import BaseForm
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest
from django.utils.datastructures import _IndexableCollection
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal
class FieldIsAForeignKeyColumnName(Exception): ...
def lookup_needs_distinct(opts: Options, lookup_path: str) -> bool: ...
def prepare_lookup_value(key: str, value: Union[datetime, str]) -> Union[bool, datetime, str]: ...
def prepare_lookup_value(key: str, value: Union[datetime.datetime, str]) -> Union[bool, datetime.datetime, str]: ...
def quote(s: Union[int, str, UUID]) -> str: ...
def unquote(s: str) -> str: ...
def flatten(fields: Any) -> List[Union[Callable, str]]: ...
def flatten_fieldsets(fieldsets: Any) -> List[Union[Callable, str]]: ...
def get_deleted_objects(
objs: Sequence[Optional[Model]], request: WSGIRequest, admin_site: AdminSite
) -> Tuple[List[Any], Dict[Any, Any], Set[Any], List[Any]]: ...
objs: Union[Sequence[Optional[Model]], QuerySet[Model]], request: HttpRequest, admin_site: AdminSite
) -> Tuple[List[Model], Dict[str, int], Set[str], List[str]]: ...
class NestedObjects(Collector):
data: collections.OrderedDict
data: Dict[str, Any]
dependencies: Dict[Any, Any]
fast_deletes: List[Any]
field_updates: Dict[Any, Any]
@@ -38,21 +44,33 @@ class NestedObjects(Collector):
model_objs: Any = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def add_edge(self, source: Optional[Model], target: Model) -> None: ...
def related_objects(self, related: ManyToOneRel, objs: Sequence[Optional[Model]]) -> QuerySet: ...
def related_objects(
self, related_model: Type[Model], related_fields: Iterable[Field], objs: _IndexableCollection[Model]
) -> QuerySet[Model]: ...
def nested(self, format_callback: Callable = ...) -> List[Any]: ...
def can_fast_delete(self, *args: Any, **kwargs: Any) -> bool: ...
def model_format_dict(obj: Any): ...
def model_format_dict(obj: Union[Model, Type[Model], QuerySet, Options[Model]]): ...
def model_ngettext(obj: Union[Options, QuerySet], n: Optional[int] = ...) -> str: ...
def lookup_field(
name: Union[Callable, str], obj: Model, model_admin: BaseModelAdmin = ...
) -> Tuple[Optional[Field], Any, Any]: ...
name: Union[Callable, str], obj: Model, model_admin: Optional[BaseModelAdmin] = ...
) -> Tuple[Optional[Field], Optional[str], Any]: ...
@overload
def label_for_field( # type: ignore
name: Union[Callable, str],
model: Type[Model],
model_admin: Optional[BaseModelAdmin] = ...,
return_attr: Literal[True] = ...,
form: Optional[BaseForm] = ...,
) -> Tuple[str, Union[Callable, str, None]]: ...
@overload
def label_for_field(
name: Union[Callable, str],
model: Type[Model],
model_admin: Optional[BaseModelAdmin] = ...,
return_attr: bool = ...,
return_attr: Literal[False] = ...,
form: Optional[BaseForm] = ...,
) -> Union[Tuple[Optional[str], Union[Callable, Type[str]]], str]: ...
) -> str: ...
def help_text_for_field(name: str, model: Type[Model]) -> str: ...
def display_for_field(value: Any, field: Field, empty_value_display: str) -> str: ...
def display_for_value(value: Any, empty_value_display: str, boolean: bool = ...) -> str: ...
@@ -63,5 +81,5 @@ def get_model_from_relation(field: Union[Field, reverse_related.ForeignObjectRel
def reverse_field_path(model: Type[Model], path: str) -> Tuple[Type[Model], str]: ...
def get_fields_from_path(model: Type[Model], path: str) -> List[Field]: ...
def construct_change_message(
form: AdminPasswordChangeForm, formsets: None, add: bool
form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet], add: bool
) -> List[Dict[str, Dict[str, List[str]]]]: ...

View File

@@ -1,10 +1,11 @@
from typing import Any
from typing import Any, Optional
from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.db.models import Model
from django.http.request import HttpRequest
from django.views.generic.list import BaseListView
class AutocompleteJsonView(BaseListView):
model_admin: ModelAdmin = ...
term: Any = ...
def has_perm(self, request: WSGIRequest, obj: None = ...) -> bool: ...
def has_perm(self, request: HttpRequest, obj: Optional[Model] = ...) -> bool: ...

View File

@@ -1,16 +1,21 @@
from collections import OrderedDict
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
import sys
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type, Union
from django.contrib.admin.filters import ListFilter, SimpleListFilter
from django.contrib.admin.filters import ListFilter
from django.contrib.admin.options import IS_POPUP_VAR as IS_POPUP_VAR # noqa: F401
from django.contrib.admin.options import TO_FIELD_VAR as TO_FIELD_VAR
from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.contrib.admin.options import ModelAdmin, _DisplayT, _ListFilterT
from django.db.models.base import Model
from django.db.models.expressions import Combinable, CombinedExpression, OrderBy
from django.db.models.expressions import Expression
from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal
ALL_VAR: str
ORDER_VAR: str
@@ -18,69 +23,75 @@ ORDER_TYPE_VAR: str
PAGE_VAR: str
SEARCH_VAR: str
ERROR_FLAG: str
IGNORED_PARAMS: Any
IGNORED_PARAMS: Tuple[str, ...]
class ChangeList:
model: Type[Model] = ...
opts: Options = ...
lookup_opts: Options = ...
root_queryset: QuerySet = ...
list_display: List[str] = ...
list_display_links: List[str] = ...
list_filter: Tuple = ...
date_hierarchy: None = ...
search_fields: Tuple = ...
list_select_related: bool = ...
list_display: _DisplayT = ...
list_display_links: _DisplayT = ...
list_filter: Sequence[_ListFilterT] = ...
date_hierarchy: Any = ...
search_fields: Sequence[str] = ...
list_select_related: Union[bool, Sequence[str]] = ...
list_per_page: int = ...
list_max_show_all: int = ...
model_admin: ModelAdmin = ...
preserved_filters: str = ...
sortable_by: Tuple[str] = ...
sortable_by: Optional[Sequence[str]] = ...
page_num: int = ...
show_all: bool = ...
is_popup: bool = ...
to_field: None = ...
params: Dict[Any, Any] = ...
list_editable: Tuple = ...
to_field: Any = ...
params: Dict[str, Any] = ...
list_editable: Sequence[str] = ...
query: str = ...
queryset: Any = ...
title: Any = ...
pk_attname: Any = ...
title: str = ...
pk_attname: str = ...
formset: Optional[BaseFormSet]
def __init__(
self,
request: WSGIRequest,
request: HttpRequest,
model: Type[Model],
list_display: Union[List[Union[Callable, str]], Tuple[str]],
list_display_links: Optional[Union[List[Callable], List[str], Tuple[str]]],
list_filter: Union[List[Type[SimpleListFilter]], List[str], Tuple],
list_display: _DisplayT,
list_display_links: _DisplayT,
list_filter: Sequence[_ListFilterT],
date_hierarchy: Optional[str],
search_fields: Union[List[str], Tuple],
list_select_related: Union[Tuple, bool],
search_fields: Sequence[str],
list_select_related: Union[bool, Sequence[str]],
list_per_page: int,
list_max_show_all: int,
list_editable: Union[List[str], Tuple],
list_editable: Sequence[str],
model_admin: ModelAdmin,
sortable_by: Union[List[Callable], List[str], Tuple],
sortable_by: Optional[Sequence[str]],
) -> None: ...
def get_filters_params(self, params: None = ...) -> Dict[str, str]: ...
def get_filters(self, request: WSGIRequest) -> Tuple[List[ListFilter], bool, Dict[str, Union[bool, str]], bool]: ...
def get_filters_params(self, params: Optional[Dict[str, Any]] = ...) -> Dict[str, Any]: ...
def get_filters(
self, request: HttpRequest
) -> Tuple[List[ListFilter], bool, Dict[str, Union[bool, str]], bool, bool]: ...
def get_query_string(
self, new_params: Optional[Dict[str, None]] = ..., remove: Optional[List[str]] = ...
self, new_params: Optional[Dict[str, Any]] = ..., remove: Optional[Iterable[str]] = ...
) -> str: ...
result_count: Any = ...
show_full_result_count: Any = ...
show_admin_actions: Any = ...
full_result_count: Any = ...
result_count: int = ...
show_full_result_count: bool = ...
show_admin_actions: bool = ...
full_result_count: Optional[int] = ...
result_list: Any = ...
can_show_all: Any = ...
multi_page: Any = ...
can_show_all: bool = ...
multi_page: bool = ...
paginator: Any = ...
def get_results(self, request: WSGIRequest) -> None: ...
def get_ordering_field(self, field_name: Union[Callable, str]) -> Optional[Union[CombinedExpression, str]]: ...
def get_ordering(self, request: WSGIRequest, queryset: QuerySet) -> List[Union[OrderBy, Combinable, str]]: ...
def get_ordering_field_columns(self) -> OrderedDict: ...
def get_queryset(self, request: WSGIRequest) -> QuerySet: ...
def get_results(self, request: HttpRequest) -> None: ...
def get_ordering_field(self, field_name: Union[Callable, str]) -> Optional[Union[Expression, str]]: ...
def get_ordering(self, request: HttpRequest, queryset: QuerySet) -> List[Union[Expression, str]]: ...
def get_ordering_field_columns(self) -> Dict[int, Literal["desc", "asc"]]: ...
def get_queryset(self, request: HttpRequest) -> QuerySet: ...
filter_specs: List[ListFilter]
has_filters: bool
has_active_filters: bool
clear_all_filters_qs: str
def apply_select_related(self, qs: QuerySet) -> QuerySet: ...
def has_related_field_in_list_display(self) -> bool: ...
def url_for_result(self, result: Model) -> str: ...

View File

@@ -1,28 +1,31 @@
from typing import Any, Dict, Optional, Tuple, Union
from uuid import UUID
from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple, Union
from django import forms
from django.contrib.admin.sites import AdminSite
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToOneRel
from django.core.files.base import File
from django.db.models.fields import _FieldChoices
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToManyRel, ManyToOneRel
from django.forms.models import ModelChoiceIterator
from django.forms.widgets import Media
from django.forms.widgets import Media, _OptAttrs
class FilteredSelectMultiple(forms.SelectMultiple):
@property
def media(self) -> Media: ...
verbose_name: Any = ...
is_stacked: Any = ...
def __init__(self, verbose_name: str, is_stacked: bool, attrs: None = ..., choices: Tuple = ...) -> None: ...
verbose_name: str = ...
is_stacked: bool = ...
def __init__(
self, verbose_name: str, is_stacked: bool, attrs: Optional[_OptAttrs] = ..., choices: _FieldChoices = ...
) -> None: ...
class AdminDateWidget(forms.DateInput):
@property
def media(self) -> Media: ...
def __init__(self, attrs: Optional[_OptAttrs] = ..., format: Optional[str] = ...) -> None: ...
class AdminTimeWidget(forms.TimeInput):
@property
def media(self) -> Media: ...
def __init__(self, attrs: Optional[_OptAttrs] = ..., format: Optional[str] = ...) -> None: ...
class AdminSplitDateTime(forms.SplitDateTimeWidget):
template_name: str
def __init__(self, attrs: Optional[_OptAttrs] = ...) -> None: ...
def get_context(self, name: str, value: Any, attrs: Optional[_OptAttrs]) -> Dict[str, Any]: ...
class AdminSplitDateTime(forms.SplitDateTimeWidget): ...
class AdminRadioSelect(forms.RadioSelect): ...
class AdminFileWidget(forms.ClearableFileInput): ...
@@ -31,18 +34,27 @@ def url_params_from_lookup_dict(lookups: Any) -> Dict[str, str]: ...
class ForeignKeyRawIdWidget(forms.TextInput):
rel: ManyToOneRel = ...
admin_site: AdminSite = ...
db: None = ...
def __init__(self, rel: ForeignObjectRel, admin_site: AdminSite, attrs: None = ..., using: None = ...) -> None: ...
db: Optional[str] = ...
def __init__(
self, rel: ManyToOneRel, admin_site: AdminSite, attrs: Optional[_OptAttrs] = ..., using: Optional[str] = ...
) -> None: ...
def base_url_parameters(self) -> Dict[str, str]: ...
def get_context(self, name: str, value: Any, attrs: Optional[_OptAttrs]) -> Dict[str, Any]: ...
def url_parameters(self) -> Dict[str, str]: ...
def label_and_url_for_value(self, value: Union[int, str, UUID]) -> Tuple[str, str]: ...
def label_and_url_for_value(self, value: Any) -> Tuple[str, str]: ...
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): ...
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
rel: ManyToManyRel = ... # type: ignore
def get_context(self, name: str, value: Any, attrs: Optional[_OptAttrs]) -> Dict[str, Any]: ...
def url_parameters(self) -> Dict[str, str]: ...
def label_and_url_for_value(self, value: Any) -> Tuple[str, str]: ...
def format_value(self, value: Any) -> Optional[str]: ...
def value_from_datadict(self, data: Mapping[str, Any], files: Mapping[str, Iterable[File]], name: str) -> Any: ...
class RelatedFieldWidgetWrapper(forms.Widget):
template_name: str = ...
choices: ModelChoiceIterator = ...
widget: forms.Widget = ...
widget: forms.ChoiceWidget = ...
rel: ManyToOneRel = ...
can_add_related: bool = ...
can_change_related: bool = ...
@@ -51,8 +63,8 @@ class RelatedFieldWidgetWrapper(forms.Widget):
admin_site: AdminSite = ...
def __init__(
self,
widget: forms.Widget,
rel: ForeignObjectRel,
widget: forms.ChoiceWidget,
rel: ManyToOneRel,
admin_site: AdminSite,
can_add_related: Optional[bool] = ...,
can_change_related: bool = ...,
@@ -60,42 +72,66 @@ class RelatedFieldWidgetWrapper(forms.Widget):
can_view_related: bool = ...,
) -> None: ...
@property
def media(self) -> Media: ...
def media(self) -> Media: ... # type: ignore
@property
def is_hidden(self) -> bool: ...
def get_related_url(self, info: Tuple[str, str], action: str, *args: Any) -> str: ...
def get_context(self, name: str, value: Any, attrs: Optional[_OptAttrs]) -> Dict[str, Any]: ...
def value_from_datadict(self, data: Mapping[str, Any], files: Mapping[str, Iterable[File]], name: str) -> Any: ...
def value_omitted_from_data(
self, data: Mapping[str, Any], files: Mapping[str, Iterable[File]], name: str
) -> bool: ...
def id_for_label(self, id_: str) -> str: ...
class AdminTextareaWidget(forms.Textarea): ...
class AdminTextInputWidget(forms.TextInput): ...
class AdminEmailInputWidget(forms.EmailInput): ...
class AdminURLFieldWidget(forms.URLInput): ...
class AdminTextareaWidget(forms.Textarea):
def __init__(self, attrs: Optional[_OptAttrs] = ...) -> None: ...
class AdminTextInputWidget(forms.TextInput):
def __init__(self, attrs: Optional[_OptAttrs] = ...) -> None: ...
class AdminEmailInputWidget(forms.EmailInput):
def __init__(self, attrs: Optional[_OptAttrs] = ...) -> None: ...
class AdminURLFieldWidget(forms.URLInput):
template_name: str
def __init__(self, attrs: Optional[_OptAttrs] = ..., validator_class: Any = ...) -> None: ...
def get_context(self, name: str, value: Any, attrs: Optional[_OptAttrs]) -> Dict[str, Any]: ...
class AdminIntegerFieldWidget(forms.NumberInput):
def __init__(self, attrs: Optional[_OptAttrs] = ...) -> None: ...
class_name: str = ...
class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget): ...
class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget):
class_name: str = ...
class AdminUUIDInputWidget(forms.TextInput):
def __init__(self, attrs: Optional[Dict[str, str]] = ...) -> None: ...
def __init__(self, attrs: Optional[_OptAttrs] = ...) -> None: ...
SELECT2_TRANSLATIONS: Any
SELECT2_TRANSLATIONS: Dict[str, str] = ...
class AutocompleteMixin:
url_name: str = ...
rel: Any = ...
admin_site: Any = ...
db: Any = ...
field: Any = ...
admin_site: AdminSite = ...
db: Optional[str] = ...
choices: Any = ...
attrs: Any = ...
attrs: _OptAttrs = ...
def __init__(
self,
rel: ForeignObjectRel,
field: Any,
admin_site: AdminSite,
attrs: Optional[Dict[str, str]] = ...,
choices: Tuple = ...,
using: None = ...,
attrs: Optional[_OptAttrs] = ...,
choices: Any = ...,
using: Optional[str] = ...,
) -> None: ...
def get_url(self) -> str: ...
@property
def media(self) -> Media: ...
def build_attrs(self, base_attrs: _OptAttrs, extra_attrs: Optional[_OptAttrs] = ...) -> Dict[str, Any]: ...
# typo in source: `attr` instead of `attrs`
def optgroups(
self, name: str, value: Sequence[str], attr: Optional[_OptAttrs] = ...
) -> List[Tuple[Optional[str], List[Dict[str, Any]], Optional[int]]]: ...
class AutocompleteSelect(AutocompleteMixin, forms.Select): ...
class AutocompleteSelectMultiple(AutocompleteMixin, forms.SelectMultiple): ...
class AutocompleteSelect(AutocompleteMixin, forms.Select): ... # type: ignore
class AutocompleteSelectMultiple(AutocompleteMixin, forms.SelectMultiple): ... # type: ignore