Index
2012-07-21 13:20 – Dave Kelly : [dabo-users] Populating a dropdown list
2012-07-22 18:14 – Ed Leafe : Re: [dabo-users] Populating a dropdown list
2012-07-24 20:58 – John Fabiani : Re: [dabo-users] Populating a dropdown list
2012-07-27 13:25 – Dave Kelly : Re: [dabo-users] Populating a dropdown list
2012-07-27 13:52 – Ed Leafe : Re: [dabo-users] Populating a dropdown list
2012-07-28 04:58 – Dave Kelly : Re: [dabo-users] Populating a dropdown list
Back to top
[dabo-users] Populating a dropdown list

Author: Dave Kelly

Posted: 2012-07-21 13:20:09   Link

Trying to follow the PyCon tutorial, I am attempting to populate a dropdown

list. The underlying table for the dropdown list contains only one field

which is the primary key. I can't seem to get the list to populate. The

steps I took to achieve this were:

1. I created a script in the /biz directory called

PublicdepartmentsBizobj.py which contains:

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import dabo

class PublicdepartmentsBizobj(dabo.biz.dBizobj):

def afterinit(self):

self.datasource = "public.departments"

self.keyfield = "department"

self.addfrom("public.departments")

self.addfield("department")

def validateRecord(self):

"""Returning anything other than an empty

string from

this method will prevent the data from being

saved.

"""

ret = ""

# Add your business rules here.

return ret

def getNamesAndKeys(self):

crs = self.getTempCursor()

crs.execute("select department from

public.departments order by department")

ds = crs.getDataSet()

names = [rec["department"] for rec in ds]

keys = [rec["department"] for rec in ds]

return(names, keys)

My createBizobjs() method for the form contains:

def createBizobjs(self):

publicemployeesBizobj =

self.Application.biz.PublicemployeesBizobj(self.Connection)

self.addBizobj(publicemployeesBizobj)

publicdepartmentsBizobj =

self.Application.biz.PublicdepartmentsBizobj(self.Connection)

self.addBizobj(publicdepartmentsBizobj)

I set the DataSource property of my dropdownlist control to

"public.departments". I set the DataField property to "department". The

ValueMode is set to "Key" (I also tried "String"). RegID is set to

"department_list".

The afterInitAll method is as follows:

def afterInitAll(self):

departmentBiz = self.getBizobj("public.departments")

names, keys = departmentBiz.getNamesAndKeys()

self.department_list.Choices = names

self.department_list.Keys = keys

self.department_list.ValueMode = "Key"

self.requery()

I closed the ClassDesigner and updated my main.py to the following:

import dabo

dabo.ui.loadUI("wx")

app = dabo.dApp()

app.MainFormClass = "time_clock.cdxml"

app.start()

The form loads but the dropdown list is empty. Furthermore, the console has

the following output. I am sure I have missed something blatently obvious

but I wil need it pointed out to me.

dave@dave-Mint ~/time $ python main.py

/usr/local/lib/python2.7/dist-packages/dabo/lib/SimpleCrypt.py:52:

UserWarning: WARNING: SimpleCrypt is not secure. Please see

http://wiki.dabodev.com/SimpleCrypt for more information

warnings.warn("WARNING: SimpleCrypt is not secure. Please see

http://wiki.dabodev.com/SimpleCrypt for more information")

Traceback (most recent call last):

File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py",

line 14636, in <lambda>

lambda event: event.callable(*event.args, **event.kw) )

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py",

line 348, in _afterInitAll

self.afterInitAll()

File "/tmp/tmpQOkWFW.py", line 173, in afterInitAll

names, keys = departmentBiz.getNamesAndKeys()

AttributeError: 'NoneType' object has no attribute 'getNamesAndKeys'

Dave Kelly

The Priory Inn

01666 502 251

<http://www.theprioryinn.co.uk/> www.theprioryinn.co.uk

"Dining in a 30 Mile Food Zone"

--- StripMime Report -- processed MIME parts ---

multipart/alternative

text/plain (text body -- kept)

text/html

---

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/004501cd676d$76358e90$62a0abb0$@theprioryinn.co.uk

©2012 Dave Kelly
Back to top
Re: [dabo-users] Populating a dropdown list

Author: Ed Leafe

Posted: 2012-07-22 18:14:21   Link

On Jul 21, 2012, at 1:20 PM, Dave Kelly wrote:

> def afterInitAll(self):

> departmentBiz = self.getBizobj("public.departments")

> names, keys = departmentBiz.getNamesAndKeys()

- and -

> Traceback (most recent call last):

> File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py",

> line 14636, in <lambda>

> lambda event: event.callable(*event.args, **event.kw) )

