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 class
  • event_types: List[EventTypes]
  • action_direction: ActionDirections - before or after
  • funct: 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 class
  • event_type: EventTypes - type of needed event
  • action_direction: ActionDirections - before or after

Returns:

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 subclass
  • event_type: EventTypes - event types
  • action_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_event and after_event

Arguments:

  • event_types: Union[List[EventTypes], EventTypes] - event types
  • action_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 types

Returns:

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 types

Returns:

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 types

Returns:

None