Skip to content

Commit

Permalink
Adds simple signal docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gvangool committed Oct 6, 2015
1 parent 56e52ac commit dc616db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ exclusive (everything but these):
class is_paid(StateGroup):
exclude_states = ['initiated']
Signals
-------
Two signals are provided (``before_state_execute`` and
``after_state_execute``) which allow you to trigger actions surrounding state
transitions.
This might be best explained with an example:
.. code:: python
from django.dispatch import receiver
from django_states.signals import before_state_execute, after_state_execute
from reversion.revisions import revision_context_manager
@receiver(before_state_execute)
def before_transition_handler(sender, transition, user, **kwargs):
revision_context_manager.start()
@receiver(after_state_execute)
def after_transition_handler(sender, transition, user, **kwargs):
revision_context_manager.set_comment('State transition: ' + transition)
if user is not None:
revision_context_manager.set_user(user)
revision_context_manager.end()
State graph
-----------
Expand Down
5 changes: 5 additions & 0 deletions docs/django_states/signals.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``django_states.signals``
=========================

.. automodule:: django_states.signals
:members:
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Internal API
django_states/machine
django_states/model_methods
django_states/models
django_states/signals
django_states/templatetags
django_states/views

Expand Down

0 comments on commit dc616db

Please sign in to comment.