> File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py",

> line 348, in _afterInitAll

> self.afterInitAll()

> File "/tmp/tmpQOkWFW.py", line 173, in afterInitAll

> names, keys = departmentBiz.getNamesAndKeys()

> AttributeError: 'NoneType' object has no attribute 'getNamesAndKeys'

It looks like the problem is the DataSource for the bizobj. I haven't worked with schemas too much; John Fabiani can probably help here. But the traceback shows that 'departmentBiz' is None, meaning that the getBizobj() call couldn't find a bizobj with that DataSource.

John, any suggestions for how to properly reference a DataSource with a schema path?

-- Ed Leafe

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/B1A6F008-DA95-4EDE-979C-26EDABE519C7@leafe.com

©2012 Ed Leafe
Back to top
Re: [dabo-users] Populating a dropdown list

Author: John Fabiani

Posted: 2012-07-24 20:58:53   Link

On 07/21/2012 11:20 AM, Dave Kelly wrote:

> Trying to follow the PyCon tutorial, I am attempting to populate a dropdown

> list. The underlying table for the dropdown list contains only one field

> which is the primary key. I can't seem to get the list to populate. The

> steps I took to achieve this were:

>

>

>

> 1. I created a script in the /biz directory called

> PublicdepartmentsBizobj.py which contains:

>

>

>

> #!/usr/bin/env python

>

> # -*- coding: utf-8 -*-

>

>

>

> import dabo

>

>

>

> class PublicdepartmentsBizobj(dabo.biz.dBizobj):

>

> def afterinit(self):

>

> self.datasource = "public.departments"

>

> self.keyfield = "department"

>

> self.addfrom("public.departments")

>

> self.addfield("department")

>

>

>

> def validateRecord(self):

>

> """Returning anything other than an empty

> string from

>

> this method will prevent the data from being

> saved.

>

> """

>

> ret = ""

>

> # Add your business rules here.

>

> return ret

>

>

>

> def getNamesAndKeys(self):

>

> crs = self.getTempCursor()

>

