refactoring
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
from typing import Any, Callable
|
||||
from typing import Any, Callable, TYPE_CHECKING
|
||||
from babel.support import LazyProxy
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from .role import RoleBase
|
||||
from . import EntityPermission
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .bot_entity import BotEntity
|
||||
|
||||
EntityCaptionCallable = Callable[["EntityDescriptor"], str]
|
||||
EntityItemCaptionCallable = Callable[["EntityDescriptor", Any], str]
|
||||
EntityFieldCaptionCallable = Callable[["EntityFieldDescriptor", Any, Any], str]
|
||||
@@ -13,18 +16,14 @@ EntityFieldCaptionCallable = Callable[["EntityFieldDescriptor", Any, Any], str]
|
||||
@dataclass(kw_only = True)
|
||||
class _BaseEntityFieldDescriptor():
|
||||
icon: str = None
|
||||
caption_str: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
caption_btn: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
caption: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
description: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
edit_prompt: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
caption_value_str: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
caption_value_btn: str | LazyProxy | EntityFieldCaptionCallable | None = None
|
||||
caption_value: EntityFieldCaptionCallable | None = None
|
||||
is_visible: bool = True
|
||||
localizable: bool = False
|
||||
bool_false_value: str | LazyProxy = "no"
|
||||
bool_false_value_btn: str | LazyProxy = "no"
|
||||
bool_true_value: str | LazyProxy = "yes"
|
||||
bool_true_value_btn: str | LazyProxy = "yes"
|
||||
default: Any = None
|
||||
|
||||
|
||||
@@ -44,6 +43,9 @@ class EntityFieldDescriptor(_BaseEntityFieldDescriptor):
|
||||
name: str
|
||||
field_name: str
|
||||
type_: type
|
||||
type_base: type = None
|
||||
is_list: bool = False
|
||||
is_optional: bool = False
|
||||
entity_descriptor: "EntityDescriptor" = None
|
||||
|
||||
def __hash__(self):
|
||||
@@ -54,14 +56,14 @@ class EntityFieldDescriptor(_BaseEntityFieldDescriptor):
|
||||
class _BaseEntityDescriptor:
|
||||
|
||||
icon: str = "📘"
|
||||
caption_msg: str | LazyProxy | EntityCaptionCallable | None = None
|
||||
caption_btn: str | LazyProxy | EntityCaptionCallable | None = None
|
||||
caption: str | LazyProxy | EntityCaptionCallable | None = None
|
||||
caption_plural: str | LazyProxy | EntityCaptionCallable | None = None
|
||||
description: str | LazyProxy | EntityCaptionCallable | None = None
|
||||
item_caption_msg: EntityItemCaptionCallable | None = None
|
||||
item_caption_btn: EntityItemCaptionCallable | None = None
|
||||
item_caption: EntityItemCaptionCallable | None = None
|
||||
show_in_entities_menu: bool = True
|
||||
field_sequence: list[str] = None
|
||||
edit_buttons: list[list[str]] = None
|
||||
edit_button_visible: bool = True
|
||||
edit_buttons: list[list[str | tuple[str, str | LazyProxy | EntityFieldCaptionCallable]]] = None
|
||||
permissions: dict[EntityPermission, list[RoleBase]] = field(default_factory = lambda: {
|
||||
EntityPermission.LIST: [RoleBase.DEFAULT_USER, RoleBase.SUPER_USER],
|
||||
EntityPermission.READ: [RoleBase.DEFAULT_USER, RoleBase.SUPER_USER],
|
||||
@@ -87,5 +89,5 @@ class EntityDescriptor(_BaseEntityDescriptor):
|
||||
|
||||
name: str
|
||||
class_name: str
|
||||
type_: type
|
||||
fields_descriptors: dict[str, EntityFieldDescriptor]
|
||||
type_: type["BotEntity"]
|
||||
fields_descriptors: dict[str, EntityFieldDescriptor]
|
||||
|
||||
Reference in New Issue
Block a user