dabo Commit
Revision 3774
Date: 2007-12-05 21:13:13 -0800 (Wed, 05 Dec 2007)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/3774

Changed:
U   trunk/dabo/biz/dBizobj.py

Log:
First swat at trying to get docstrings in all the bizobj hook methods, without
copying/pasting mostly boilerplate text. I want to see if the api docs 
generate sanely, and if there are any problems with this approach that I'm not
considering, before expanding this to all the hooks.


Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2007-12-05 10:47:03 UTC (rev 3773)
+++ trunk/dabo/biz/dBizobj.py   2007-12-06 05:13:13 UTC (rev 3774)
@@ -1481,17 +1481,33 @@
 
 
 
+       def _makeHookMethod(name, actionSubject, actionVerb,  mainDoc=None, 
+                       additionalDoc=None):
+               mode = name[:5]
+               if mode == "befor":
+                       mode = "before"
+               if mainDoc is None:
+                       mainDoc = "Hook method called %s a %s is %s." % (mode, 
actionSubject, actionVerb)
+               if additionalDoc is None:
+                       if mode == "before":
+                               additionalDoc =  """Subclasses can put in 
additional code to run, and/or return a non-empty
+string to signify that the %s should not be %s. The contents
+of the string will be displayed to the user.""" % (actionSubject, actionVerb)
+                       else:
+                               additionalDoc = ""
+
+               def method(self):
+                       return ""
+               method.__doc__ =  "%s\n\n%s" % (mainDoc, additionalDoc)
+               method.func_name = name
+               return method
+
+
        ########## Pre-hook interface section ##############
-       def beforeNew(self):
-               """Called before a new record is added.
 
-               Subclasses can put in additional code to run, and/or return a 
non-empty
-               string to signify that the new record should not be added. The 
contents
-               of the string will be displayed to the user.
-               """
-               return ""
+       beforeNew = _makeHookMethod("beforeNew", "new record", "added")
+       beforeDelete = _makeHookMethod("beforeDelete", "record", "deleted")
 
-       def beforeDelete(self): return ""
        def beforeDeleteAllChildren(self): return ""
        def beforeFirst(self): return ""
        def beforePrior(self): return ""
@@ -1504,16 +1520,17 @@
        def beforeRequery(self): return ""
        def beforeChildRequery(self): return ""
        def beforeCreateCursor(self): return ""
+
+
        ########## Post-hook interface section ##############
-       def afterNew(self):
-               """Called after a new record is added.
 
-               Use this hook to change field values, or anything else you 
need. If you
-               change field values here, the memento system will catch it. If 
you want
-               to change field values and not trigger the memento system, use 
onNew()
-               instead.
-               """
-               pass
+       afterNew = _makeHookMethod("afterNew", "new record", "added",
+                       additionalDoc = \
+"""Use this hook to change field values of newly added records. If
+you change field values here, the memento system will catch it and
+prompt you to save if needed later on. If you want to change field
+values and not trigger the memento system, override onNew() instead.
+""")
 
        def afterDelete(self): pass
        def afterDeleteAllChildren(self): return ""




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to