> crs.execute("select department from

> public.departments order by department")

>

> ds = crs.getDataSet()

>

> names = [rec["department"] for rec in ds]

>

> keys = [rec["department"] for rec in ds]

>

>

>

> return(names, keys)

>

>

>

> My createBizobjs() method for the form contains:

>

>

>

> def createBizobjs(self):

>

> publicemployeesBizobj =

> self.Application.biz.PublicemployeesBizobj(self.Connection)

>

> self.addBizobj(publicemployeesBizobj)

>

> publicdepartmentsBizobj =

> self.Application.biz.PublicdepartmentsBizobj(self.Connection)

>

> self.addBizobj(publicdepartmentsBizobj)

>

>

>

>

>

> I set the DataSource property of my dropdownlist control to

> "public.departments". I set the DataField property to "department". The

> ValueMode is set to "Key" (I also tried "String"). RegID is set to

> "department_list".

>

>

>

> The afterInitAll method is as follows:

>

>

>

> def afterInitAll(self):

>

> departmentBiz = self.getBizobj("public.departments")

>

> names, keys = departmentBiz.getNamesAndKeys()

>

> self.department_list.Choices = names

>

> self.department_list.Keys = keys

>

> self.department_list.ValueMode = "Key"

>

> self.requery()

>

>

>

>

>

> I closed the ClassDesigner and updated my main.py to the following:

>

>

>

> import dabo

>

> dabo.ui.loadUI("wx")

>

>

>

> app = dabo.dApp()

>

>

>

> app.MainFormClass = "time_clock.cdxml"

>

>

>

> app.start()

>

>

>

> The form loads but the dropdown list is empty. Furthermore, the console has

> the following output. I am sure I have missed something blatently obvious

> but I wil need it pointed out to me.

>

>

>

> dave@dave-Mint ~/time $ python main.py

>

> /usr/local/lib/python2.7/dist-packages/dabo/lib/SimpleCrypt.py:52:

> UserWarning: WARNING: SimpleCrypt is not secure. Please see

> http://wiki.dabodev.com/SimpleCrypt for more information

>

> warnings.warn("WARNING: SimpleCrypt is not secure. Please see

> http://wiki.dabodev.com/SimpleCrypt for more information")

>

> Traceback (most recent call last):

>

> File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py",

> line 14636, in<lambda>

>

> lambda event: event.callable(*event.args, **event.kw) )

>

> File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py",

> line 348, in _afterInitAll

>

> self.afterInitAll()

>

> File "/tmp/tmpQOkWFW.py", line 173, in afterInitAll

>

> names, keys = departmentBiz.getNamesAndKeys()

>

> AttributeError: 'NoneType' object has no attribute 'getNamesAndKeys'

>

>

>

> Dave Kelly

>

> The Priory Inn

>

> 01666 502 251

>

Sorry on vacation until the 30th. Also to be honest I can't recall what

the demo does?

I believe you should change the following:

self.addfrom("public.departments")

self.addfrom("departments") #that is the normal coding.

publicdepartmentsBizobj =

self.Application.biz.PublicdepartmentsBizobj(self.Connection)

self.publicdepartmentsBizobj = PublicdepartmentsBizobj(self.Connection)

self.addBizobj(self.publicdepartmentsBizobj)

#using "self" allows you access and you can avoid the getBizobj()

# should also fix the error

names, keys = self.publicdepartmentsBizobj.getNamesAndKeys()

self.department_list.Choices = names

self.department_list.Keys = keys

self.department_list.ValueMode = "Key"

self.requery() #watch out here what are you requerying????

Can I assume that you want both the Choices and and Keys to match? Normally, you would use some PK (normally an int) with some description text.

names = [rec["department"] for rec in ds]

keys = [rec["department"] for rec in ds]

they are retrieving the same data. If so why use the keys?

The dropdown list is sort of different - in that it requires that a value always exist for the record (even new ones). So I do something like this.

def countyChoices(self):

countyDS = self.escounty.getDataSet()

county_Choices=['<None>']

countyKeys=[0]

Now I have a '<None>' choice for key '0' that will match a new record value,

The above said I do not see a data issue.

Johnf

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/500F52DD.8090208@jfcomputer.com

©2012 John Fabiani
Back to top
Re: [dabo-users] Populating a dropdown list

Author: Dave Kelly

Posted: 2012-07-27 13:25:04   Link

I still haven't had luck with populating a dropdown list. I decided to not

use Postgresql to avoid any specific issues with that database and am

following the PyCon tutorial to the letter. The steps I took are as

follows:

1. I made the ClientBizobj.py look like this:

import dabo

class ClientBizobj(dabo.biz.dBizobj):

def afterInit(self):

self.DataSource = "clients"

self.KeyField = "pkid"

self.addFrom("clients")

self.addField("pkid")

self.addField("clientname")

self.addField("attn")

self.addField("rate")

self.addField("street1")

self.addField("street2")

self.addField("city")

self.addField("stateprov")

self.addField("postalcode")

def getNamesAndKeys(self):

crs = self.getTempCursor()

crs.execute("""select pkid, clientname

from clients

order by clientname""")

ds = crs.getDataSet()

# Create the lists

names = [rec["clientname"] for rec in ds]

keys = [rec["pkid"] for rec in ds]

return (names, keys)

I added this to the /biz/__init__.py

from ClientBizobj import ClientBizobj

In form design I added a dropdown list. I changed the datasource property

to "hours", the datafield property to clientfk, the valuemode property to

"Key" and the regid property to ClientList.

In the afterInitAll method I added:

clientBiz = self.getBizobj("clients")

names, keys = clientBiz.getNamesAndKeys()

self.ClientList.Choices = names

self.ClientList.Keys = keys

self.ClientList.ValueMode = "Key"

self.requery()

I updated main.py to use the hours form as the default form. I closed

everything down and ran main.py. This is the output:

dave@dave-Mint ~/pycon $ python main.py

/usr/local/lib/python2.7/dist-packages/dabo/lib/SimpleCrypt.py:52:

UserWarning: WARNING: SimpleCrypt is not secure. Please see

http://wiki.dabodev.com/SimpleCrypt for more information

warnings.warn("WARNING: SimpleCrypt is not secure. Please see

http://wiki.dabodev.com/SimpleCrypt for more information")

Traceback (most recent call last):

File "main.py", line 13, in <module>

app.start()

File "/usr/local/lib/python2.7/dist-packages/dabo/dApp.py", line 395, in

start

self.setup()

File "/usr/local/lib/python2.7/dist-packages/dabo/dApp.py", line 347, in

setup

self.initUIApp()

File "/usr/local/lib/python2.7/dist-packages/dabo/dApp.py", line 387, in

initUIApp

self.uiApp.setup()

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/uiApp.py", line

429, in setup

frm = self.dApp.MainForm = dabo.ui.createForm(mfc)

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/__init__.py",

line 1354, in createForm

frm = cls(*args, **kwargs)

File "/tmp/tmp91Jzpj.py", line 10, in __init__

super(dForm_15476, self).__init__(parent=parent,

attProperties=attProperties, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dForm.py", line

1062, in __init__

*args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dForm.py", line

49, in __init__

attProperties=attProperties, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dFormMixin.py",

line 76, in __init__

attProperties=attProperties, *args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py",

line 201, in __init__

self._afterInit()

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dForm.py", line

76, in _afterInit

super(BaseForm, self)._afterInit()

File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dFormMixin.py",

line 124, in _afterInit

self.createBizobjs()

File "/tmp/tmp91Jzpj.py", line 172, in createBizobjs

clientBizobj = self.Application.biz.clientBizobj(self.Connection)

AttributeError: 'module' object has no attribute 'clientBizobj'

Obviously, it doesn't like what I have done in the CreateBizobjs. This is

exactly the behaviour I was experiencing when I was using my own Postgres

database.

I am at a loss. Any help?

Thanks!

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/00d001cd6c25$25007870$6f016950$@theprioryinn.co.uk

©2012 Dave Kelly
Back to top
Re: [dabo-users] Populating a dropdown list

Author: Ed Leafe

Posted: 2012-07-27 13:52:41   Link

On Jul 27, 2012, at 1:25 PM, Dave Kelly wrote:

> I added this to the /biz/__init__.py

>

> from ClientBizobj import ClientBizobj

[snip]

> File "/tmp/tmp91Jzpj.py", line 172, in createBizobjs

> clientBizobj = self.Application.biz.clientBizobj(self.Connection)

> AttributeError: 'module' object has no attribute 'clientBizobj'

>

> Obviously, it doesn't like what I have done in the CreateBizobjs. This is

> exactly the behaviour I was experiencing when I was using my own Postgres

> database.

Looks like a capitalization error. Your class is "ClientBizobj", but your createBizobjs() code references "clientBizobj".

-- Ed Leafe

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/EEDFC800-20B0-47C3-ACF8-69F3E37AE113@leafe.com

©2012 Ed Leafe
Back to top
Re: [dabo-users] Populating a dropdown list

Author: Dave Kelly

Posted: 2012-07-28 04:58:07   Link

Thanks Ed! (I should have seen that myself.)

Dave Kelly

The Priory Inn

01666 502 251

www.theprioryinn.co.uk

"Dining in a 30 Mile Food Zone"

> -----Original Message-----

> From: dabo-users-bounces@leafe.com [mailto:dabo-users-

> bounces@leafe.com] On Behalf Of Ed Leafe

> Sent: 27 July 2012 19:53

> To: Dabo Users list

> Subject: Re: [dabo-users] Populating a dropdown list

>

> On Jul 27, 2012, at 1:25 PM, Dave Kelly wrote:

>

> > I added this to the /biz/__init__.py

> >

> > from ClientBizobj import ClientBizobj

>

> [snip]

>

> > File "/tmp/tmp91Jzpj.py", line 172, in createBizobjs

> > clientBizobj = self.Application.biz.clientBizobj(self.Connection)

> > AttributeError: 'module' object has no attribute 'clientBizobj'

> >

> > Obviously, it doesn't like what I have done in the CreateBizobjs.

> > This is exactly the behaviour I was experiencing when I was using my

> > own Postgres database.

>

> Looks like a capitalization error. Your class is "ClientBizobj", but

your

> createBizobjs() code references "clientBizobj".

>

>

> -- Ed Leafe

>

>

>

> _______________________________________________

> Post Messages to: Dabo-users@leafe.com

> Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

> Searchable Archives: http://leafe.com/archives/search/dabo-users

> This message: http://leafe.com/archives/byMID/EEDFC800-20B0-47C3-ACF8-

> 69F3E37AE113@leafe.com

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/007101cd6ca7$7d977ab0$78c67010$@theprioryinn.co.uk

©2012 Dave Kelly