Skip to content

Commit b5ff9e9

Browse files
authored
Add Django 5.1 support (#21)
1 parent b835404 commit b5ff9e9

File tree

9 files changed

+50
-40
lines changed

9 files changed

+50
-40
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.5.0
6+
rev: v4.6.0
77
hooks:
88
- id: check-added-large-files
99
args: ["--maxkb=700"]
@@ -18,17 +18,17 @@ repos:
1818
- id: trailing-whitespace
1919

2020
- repo: https://github.com/asottile/pyupgrade
21-
rev: v3.15.2
21+
rev: v3.16.0
2222
hooks:
2323
- id: pyupgrade
2424
args:
2525
- "--py38-plus"
2626

2727
- repo: https://github.com/adamchainz/django-upgrade
28-
rev: 1.16.0
28+
rev: 1.18.0
2929
hooks:
3030
- id: django-upgrade
31-
args: [--target-version, "3.2"]
31+
args: [--target-version, "4.2"]
3232

3333

3434
- repo: https://github.com/python-poetry/poetry
@@ -43,7 +43,7 @@ repos:
4343
- id: poetry-export
4444

4545
- repo: https://github.com/astral-sh/ruff-pre-commit
46-
rev: v0.3.4
46+
rev: v0.4.8
4747
hooks:
4848
- id: ruff-format
4949
- id: ruff

CHANGELOG.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
Changelog
22
=========
33

4-
django-fsm 3.0.0 2024-03-25
4+
Unreleased
5+
~~~~~~~~~~
6+
7+
- Add support for Django 5.1
8+
- Remove support for Django 3.2
9+
- Remove support for Django 4.0
10+
- Remove support for Django 4.1
11+
12+
django-fsm-2 3.0.0 2024-03-26
513
~~~~~~~~~~~~~~~~~~~~~~~~~~~
614

15+
First release of the forked version of django-fsm
16+
717
- Drop support for Python < 3.8.
818
- Add support for python 3.11
919
- Add support for python 3.12

django_fsm/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@ def name(self):
7171
def has_perm(self, instance, user):
7272
if not self.permission:
7373
return True
74-
elif callable(self.permission):
74+
if callable(self.permission):
7575
return bool(self.permission(instance, user))
76-
elif user.has_perm(self.permission, instance):
76+
if user.has_perm(self.permission, instance):
7777
return True
78-
elif user.has_perm(self.permission):
78+
if user.has_perm(self.permission):
7979
return True
80-
else:
81-
return False
80+
return False
8281

8382
def __hash__(self):
8483
return hash(self.name)
@@ -100,7 +99,7 @@ def get_available_FIELD_transitions(instance, field):
10099
curr_state = field.get_state(instance)
101100
transitions = field.transitions[instance.__class__]
102101

103-
for name, transition in transitions.items():
102+
for transition in transitions.values():
104103
meta = transition._django_fsm
105104
if meta.has_transition(curr_state) and meta.conditions_met(instance, curr_state):
106105
yield meta.get_transition(curr_state)
@@ -177,18 +176,19 @@ def conditions_met(self, instance, state):
177176

178177
if transition is None:
179178
return False
180-
elif transition.conditions is None:
179+
180+
if transition.conditions is None:
181181
return True
182-
else:
183-
return all(map(lambda condition: condition(instance), transition.conditions))
182+
183+
return all(condition(instance) for condition in transition.conditions)
184184

185185
def has_transition_perm(self, instance, state, user):
186186
transition = self.get_transition(state)
187187

188188
if not transition:
189189
return False
190-
else:
191-
return transition.has_perm(instance, user)
190+
191+
return transition.has_perm(instance, user)
192192

193193
def next_state(self, current_state):
194194
transition = self.get_transition(current_state)
@@ -341,7 +341,7 @@ def get_all_transitions(self, instance_cls):
341341
"""
342342
transitions = self.transitions[instance_cls]
343343

344-
for name, transition in transitions.items():
344+
for transition in transitions.values():
345345
meta = transition._django_fsm
346346

347347
for transition in meta.transitions.values():
@@ -565,7 +565,7 @@ def can_proceed(bound_method, check_conditions=True):
565565
conditions.
566566
"""
567567
if not hasattr(bound_method, "_django_fsm"):
568-
raise TypeError("%s method is not transition" % bound_method.__func__.__name__)
568+
raise TypeError(f"{bound_method.__func__.__name__} method is not transition")
569569

570570
meta = bound_method._django_fsm
571571
self = bound_method.__self__
@@ -579,7 +579,7 @@ def has_transition_perm(bound_method, user):
579579
Returns True if model in state allows to call bound_method and user have rights on it
580580
"""
581581
if not hasattr(bound_method, "_django_fsm"):
582-
raise TypeError("%s method is not transition" % bound_method.__func__.__name__)
582+
raise TypeError(f"{bound_method.__func__.__name__} method is not transition")
583583

584584
meta = bound_method._django_fsm
585585
self = bound_method.__self__

django_fsm/management/commands/graph_transitions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ def node_name(field, state):
2424
def node_label(field, state):
2525
if isinstance(state, int) or (isinstance(state, bool) and hasattr(field, "choices")):
2626
return force_str(dict(field.choices).get(state))
27-
else:
28-
return state
27+
return state
2928

3029

31-
def generate_dot(fields_data):
30+
def generate_dot(fields_data): # noqa: C901
3231
result = graphviz.Digraph()
3332

3433
for field, model in fields_data:
@@ -135,7 +134,7 @@ def add_arguments(self, parser):
135134
action="store",
136135
dest="layout",
137136
default="dot",
138-
help=("Layout to be used by GraphViz for visualization. " "Layouts: %s." % " ".join(get_graphviz_layouts())),
137+
help=f"Layout to be used by GraphViz for visualization. Layouts: {get_graphviz_layouts()}.",
139138
)
140139
parser.add_argument("args", nargs="*", help=("[appname[.model[.field]]]"))
141140

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
name = "django-fsm"
33
version = "3.0.0"
44
description = "Django friendly finite state machine support."
5-
authors = ["Mikhail Podgurskiy <[email protected]>"]
5+
authors = [
6+
"Mikhail Podgurskiy <[email protected]>",
7+
]
68
license = "MIT License"
79
readme = "README.md"
810
homepage = "http://github.com/pfouque/django-fsm-2"
@@ -15,10 +17,9 @@ classifiers = [
1517
'License :: OSI Approved :: MIT License',
1618
'Operating System :: OS Independent',
1719
"Framework :: Django",
18-
"Framework :: Django :: 3.2",
19-
"Framework :: Django :: 4.1",
2020
"Framework :: Django :: 4.2",
2121
"Framework :: Django :: 5.0",
22+
"Framework :: Django :: 5.1",
2223
'Programming Language :: Python',
2324
'Programming Language :: Python :: 3',
2425
'Programming Language :: Python :: 3.8',
@@ -32,7 +33,7 @@ packages = [{ include = "django_fsm" }]
3233

3334
[tool.poetry.dependencies]
3435
python = "^3.8"
35-
django = ">=3.2"
36+
django = ">=4.2"
3637

3738
[tool.poetry.group.graphviz.dependencies]
3839
graphviz = "*"
@@ -55,13 +56,17 @@ target-version = "py38"
5556
fix = true
5657

5758
[tool.ruff.lint]
58-
59+
# select = ["ALL"]
5960
extend-select = [
6061
"F", # Pyflakes
6162
"E", # pycodestyle
6263
"W", # pycodestyle
6364
"UP", # pyupgrade
6465
"I", # isort
66+
"PERF",
67+
"RET",
68+
"C",
69+
# "B",
6570
]
6671
fixable = ["I"]
6772

tests/testapp/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def hide(self):
121121
permission=lambda self, u: u.has_perm("testapp.can_remove_post"),
122122
)
123123
def remove(self):
124-
raise Exception("No rights to delete %s" % self)
124+
raise Exception(f"No rights to delete {self}")
125125

126126
@transition(field=state, source="new", target="restored", on_error="failed", permission=can_restore)
127127
def restore(self):

tests/testapp/tests/test_custom_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class BlogPostWithCustomData(models.Model):
1414
def publish(self):
1515
pass
1616

17-
@transition(field=state, source="published", target="destroyed", custom=dict(label="Destroy", type="manual"))
17+
@transition(field=state, source="published", target="destroyed", custom={"label": "Destroy", "type": "manual"})
1818
def destroy(self):
1919
pass
2020

21-
@transition(field=state, source="published", target="review", custom=dict(label="Periodic review", type="automated"))
21+
@transition(field=state, source="published", target="review", custom={"label": "Periodic review", "type": "automated"})
2222
def review(self):
2323
pass
2424

tox.ini

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
[tox]
22
envlist =
3-
py{38,39,310}-dj32
4-
py{38,39,310}-dj40
5-
py{38,39,310,311}-dj41
63
py{38,39,310,311}-dj42
74
py{310,311,312}-dj50
5+
py{310,311,312}-dj51
86
skipsdist = True
97

108
[testenv]
119
deps =
12-
dj32: Django==3.2
13-
dj40: Django==4.0
14-
dj41: Django==4.1
1510
dj42: Django==4.2
1611
dj50: Django==5.0
12+
dj51: Django==5.1b1
1713

1814
django-guardian==2.4.0
1915
graphviz==0.20.1

0 commit comments

Comments
 (0)