Hello,
I am querying the database using sqlalchemy
d=model.Useraddress()
x=d.get_by(USER_SID=345,ADDRESS_SID=2)
Then I pass x(the corresponding record) to my template
return dict(address=address_form,value=x, action=submit_action)
But when I want to prefill the widget form with values from sqlalchemy using:
<p><span>${address(value=value, action=action)}</span></p>
The values are not set
Am I missing something here or values from sqlalchemy query do not
correspond to widget fields?
It seems as it does but it needs to be the same case.
So I went into my widget class and I replaced the
"City" with "CITY" which caused the value to fill in.
It is the same case when saving from widget to sqlalchemy.
If your widget doesn't have CAPITAL names then you have to convert them.
def saveuser(self,**kwargs):
from string import upper
b.USER_SID=(int(max_id)+1)
#Assigning rest of the keys
for widgetkey in kwargs.keys():
j=upper(widgetkey)
setattr(b,j,kwargs[widgetkey])
CONCLUSION: When using sqlalchemy and widgets we need to name our
attributes in the widget using CAPITAL letters. when we use sqlalchemy
autoload function.
sqlalchemy:
user_table = sqlalchemy.Table('user', metadata, autoload=True)
widget:
class User(widgets.WidgetsList):
LASTNAME=widgets.TextField(label='Last Name',validator=validators.NotEmpty)
FIRSTNAME=widgets.TextField(label='First
Name',validator=validators.NotEmpty)
WAS THIS INTENDED? If not should it be documented somewhere or changed?
http://www.lucasmanual.com/mywiki/TurboGears
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---