beanis.odm.actions
ActionRegistry
class ActionRegistry()
ActionRegistry.add_action
@classmethod
def add_action(cls, document_class: Type["Document"],
event_types: List[EventTypes],
action_direction: ActionDirections, funct: Callable)
Add action to the action registry
Arguments:
document_class: document classevent_types: List[EventTypes]action_direction: ActionDirections - before or afterfunct: Callable - function
ActionRegistry.get_action_list
@classmethod
def get_action_list(cls, document_class: Type["Document"],
event_type: EventTypes,
action_direction: ActionDirections) -> List[Callable]
Get stored action list
Arguments:
document_class: Type - document classevent_type: EventTypes - type of needed eventaction_direction: ActionDirections - before or afterReturns:
List[Callable] - list of stored methods
ActionRegistry.run_actions
@classmethod
async def run_actions(cls, instance: "Document", event_type: EventTypes,
action_direction: ActionDirections,
exclude: List[Union[ActionDirections, str]])
Run actions
Arguments:
instance: Document - object of the Document subclassevent_type: EventTypes - event typesaction_direction: ActionDirections - before or after
register_action
def register_action(event_types: Tuple[Union[List[EventTypes], EventTypes],
...],
action_direction: ActionDirections) -> Callable[[F], F]
Decorator. Base registration method.
Used inside
before_eventandafter_eventArguments:
event_types: Union[List[EventTypes], EventTypes] - event typesaction_direction: ActionDirections - before or after
before_event
def before_event(
*args: Union[List[EventTypes], EventTypes]) -> Callable[[F], F]
Decorator. It adds action, which should run before mentioned one
or many events happen
Arguments:
args: Union[List[EventTypes], EventTypes] - event typesReturns:
None
after_event
def after_event(
*args: Union[List[EventTypes], EventTypes]) -> Callable[[F], F]
Decorator. It adds action, which should run after mentioned one
or many events happen
Arguments:
args: Union[List[EventTypes], EventTypes] - event typesReturns:
None
wrap_with_actions
def wrap_with_actions(
event_type: EventTypes
) -> Callable[["AsyncDocMethod[DocType, P, R]"],
"AsyncDocMethod[DocType, P, R]"]
Helper function to wrap Document methods with
before and after event listeners
Arguments:
event_type: EventTypes - event typesReturns:
None