Signals

Potion comes with several Blinker signals. The signals can be used to pre-process and post-process most parts of the read, create, update cycle.

Resources using the SQLAlchemyManager or PeeweeManager hook into these signals. Other Manager implementations should be written to hook into them as well.

Signal listeners can edit the item:

>>> @before_create.connect_via(ArticleResource)
... def on_before_create_article(sender, item):
...     item.author_id = current_user.id

Listeners may also raise exceptions:

>>> @before_create.connect_via(ArticleResource)
... def on_before_create_article(sender, item):
...     if not current_user.is_editor:
...         raise BadRequest()

The complete list of signals:

class signals.before_create
Parameters:
  • sender – item resource
  • item – instance of item
class signals.after_create
Parameters:
  • sender – item resource
  • item – instance of item
class signals.before_update
Parameters:
  • sender – item resource
  • item – instance of item
  • changes (dict) – dictionary of changes, already parsed
class signals.after_update
Parameters:
  • sender – item resource
  • item – instance of item
  • changes (dict) – dictionary of changes, already parsed
class signals.before_delete
Parameters:
  • sender – item resource
  • item – instance of item
class signals.after_delete
Parameters:
  • sender – item resource
  • item – instance of item
class signals.before_add_to_relation
Parameters:
  • sender – parent resource
  • item – instance of parent item
  • attribute – name of relationship to child
  • child – instance of child item
class signals.after_add_to_relation
Parameters:
  • sender – parent resource
  • item – instance of parent item
  • attribute – name of relationship to child
  • child – instance of child item
class signals.before_remove_from_relation
Parameters:
  • sender – parent resource
  • item – instance of parent item
  • attribute – name of relationship to child
  • child – instance of child item
class signals.after_remove_from_relation
Parameters:
  • sender – parent resource
  • item – instance of parent item
  • attribute – name of relationship to child
  • child – instance of child item

Note

Relation-related signals are only used by Relation, They do not apply to relations created or removed by updating an item with fields.ToOne or fields.ToMany fields.