Skip to content

Commit 5edf07b

Browse files
authored
Revert "Add 'ignore' to graph_transition command (#56)"
This reverts commit 4bd42ac.
1 parent 4bd42ac commit 5edf07b

File tree

3 files changed

+19
-43
lines changed

3 files changed

+19
-43
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,6 @@ $ ./manage.py graph_transitions > transitions.dot
429429

430430
# Create a PNG image file only for specific model
431431
$ ./manage.py graph_transitions -o blog_transitions.png myapp.Blog
432-
433-
# Exclude some transitions
434-
$ ./manage.py graph_transitions -e transition_1,transition_2 myapp.Blog
435432
```
436433

437434
## Extensions

django_fsm/management/commands/graph_transitions.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,25 @@ def all_fsm_fields_data(model):
1616
return [(field, model) for field in model._meta.get_fields() if isinstance(field, FSMFieldMixin)]
1717

1818

19-
def node_name(field, state) -> str:
19+
def node_name(field, state):
2020
opts = field.model._meta
2121
return "{}.{}.{}.{}".format(opts.app_label, opts.verbose_name.replace(" ", "_"), field.name, state)
2222

2323

24-
def node_label(field, state) -> str:
25-
if isinstance(state, int):
26-
return str(state)
27-
if isinstance(state, bool) and hasattr(field, "choices"):
24+
def node_label(field, state):
25+
if isinstance(state, int) or (isinstance(state, bool) and hasattr(field, "choices")):
2826
return force_str(dict(field.choices).get(state))
2927
return state
3028

3129

32-
def generate_dot(fields_data, ignore_transitions: list[str] | None = None): # noqa: C901, PLR0912
33-
ignore_transitions = ignore_transitions or []
30+
def generate_dot(fields_data): # noqa: C901, PLR0912
3431
result = graphviz.Digraph()
3532

3633
for field, model in fields_data:
3734
sources, targets, edges, any_targets, any_except_targets = set(), set(), set(), set(), set()
3835

3936
# dump nodes and edges
4037
for transition in field.get_all_transitions(model):
41-
if transition.name in ignore_transitions:
42-
continue
43-
4438
_targets = list(
4539
(state for state in transition.target.allowed_states)
4640
if isinstance(transition.target, (GET_STATE, RETURN_VALUE))
@@ -133,7 +127,7 @@ def add_arguments(self, parser):
133127
"-o",
134128
action="store",
135129
dest="outputfile",
136-
help="Render output file. Type of output dependent on file extensions. Use png or jpg to render graph to image.",
130+
help=("Render output file. Type of output dependent on file extensions. Use png or jpg to render graph to image."),
137131
)
138132
parser.add_argument(
139133
"--layout",
@@ -143,14 +137,6 @@ def add_arguments(self, parser):
143137
default="dot",
144138
help=f"Layout to be used by GraphViz for visualization. Layouts: {get_graphviz_layouts()}.",
145139
)
146-
parser.add_argument(
147-
"--exclude",
148-
"-e",
149-
action="store",
150-
dest="exclude",
151-
default="",
152-
help="Ignore transitions with this name.",
153-
)
154140
parser.add_argument("args", nargs="*", help=("[appname[.model[.field]]]"))
155141

156142
def render_output(self, graph, **options):
@@ -167,8 +153,9 @@ def handle(self, *args, **options):
167153
field_spec = arg.split(".")
168154

169155
if len(field_spec) == 1:
170-
app = apps.get_app_config(field_spec[0])
171-
for model in apps.get_models(app):
156+
app = apps.get_app(field_spec[0])
157+
models = apps.get_models(app)
158+
for model in models:
172159
fields_data += all_fsm_fields_data(model)
173160
if len(field_spec) == 2: # noqa: PLR2004
174161
model = apps.get_model(field_spec[0], field_spec[1])
@@ -179,8 +166,7 @@ def handle(self, *args, **options):
179166
else:
180167
for model in apps.get_models():
181168
fields_data += all_fsm_fields_data(model)
182-
183-
dotdata = generate_dot(fields_data, ignore_transitions=options["exclude"].split(","))
169+
dotdata = generate_dot(fields_data)
184170

185171
if options["outputfile"]:
186172
self.render_output(dotdata, **options)

tests/testapp/tests/test_graph_transitions.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,16 @@
77

88

99
class GraphTransitionsCommandTest(TestCase):
10-
MODELS_TO_TEST = [
11-
"testapp.Application",
12-
"testapp.FKApplication",
13-
]
10+
def test_dummy(self):
11+
call_command("graph_transitions", "testapp.Application")
1412

15-
def test_app(self):
16-
call_command("graph_transitions", "testapp")
13+
def test_layouts(self):
14+
for layout in get_graphviz_layouts():
15+
call_command("graph_transitions", "-l", layout, "testapp.Application")
1716

18-
def test_single_model(self):
19-
for model in self.MODELS_TO_TEST:
20-
call_command("graph_transitions", model)
17+
def test_fk_dummy(self):
18+
call_command("graph_transitions", "testapp.FKApplication")
2119

22-
def test_single_model_with_layouts(self):
23-
for model in self.MODELS_TO_TEST:
24-
for layout in get_graphviz_layouts():
25-
call_command("graph_transitions", "-l", layout, model)
26-
27-
def test_exclude(self):
28-
for model in self.MODELS_TO_TEST:
29-
call_command("graph_transitions", "-e", "standard,no_target", model)
20+
def test_fk_layouts(self):
21+
for layout in get_graphviz_layouts():
22+
call_command("graph_transitions", "-l", layout, "testapp.FKApplication")

0 commit comments

Comments
 (0)