@@ -71,14 +71,13 @@ def name(self):
71
71
def has_perm (self , instance , user ):
72
72
if not self .permission :
73
73
return True
74
- elif callable (self .permission ):
74
+ if callable (self .permission ):
75
75
return bool (self .permission (instance , user ))
76
- elif user .has_perm (self .permission , instance ):
76
+ if user .has_perm (self .permission , instance ):
77
77
return True
78
- elif user .has_perm (self .permission ):
78
+ if user .has_perm (self .permission ):
79
79
return True
80
- else :
81
- return False
80
+ return False
82
81
83
82
def __hash__ (self ):
84
83
return hash (self .name )
@@ -100,7 +99,7 @@ def get_available_FIELD_transitions(instance, field):
100
99
curr_state = field .get_state (instance )
101
100
transitions = field .transitions [instance .__class__ ]
102
101
103
- for name , transition in transitions .items ():
102
+ for transition in transitions .values ():
104
103
meta = transition ._django_fsm
105
104
if meta .has_transition (curr_state ) and meta .conditions_met (instance , curr_state ):
106
105
yield meta .get_transition (curr_state )
@@ -177,18 +176,19 @@ def conditions_met(self, instance, state):
177
176
178
177
if transition is None :
179
178
return False
180
- elif transition .conditions is None :
179
+
180
+ if transition .conditions is None :
181
181
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 )
184
184
185
185
def has_transition_perm (self , instance , state , user ):
186
186
transition = self .get_transition (state )
187
187
188
188
if not transition :
189
189
return False
190
- else :
191
- return transition .has_perm (instance , user )
190
+
191
+ return transition .has_perm (instance , user )
192
192
193
193
def next_state (self , current_state ):
194
194
transition = self .get_transition (current_state )
@@ -341,7 +341,7 @@ def get_all_transitions(self, instance_cls):
341
341
"""
342
342
transitions = self .transitions [instance_cls ]
343
343
344
- for name , transition in transitions .items ():
344
+ for transition in transitions .values ():
345
345
meta = transition ._django_fsm
346
346
347
347
for transition in meta .transitions .values ():
@@ -565,7 +565,7 @@ def can_proceed(bound_method, check_conditions=True):
565
565
conditions.
566
566
"""
567
567
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" )
569
569
570
570
meta = bound_method ._django_fsm
571
571
self = bound_method .__self__
@@ -579,7 +579,7 @@ def has_transition_perm(bound_method, user):
579
579
Returns True if model in state allows to call bound_method and user have rights on it
580
580
"""
581
581
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" )
583
583
584
584
meta = bound_method ._django_fsm
585
585
self = bound_method .__self__
0 commit comments