@@ -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__
0 commit comments