dabo Commit
Revision 4040
Date: 2008-04-15 16:16:04 -0700 (Tue, 15 Apr 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/4040
Changed:
U trunk/dabo/biz/dBizobj.py
Log:
Commented out the raising of ValueError in getDataTypeForField(),
as I was getting lots of Dabo Error Log entries for virtual fields.
This matches the doc which says the function will return None if
there isn't any DataStructure information for the field.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2008-04-15 12:50:04 UTC (rev 4039)
+++ trunk/dabo/biz/dBizobj.py 2008-04-15 23:16:04 UTC (rev 4040)
@@ -1451,7 +1451,8 @@
fldInfo = [rec[1] for rec in ds
if rec[0] == fld][0]
except IndexError:
- raise ValueError, _("Field '%s' does not exist in the DataStructure") % fld
+ return None
+ #raise ValueError, _("Field '%s' does not exist in the DataStructure") % fld
return dabo.db.getPythonType(fldInfo)
On Apr 15, 2008, at 6:16 PM, Paul McNett wrote:
> Commented out the raising of ValueError in getDataTypeForField(),
> as I was getting lots of Dabo Error Log entries for virtual fields.
>
> This matches the doc which says the function will return None if
> there isn't any DataStructure information for the field.
This was the 'syntax error' that John Fabiani was getting last week.
I had created a fix and sent it to him, and was waiting for
confirmation that it solved his problem. I know that the docstring
said it would return None if the field isn't in the DataStructure, but
I think that if we can determine the field type, we should return it,
no?
Here's my fix; try it out on your stuff and let me know if it works
for you. If it's OK, we can change the docstring to reflect this change.
def getDataTypeForField(self, fld):
"""Given a field name, returns its Python type, or None if no
DataStructure information is available.
"""
if fld in self.VirtualFields:
return type(self.getFieldVal(fld))
ds = self.getDataStructure()
if not ds:
return None
try:
fldInfo = [rec[1] for rec in ds
if rec[0] == fld][0]
except IndexError:
raise ValueError, _("Field '%s' does not exist in the
DataStructure") % fld
return dabo.db.getPythonType(fldInfo)
-- Ed Leafe
Sorry if I had to do something. I have been waiting for you. I still get an
error on the virtual fields for my children.
On Tuesday 15 April 2008 04:53:35 pm Ed Leafe wrote:
> On Apr 15, 2008, at 6:16 PM, Paul McNett wrote:
> > Commented out the raising of ValueError in getDataTypeForField(),
> > as I was getting lots of Dabo Error Log entries for virtual fields.
> >
> > This matches the doc which says the function will return None if
> > there isn't any DataStructure information for the field.
>
> This was the 'syntax error' that John Fabiani was getting last week.
> I had created a fix and sent it to him, and was waiting for
> confirmation that it solved his problem. I know that the docstring
> said it would return None if the field isn't in the DataStructure, but
> I think that if we can determine the field type, we should return it,
> no?
>
> Here's my fix; try it out on your stuff and let me know if it works
> for you. If it's OK, we can change the docstring to reflect this change.
>
> def getDataTypeForField(self, fld):
> """Given a field name, returns its Python type, or None if no
> DataStructure information is available.
> """
> if fld in self.VirtualFields:
> return type(self.getFieldVal(fld))
> ds = self.getDataStructure()
> if not ds:
> return None
> try:
> fldInfo = [rec[1] for rec in ds
> if rec[0] == fld][0]
> except IndexError:
> raise ValueError, _("Field '%s' does not exist in the
> DataStructure") % fld
> return dabo.db.getPythonType(fldInfo)
>
>
> -- Ed Leafe
>
>
>
>
>
[excessive quoting removed by server]
On Apr 15, 2008, at 7:13 PM, johnf wrote:
> Sorry if I had to do something. I have been waiting for you. I
> still get an
> error on the virtual fields for my children.
What is the error? Is it returning the correct type?
-- Ed Leafe
On Tuesday 15 April 2008 05:20:04 pm Ed Leafe wrote:
> On Apr 15, 2008, at 7:13 PM, johnf wrote:
> > Sorry if I had to do something. I have been waiting for you. I
> > still get an
> > error on the virtual fields for my children.
>
> What is the error? Is it returning the correct type?
>
> -- Ed Leafe
>
>
>
>
>
[excessive quoting removed by server]
On Tuesday 15 April 2008 08:17:03 pm johnf wrote:
> On Tuesday 15 April 2008 05:20:04 pm Ed Leafe wrote:
> > On Apr 15, 2008, at 7:13 PM, johnf wrote:
> > > Sorry if I had to do something. I have been waiting for you. I
> > > still get an
> > > error on the virtual fields for my children.
> >
> > What is the error? Is it returning the correct type?
> >
> > -- Ed Leafe
For some reason the list is not allowing me to provide the info you need.
Field 'prodcostDescript' does not exist in the DataStructure is the error.
below is the class.
class PublicagprodcostBizobj(dabo.biz.dBizobj):
def afterInit(self):
self.DataSource = "public.agprodcost"
self.VirtualFields={'prodcostDescript':self.costtype}
--
John Fabiani
On Apr 16, 2008, at 9:40 AM, johnf wrote:
> For some reason the list is not allowing me to provide the info you
> need.
It's called "failure to trim replies". It recognizes its own footer
in a quote, and considers that and anything below it to be waste.
> Field 'prodcostDescript' does not exist in the DataStructure is the
> error.
> below is the class.
>
> class PublicagprodcostBizobj(dabo.biz.dBizobj):
> def afterInit(self):
> self.DataSource = "public.agprodcost"
> self.VirtualFields={'prodcostDescript':self.costtype}
So this is being called before the afterInit() of the bizobj has run?
Can you change getDataTypeForField() to the code below, and let me
know what it prints out?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def getDataTypeForField(self, fld):
"""Given a field name, returns its Python type, or None if no
DataStructure information is available.
"""
lp = dabo.dBug.logPoint()
print "\n%s" % lp
print "VF KEYS: %s", str(self.VirtualFields.keys())
if fld in self.VirtualFields:
return type(self.getFieldVal(fld))
ds = self.getDataStructure()
if not ds:
return None
try:
fldInfo = [rec[1] for rec in ds
if rec[0] == fld][0]
except IndexError:
raise ValueError, _("Field '%s' does not exist in the
DataStructure") % fld
return dabo.db.getPythonType(fldInfo)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- Ed Leafe
On Wednesday 16 April 2008 08:19:13 am Ed Leafe wrote:
> So this is being called before the afterInit() of the bizobj has run?
I just keep my bizobj's in seperate files and import them in the
createBizobs(). But they follow the standard format that is created by
ClassDesigner. So the answer is no.
> Can you change getDataTypeForField() to the code below, and let me
> know what it prints out?
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> def getDataTypeForField(self, fld):
/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py:7852 in
MainLoop:
wx.PyApp.MainLoop(self)
/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py:7213 in
MainLoop:
return _core_.PyApp_MainLoop(*args, **kwargs)
/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py:14345 in
<lambda>:
lambda event: event.callable(*event.args, **event.kw) )
/home/johnf/downloads/dabo/dabo/ui/uiwx/dGrid.py:713 in
_setDataTypeFromDataField:
dt = self.Parent.typeFromDataField(fld)
/home/johnf/downloads/dabo/dabo/ui/uiwx/dGrid.py:1927 in typeFromDataField:
pyType = biz.getDataTypeForField(df)
/home/johnf/downloads/dabo/dabo/biz/dBizobj.py:1461 in getDataTypeForField:
lp = dabo.dBug.logPoint()
VF KEYS: %s ['prodcostDescript']
--
John Fabiani
Ed Leafe wrote:
> On Apr 15, 2008, at 6:16 PM, Paul McNett wrote:
>
>> Commented out the raising of ValueError in getDataTypeForField(),
>> as I was getting lots of Dabo Error Log entries for virtual fields.
>>
>> This matches the doc which says the function will return None if
>> there isn't any DataStructure information for the field.
>
>
> This was the 'syntax error' that John Fabiani was getting last week.
> I had created a fix and sent it to him, and was waiting for
> confirmation that it solved his problem. I know that the docstring
> said it would return None if the field isn't in the DataStructure, but
> I think that if we can determine the field type, we should return it,
> no?
>
> Here's my fix; try it out on your stuff and let me know if it works
> for you. If it's OK, we can change the docstring to reflect this change.
It results in an error if there aren't any records, and the virtual
field function assumes there is an active record:
Traceback (most recent call last):
File
"//Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/_core.py",
line 14364, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
File "/users/pmcnett/dabo/dabo/ui/uiwx/dGrid.py", line 713, in
_setDataTypeFromDataField
dt = self.Parent.typeFromDataField(fld)
File "/users/pmcnett/dabo/dabo/ui/uiwx/dGrid.py", line 1927, in
typeFromDataField
pyType = biz.getDataTypeForField(df)
File "/users/pmcnett/dabo/dabo/biz/dBizobj.py", line 1447, in
getDataTypeForField
return type(self.getFieldVal(fld))
File "/users/pmcnett/dabo/dabo/biz/dBizobj.py", line 1323, in getFieldVal
ret = cursor.getFieldVal(fld, row,
_rowChangeCallback=changeRowNumCallback)
File "/users/pmcnett/dabo/dabo/db/dCursorMixin.py", line 818, in
getFieldVal
raise dException.NoRecordsException, _("No records in the data set.")
Perhaps we should come up with a way to specify what the return values
are for the virtual fields? Brainstorms:
+ Add virtual fields to DataStructure
- no good, because the appdev will have to remember to maintain
info in more than one place; plus, DataStructure really implies
real data, not virtual data.
+ Add return type information to the VirtualFields dict:
self.VirtualFields = {"number_panels": (self.get_number_panels, int)}
This could be made backwards-compatible by ignoring the lack of a
specified return type.
Paul
On Wednesday 16 April 2008 09:01:00 am Paul McNett wrote:
> + Add return type information to the VirtualFields dict:
> =A0 =A0self.VirtualFields =3D {"number_panels": (self.get_number_panels, =
int)}
That would work for me. But is it very pythonic? =20
=2D-=20
John Fabiani