mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-15 00:07:09 +08:00
Django admin additions (#543)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from typing import Any, Callable, Optional, Type
|
from typing import Any, Callable, Optional, Type
|
||||||
|
|
||||||
|
from django.contrib.admin.sites import AdminSite
|
||||||
from django.db.models.base import Model
|
from django.db.models.base import Model
|
||||||
|
|
||||||
def register(*models: Type[Model], site: Optional[Any] = ...) -> Callable: ...
|
def register(*models: Type[Model], site: Optional[AdminSite] = ...) -> Callable: ...
|
||||||
|
|||||||
@@ -1,36 +1,51 @@
|
|||||||
|
import sys
|
||||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
|
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
|
from django.apps.config import AppConfig
|
||||||
from django.contrib.admin.options import ModelAdmin
|
from django.contrib.admin.options import ModelAdmin
|
||||||
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.core.handlers.wsgi import WSGIRequest
|
from django.core.handlers.wsgi import WSGIRequest
|
||||||
from django.db.models.base import Model
|
from django.db.models.base import Model
|
||||||
|
from django.db.models.query import QuerySet
|
||||||
from django.http.response import HttpResponse
|
from django.http.response import HttpResponse
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.urls.resolvers import URLResolver
|
from django.urls.resolvers import URLResolver
|
||||||
from django.utils.functional import LazyObject
|
from django.utils.functional import LazyObject
|
||||||
|
from django.core.checks import CheckMessage
|
||||||
|
|
||||||
from django.apps.config import AppConfig
|
if sys.version_info >= (3, 9):
|
||||||
|
from weakref import WeakSet
|
||||||
|
|
||||||
all_sites: Any
|
all_sites: WeakSet[AdminSite]
|
||||||
|
else:
|
||||||
|
from typing import MutableSet
|
||||||
|
|
||||||
|
all_sites: MutableSet[AdminSite]
|
||||||
|
|
||||||
|
_ActionCallback = Callable[[ModelAdmin, WSGIRequest, QuerySet], Optional[TemplateResponse]]
|
||||||
|
|
||||||
class AlreadyRegistered(Exception): ...
|
class AlreadyRegistered(Exception): ...
|
||||||
class NotRegistered(Exception): ...
|
class NotRegistered(Exception): ...
|
||||||
|
|
||||||
class AdminSite:
|
class AdminSite:
|
||||||
site_title: Any = ...
|
site_title: str = ...
|
||||||
site_header: Any = ...
|
site_header: str = ...
|
||||||
index_title: Any = ...
|
index_title: str = ...
|
||||||
site_url: str = ...
|
site_url: str = ...
|
||||||
login_form: Any = ...
|
login_form: Optional[AuthenticationForm] = ...
|
||||||
index_template: Any = ...
|
index_template: Optional[str] = ...
|
||||||
app_index_template: Any = ...
|
app_index_template: Optional[str] = ...
|
||||||
login_template: Any = ...
|
login_template: Optional[str] = ...
|
||||||
logout_template: Any = ...
|
logout_template: Optional[str] = ...
|
||||||
password_change_template: Any = ...
|
password_change_template: Optional[str] = ...
|
||||||
password_change_done_template: Any = ...
|
password_change_done_template: Optional[str] = ...
|
||||||
name: str = ...
|
name: str = ...
|
||||||
|
_empty_value_display: str = ...
|
||||||
_registry: Dict[Type[Model], ModelAdmin]
|
_registry: Dict[Type[Model], ModelAdmin]
|
||||||
|
_global_actions: Dict[str, _ActionCallback]
|
||||||
|
_actions: Dict[str, _ActionCallback]
|
||||||
def __init__(self, name: str = ...) -> None: ...
|
def __init__(self, name: str = ...) -> None: ...
|
||||||
def check(self, app_configs: Optional[Iterable[AppConfig]]) -> List[Any]: ...
|
def check(self, app_configs: Optional[Iterable[AppConfig]]) -> List[CheckMessage]: ...
|
||||||
def register(
|
def register(
|
||||||
self,
|
self,
|
||||||
model_or_iterable: Union[Type[Model], Iterable[Type[Model]]],
|
model_or_iterable: Union[Type[Model], Iterable[Type[Model]]],
|
||||||
@@ -39,28 +54,28 @@ class AdminSite:
|
|||||||
) -> None: ...
|
) -> None: ...
|
||||||
def unregister(self, model_or_iterable: Union[Type[Model], Iterable[Type[Model]]]) -> None: ...
|
def unregister(self, model_or_iterable: Union[Type[Model], Iterable[Type[Model]]]) -> None: ...
|
||||||
def is_registered(self, model: Type[Model]) -> bool: ...
|
def is_registered(self, model: Type[Model]) -> bool: ...
|
||||||
def add_action(self, action: Callable, name: Optional[str] = ...) -> None: ...
|
def add_action(self, action: _ActionCallback, name: Optional[str] = ...) -> None: ...
|
||||||
def disable_action(self, name: str) -> None: ...
|
def disable_action(self, name: str) -> None: ...
|
||||||
def get_action(self, name: str) -> Callable: ...
|
def get_action(self, name: str) -> Callable: ...
|
||||||
@property
|
@property
|
||||||
def actions(self): ...
|
def actions(self) -> Iterable[Tuple[str, _ActionCallback]]: ...
|
||||||
@property
|
@property
|
||||||
def empty_value_display(self): ...
|
def empty_value_display(self) -> str: ...
|
||||||
@empty_value_display.setter
|
@empty_value_display.setter
|
||||||
def empty_value_display(self, empty_value_display: Any) -> None: ...
|
def empty_value_display(self, empty_value_display: str) -> None: ...
|
||||||
def has_permission(self, request: WSGIRequest) -> bool: ...
|
def has_permission(self, request: WSGIRequest) -> bool: ...
|
||||||
def admin_view(self, view: Callable, cacheable: bool = ...) -> Callable: ...
|
def admin_view(self, view: Callable, cacheable: bool = ...) -> Callable: ...
|
||||||
def get_urls(self) -> List[URLResolver]: ...
|
def get_urls(self) -> List[URLResolver]: ...
|
||||||
@property
|
@property
|
||||||
def urls(self) -> Tuple[List[URLResolver], str, str]: ...
|
def urls(self) -> Tuple[List[URLResolver], str, str]: ...
|
||||||
def each_context(self, request: Any): ...
|
def each_context(self, request: WSGIRequest) -> Dict[str, Any]: ...
|
||||||
def password_change(
|
def password_change(
|
||||||
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
|
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
|
||||||
) -> TemplateResponse: ...
|
) -> TemplateResponse: ...
|
||||||
def password_change_done(
|
def password_change_done(
|
||||||
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
|
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
|
||||||
) -> TemplateResponse: ...
|
) -> TemplateResponse: ...
|
||||||
def i18n_javascript(self, request: WSGIRequest, extra_context: Optional[Dict[Any, Any]] = ...) -> HttpResponse: ...
|
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 logout(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
|
||||||
def login(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
|
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 _build_app_dict(self, request: WSGIRequest, label: Optional[str] = ...) -> Dict[str, Any]: ...
|
||||||
@@ -72,4 +87,4 @@ class AdminSite:
|
|||||||
|
|
||||||
class DefaultAdminSite(LazyObject): ...
|
class DefaultAdminSite(LazyObject): ...
|
||||||
|
|
||||||
site: Any
|
site: AdminSite
|
||||||
|
|||||||
@@ -113,9 +113,15 @@ IGNORED_ERRORS = {
|
|||||||
'error: "HttpResponse" has no attribute "context_data"',
|
'error: "HttpResponse" has no attribute "context_data"',
|
||||||
],
|
],
|
||||||
"admin_checks": ['Argument 1 to "append" of "list" has incompatible type "str"; expected "CheckMessage"'],
|
"admin_checks": ['Argument 1 to "append" of "list" has incompatible type "str"; expected "CheckMessage"'],
|
||||||
|
"admin_default_site": [
|
||||||
|
'Incompatible types in assignment (expression has type "DefaultAdminSite", variable has type "AdminSite")'
|
||||||
|
],
|
||||||
"admin_inlines": [
|
"admin_inlines": [
|
||||||
'error: "HttpResponse" has no attribute "rendered_content"',
|
'error: "HttpResponse" has no attribute "rendered_content"',
|
||||||
],
|
],
|
||||||
|
"admin_registration": [
|
||||||
|
'Argument "site" to "register" has incompatible type "Type[Traveler]"; expected "Optional[AdminSite]"',
|
||||||
|
],
|
||||||
"admin_utils": [
|
"admin_utils": [
|
||||||
'"Article" has no attribute "non_field"',
|
'"Article" has no attribute "non_field"',
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user