18
18
from django_fsm .signals import pre_transition
19
19
20
20
__all__ = [
21
- "TransitionNotAllowed" ,
21
+ "GET_STATE" ,
22
+ "RETURN_VALUE" ,
22
23
"ConcurrentTransition" ,
23
- "FSMFieldMixin " ,
24
+ "ConcurrentTransitionMixin " ,
24
25
"FSMField" ,
26
+ "FSMFieldMixin" ,
25
27
"FSMIntegerField" ,
26
28
"FSMKeyField" ,
27
- "ConcurrentTransitionMixin" ,
28
- "transition" ,
29
+ "TransitionNotAllowed" ,
29
30
"can_proceed" ,
30
31
"has_transition_perm" ,
31
- "GET_STATE" ,
32
- "RETURN_VALUE" ,
32
+ "transition" ,
33
33
]
34
34
35
35
36
- class TransitionNotAllowed (Exception ):
36
+ class TransitionNotAllowed (Exception ): # noqa: N818
37
37
"""Raised when a transition is not allowed"""
38
38
39
39
def __init__ (self , * args , ** kwargs ):
@@ -42,11 +42,11 @@ def __init__(self, *args, **kwargs):
42
42
super ().__init__ (* args , ** kwargs )
43
43
44
44
45
- class InvalidResultState (Exception ):
45
+ class InvalidResultState (Exception ): # noqa: N818
46
46
"""Raised when we got invalid result state"""
47
47
48
48
49
- class ConcurrentTransition (Exception ):
49
+ class ConcurrentTransition (Exception ): # noqa: N818
50
50
"""
51
51
Raised when the transition cannot be executed because the
52
52
object has become stale (state has been changed since it
@@ -91,7 +91,7 @@ def __eq__(self, other):
91
91
return False
92
92
93
93
94
- def get_available_FIELD_transitions (instance , field ):
94
+ def get_available_FIELD_transitions (instance , field ): # noqa: N802
95
95
"""
96
96
List of transitions available in current model state
97
97
with all conditions met
@@ -105,14 +105,14 @@ def get_available_FIELD_transitions(instance, field):
105
105
yield meta .get_transition (curr_state )
106
106
107
107
108
- def get_all_FIELD_transitions (instance , field ):
108
+ def get_all_FIELD_transitions (instance , field ): # noqa: N802
109
109
"""
110
110
List of all transitions available in current model state
111
111
"""
112
112
return field .get_all_transitions (instance .__class__ )
113
113
114
114
115
- def get_available_user_FIELD_transitions (instance , user , field ):
115
+ def get_available_user_FIELD_transitions (instance , user , field ): # noqa: N802
116
116
"""
117
117
List of transitions available in current model state
118
118
with all conditions met and user have rights on it
@@ -211,7 +211,7 @@ class FSMFieldDescriptor:
211
211
def __init__ (self , field ):
212
212
self .field = field
213
213
214
- def __get__ (self , instance , type = None ):
214
+ def __get__ (self , instance , instance_type = None ):
215
215
if instance is None :
216
216
return self
217
217
return self .field .get_state (instance )
@@ -234,7 +234,9 @@ def __init__(self, *args, **kwargs):
234
234
self .state_proxy = {} # state -> ProxyClsRef
235
235
236
236
state_choices = kwargs .pop ("state_choices" , None )
237
- choices = kwargs .get ("choices" , None )
237
+ choices = kwargs .get (
238
+ "choices" ,
239
+ )
238
240
if state_choices is not None and choices is not None :
239
241
raise ValueError ("Use one of choices or state_choices value" )
240
242
@@ -295,7 +297,9 @@ def change_state(self, instance, method, *args, **kwargs):
295
297
)
296
298
if not meta .conditions_met (instance , current_state ):
297
299
raise TransitionNotAllowed (
298
- f"Transition conditions have not been met for method '{ method_name } '" , object = instance , method = method
300
+ f"Transition conditions have not been met for method '{ method_name } '" ,
301
+ object = instance ,
302
+ method = method ,
299
303
)
300
304
301
305
next_state = meta .next_state (current_state )
@@ -344,8 +348,7 @@ def get_all_transitions(self, instance_cls):
344
348
for transition in transitions .values ():
345
349
meta = transition ._django_fsm
346
350
347
- for transition in meta .transitions .values ():
348
- yield transition
351
+ yield from meta .transitions .values ()
349
352
350
353
def contribute_to_class (self , cls , name , ** kwargs ):
351
354
self .base_cls = cls
@@ -406,8 +409,6 @@ class FSMIntegerField(FSMFieldMixin, models.IntegerField):
406
409
Same as FSMField, but stores the state value in an IntegerField.
407
410
"""
408
411
409
- pass
410
-
411
412
412
413
class FSMKeyField (FSMFieldMixin , models .ForeignKey ):
413
414
"""
@@ -557,7 +558,7 @@ def _change_state(instance, *args, **kwargs):
557
558
return inner_transition
558
559
559
560
560
- def can_proceed (bound_method , check_conditions = True ):
561
+ def can_proceed (bound_method , check_conditions = True ): # noqa: FBT002
561
562
"""
562
563
Returns True if model in state allows to call bound_method
563
564
@@ -597,25 +598,23 @@ def get_state(self, model, transition, result, args=[], kwargs={}):
597
598
raise NotImplementedError
598
599
599
600
600
- class RETURN_VALUE (State ):
601
+ class RETURN_VALUE (State ): # noqa: N801
601
602
def __init__ (self , * allowed_states ):
602
603
self .allowed_states = allowed_states if allowed_states else None
603
604
604
605
def get_state (self , model , transition , result , args = [], kwargs = {}):
605
- if self .allowed_states is not None :
606
- if result not in self .allowed_states :
607
- raise InvalidResultState (f"{ result } is not in list of allowed states\n { self .allowed_states } " )
606
+ if self .allowed_states is not None and result not in self .allowed_states :
607
+ raise InvalidResultState (f"{ result } is not in list of allowed states\n { self .allowed_states } " )
608
608
return result
609
609
610
610
611
- class GET_STATE (State ):
611
+ class GET_STATE (State ): # noqa: N801
612
612
def __init__ (self , func , states = None ):
613
613
self .func = func
614
614
self .allowed_states = states
615
615
616
616
def get_state (self , model , transition , result , args = [], kwargs = {}):
617
617
result_state = self .func (model , * args , ** kwargs )
618
- if self .allowed_states is not None :
619
- if result_state not in self .allowed_states :
620
- raise InvalidResultState (f"{ result_state } is not in list of allowed states\n { self .allowed_states } " )
618
+ if self .allowed_states is not None and result_state not in self .allowed_states :
619
+ raise InvalidResultState (f"{ result_state } is not in list of allowed states\n { self .allowed_states } " )
621
620
return result_state
0 commit comments