Skip to content

Commit

Permalink
Fix diagrams when using Enums
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjbremner committed Oct 23, 2019
1 parent a735311 commit b7d277c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion transitions/extensions/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _get_graph(self, model, title=None, force_new=False, show_roi=False):
grph = self.graph_cls(self, title=title if title is not None else self.title)
self.model_graphs[model] = grph
try:
self.model_graphs[model].set_node_style(model.state, 'active')
self.model_graphs[model].set_node_style(model.state.name, 'active')
except AttributeError:
_LOGGER.info("Could not set active state of diagram")
try:
Expand Down
7 changes: 5 additions & 2 deletions transitions/extensions/markup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from six import string_types, iteritems
from functools import partial
import itertools
Expand Down Expand Up @@ -67,7 +68,7 @@ def _convert_states(self, states):
markup_states = []
for state in states:
s_def = _convert(state, self.state_attributes, self.skip_references)
s_def['name'] = getattr(state, '_name', state.name)
s_def['name'] = state.name
if getattr(state, 'children', False):
s_def['children'] = self._convert_states(state.children)
markup_states.append(s_def)
Expand Down Expand Up @@ -153,7 +154,9 @@ def _convert(obj, attributes, skip):
val = getattr(obj, key, False)
if not val:
continue
if isinstance(val, string_types):
if isinstance(val, Enum):
s[key] = val.name
elif isinstance(val, string_types):
s[key] = val
else:
try:
Expand Down

0 comments on commit b7d277c

Please sign in to comment.