Events

Ferris has a very simple global pubsub-style event system. Beyond the events emitted by Handlers, there’s also a way to globally emit and respond to events.

listeners.py

Inside of the app directory lives listeners.py. This is where you can register global event listeners using on:

ferris.core.events.on(event_name)[source]

Automatically called when the specified event occurs.

For example, to make sure a user is in a particular domain:

@on('handler_is_authorized')
def is_authorized(handler, *args, **kwargs):
    if not 'example.com' in handler.user.email():
        raise Exception('Unauthorized')

All handler events are prefixed with handler_ when broadcast globally.

Emitting Events

You can emit events on the global bus by using fire:

ferris.core.events.fire(event_name, *args, **kwargs)[source]

Calls all of the registered event handlers for a given event. Passes through all arguments

For example:

@route
def transmat(self, item):
    fire("item_transmat", item)

Table Of Contents

Previous topic

Forms

Next topic

Plugins

This Page