Signals¶
Restone 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 hook into these signals.
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 better way is:
>>> class ArticleResource:
... def on_before_create(self,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_relate¶
- Parameters:
sender – parent resource
item – instance of parent item
attribute – name of relationship to child
child – instance of child item
- class signals.after_relate¶
- Parameters:
sender – parent resource
item – instance of parent item
attribute – name of relationship to child
child – instance of child item
- class signals.before_remove¶
- Parameters:
sender – parent resource
item – instance of parent item
attribute – name of relationship to child
child – instance of child item
- class signals.after_remove¶
- 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 Res or Many fields.