Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit b1553a0

Browse files
committed
Add on_error state draw
1 parent 998f39e commit b1553a0

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ Changelog
324324

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

327-
### django-fsm GIT
327+
### django-fsm 2.2.0 2014-09-03
328328
* Support for [class substitution](http://schinckel.net/2013/06/13/django-proxy-model-state-machine/) to proxy classes depending on the state
329329
* Added ConcurrentTransitionMixin with optimistic locking support
330330
* Default db_index=True for FSMIntegerField removed

django_fsm/management/commands/graph_transitions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ def generate_dot(fields_data):
3232
target_name = node_name(field, transition.target)
3333
sources.add((source_name, transition.source))
3434
targets.add((target_name, transition.target))
35-
edges.add((source_name, target_name))
35+
edges.add((source_name, target_name, ()))
36+
if transition.on_error:
37+
on_error_name = node_name(field, transition.on_error)
38+
targets.add((on_error_name, transition.on_error))
39+
edges.add((source_name, on_error_name, (('style', 'dotted'),)))
3640

3741
for target in any_targets:
3842
target_name = node_name(field, target)
3943
targets.add((target_name, target))
4044
for source_name, label in sources:
41-
edges.add((source_name, target_name))
45+
edges.add((source_name, target_name, ()))
4246

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

4953
for name, label in sources | targets:
5054
subgraph.node(name, label=label)
51-
for source_name, target_name in edges:
52-
subgraph.edge(source_name, target_name)
55+
for source_name, target_name, attrs in edges:
56+
subgraph.edge(source_name, target_name, **dict(attrs))
5357

5458
result.subgraph(subgraph)
5559

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='django-fsm',
10-
version='2.1.0',
10+
version='2.2.0',
1111
description='Django friendly finite state machine support.',
1212
author='Mikhail Podgurskiy',
1313
author_email='[email protected]',

tests/testapp/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,20 @@ class BlogPost(models.Model):
8585
state = FSMField(default='new', protected=True)
8686

8787
@transition(field=state, source='new', target='published',
88-
permission='testapp.can_publish_post')
88+
on_error='failed', permission='testapp.can_publish_post')
8989
def publish(self):
9090
pass
9191

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

96-
@transition(field=state, source='published', target='hidden')
96+
@transition(field=state, source='published', target='hidden', on_error='failed',)
9797
def hide(self):
9898
pass
9999

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

0 commit comments

Comments
 (0)