Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Add on_error state draw
Browse files Browse the repository at this point in the history
  • Loading branch information
kmmbvnr committed Sep 3, 2014
1 parent 998f39e commit b1553a0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Changelog

<img src="https://f.cloud.github.com/assets/41479/2227946/a9e77760-9ad0-11e3-804f-301d075470fe.png" alt="django-fsm" width="100px"/>

### django-fsm GIT
### django-fsm 2.2.0 2014-09-03
* Support for [class substitution](http://schinckel.net/2013/06/13/django-proxy-model-state-machine/) to proxy classes depending on the state
* Added ConcurrentTransitionMixin with optimistic locking support
* Default db_index=True for FSMIntegerField removed
Expand Down
12 changes: 8 additions & 4 deletions django_fsm/management/commands/graph_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ def generate_dot(fields_data):
target_name = node_name(field, transition.target)
sources.add((source_name, transition.source))
targets.add((target_name, transition.target))
edges.add((source_name, target_name))
edges.add((source_name, target_name, ()))
if transition.on_error:
on_error_name = node_name(field, transition.on_error)
targets.add((on_error_name, transition.on_error))
edges.add((source_name, on_error_name, (('style', 'dotted'),)))

for target in any_targets:
target_name = node_name(field, target)
targets.add((target_name, target))
for source_name, label in sources:
edges.add((source_name, target_name))
edges.add((source_name, target_name, ()))

# construct subgraph
opts = field.model._meta
Expand All @@ -48,8 +52,8 @@ def generate_dot(fields_data):

for name, label in sources | targets:
subgraph.node(name, label=label)
for source_name, target_name in edges:
subgraph.edge(source_name, target_name)
for source_name, target_name, attrs in edges:
subgraph.edge(source_name, target_name, **dict(attrs))

result.subgraph(subgraph)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='django-fsm',
version='2.1.0',
version='2.2.0',
description='Django friendly finite state machine support.',
author='Mikhail Podgurskiy',
author_email='[email protected]',
Expand Down
6 changes: 3 additions & 3 deletions tests/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ class BlogPost(models.Model):
state = FSMField(default='new', protected=True)

@transition(field=state, source='new', target='published',
permission='testapp.can_publish_post')
on_error='failed', permission='testapp.can_publish_post')
def publish(self):
pass

@transition(field=state, source='published')
def notify_all(self):
pass

@transition(field=state, source='published', target='hidden')
@transition(field=state, source='published', target='hidden', on_error='failed',)
def hide(self):
pass

@transition(field=state, source='new', target='removed',
permission=lambda u: u.has_perm('testapp.can_remove_post'))
on_error='failed', permission=lambda u: u.has_perm('testapp.can_remove_post'))
def remove(self):
raise Exception('No rights to delete %s' % self)

Expand Down

0 comments on commit b1553a0

Please sign in to comment.