dabo Commit
Revision 4722
Date: 2008-11-27 13:01:56 -0800 (Thu, 27 Nov 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4722

Changed:
U   trunk/ide/ClassDesignerFormMixin.py

Log:
Modified the process of adding DE-bound controls so that if the user elects to 
create bizobj code, it is not placed in the form's code, but written to a file 
in the app's biz directory. If no biz directory can be found, the user will be 
prompted for a location to save the file. The biz/__init__.py file is also 
updated to import the bizobj.

The form's createBizobjs() method now only adds the code to create the bizobj 
using the app.biz module reference.



Diff:
Modified: trunk/ide/ClassDesignerFormMixin.py
===================================================================
--- trunk/ide/ClassDesignerFormMixin.py 2008-11-27 20:58:23 UTC (rev 4721)
+++ trunk/ide/ClassDesignerFormMixin.py 2008-11-27 21:01:56 UTC (rev 4722)
@@ -818,20 +818,37 @@
                        cd = {}
                currCode = cd.get("createBizobjs", "")
                
-               bizcode = self.getBizobjTemplate()
+               bizCodeTemplate = self.getBizobjTemplate()
+               loadCodeTemplate = self.getBizobjLoadTemplate()
                addFlds = []
                for fld in flds:
-                       addFlds.append("\t\t\tself.addField(\"%s\")" % fld)
+                       addFlds.append("\t\tself.addField(\"%s\")" % fld)
                fldDefs = "\n".join(addFlds)
                tq = "\"" * 3
-               code = bizcode % locals()
+               bizcode = bizCodeTemplate % locals()
+               # Get the biz directory
+               bizdir = self.Application.getStandardAppDirectory("biz", 
os.path.abspath(self._classFile))
+               if not bizdir:
+                       bizdir = dabo.ui.getDirectory(message=_("Please select 
your bizobj directory"))
+               if not bizdir:
+                       if dabo.ui.areYouSure(message=_("Cannot create bizobj 
class without a directory. Do you want to copy the code to the clipboard?"),
+                                       title=_("Copy Bizobj Code"), 
cancelButton=False):
+                               self.Application.copyToClipboard(bizcode)
+               else:
+                       fname = "%(tblTitle)sBizobj.py" % locals()
+                       file(os.path.join(bizdir, fname), "w").write(bizcode)
+                       clsname = fname.strip(".py")
+                       file(os.path.join(bizdir, "__init__.py"), 
"a").write("\nfrom %(clsname)s import %(clsname)s\n" % locals())
+
+               # Now create the import code for the form.
+               loadcode = loadCodeTemplate % locals()
                if currCode:
                        # Add some blank lines
                        currCode += "\n\n"
                else:
                        # No 'def' line yet
                        currCode = "def createBizobjs(self):\n"
-               currCode += code
+               currCode += loadcode
                cd["createBizobjs"] = currCode
                rep[self] = cd
                self.Controller.updateCodeEditor()
@@ -1368,23 +1385,31 @@
 
 
        def getBizobjTemplate(self):
-               return """
-       class %(tblTitle)sBizobj(dabo.biz.dBizobj):
-               def afterInit(self):
-                       self.DataSource = "%(tbl)s"
-                       self.KeyField = "%(pk)s"
-                       self.addFrom("%(tbl)s")
+               return """#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import dabo
+
+class %(tblTitle)sBizobj(dabo.biz.dBizobj):
+       def afterInit(self):
+               self.DataSource = "%(tbl)s"
+               self.KeyField = "%(pk)s"
+               self.addFrom("%(tbl)s")
 %(fldDefs)s
 
-               def validateRecord(self):
-                       %(tq)sReturning anything other than an empty string from
-                       this method will prevent the data from being saved.
-                       %(tq)s
-                       ret = ""
-                       # Add your business rules here. 
-                       return ret
+       def validateRecord(self):
+               %(tq)sReturning anything other than an empty string from
+               this method will prevent the data from being saved.
+               %(tq)s
+               ret = ""
+               # Add your business rules here. 
+               return ret
 
-       %(lowbiz)s = %(tblTitle)sBizobj(self.Connection)
+"""
+
+       def getBizobjLoadTemplate(self):
+               return """
+       %(lowbiz)s = self.Application.biz.%(tblTitle)sBizobj(self.Connection)
        self.addBizobj(%(lowbiz)s)
 """    
                




_______________________________________________
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/[EMAIL PROTECTED]

Reply via email to