STATE_TRANSITIONS dictionary values are changed to strings.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Fri, 28 Aug 2009 19:41:28 +0530
changeset 2831 a7ed56911653
parent 2830 5caf0d342696
child 2832 2a0a7e081caf
STATE_TRANSITIONS dictionary values are changed to strings. Our assumption that Python's functions and methods are first class members and using the method names directly as dictionary values doesn't seem to work. So we are using method names as strings in STATE_TRANSITIONS dictionary and getting the method object using getattr.
app/soc/modules/ghop/logic/models/task.py
--- a/app/soc/modules/ghop/logic/models/task.py	Fri Aug 28 13:17:32 2009 +0200
+++ b/app/soc/modules/ghop/logic/models/task.py	Fri Aug 28 19:41:28 2009 +0530
@@ -39,10 +39,10 @@
 
 
 STATE_TRANSITIONS = {
-    'Claimed': transitFromClaimed,
-    'NeedsReview': transitFromNeedsReview,
-    'ActionNeeded': transitFromActionNeeded,
-    'NeedsWork': transitFromNeedsWork,
+    'Claimed': 'transitFromClaimed',
+    'NeedsReview': 'transitFromNeedsReview',
+    'ActionNeeded': 'transitFromActionNeeded',
+    'NeedsWork': 'transitFromNeedsWork',
     }
 
 
@@ -292,7 +292,7 @@
     if entity.deadline and datetime.datetime.now() > entity.deadline:
       # calls a specific method to make a transition depending on the
       # task's current state
-      transit_func = STATE_TRANSITIONS[entity.status]
+      transit_func = getattr(self, STATE_TRANSITIONS[entity.status])
       update_dict = transit_func(entity)
 
       comment_properties = {