Well,
I don't know if these is the best approach, but I have a solution
to this problem...
To don't change the source code of the framework, I make a copy of
the original form.py called gae_form.py(and put this file in the same
level of code.py) and in this file I put/change this places/codes:
1) Add this imports in the begin of the file:
import logging
from google.appengine.ext import db
2) Change the imports:
[before]
import webapi as web
import utils, net
[after]
import web.webapi as web
import web.utils as utils, web.net as net
3) Change implementation of the function attrget():
[before ]
def attrget(obj, attr, value=None):
if hasattr(obj, 'has_key') and obj.has_key(attr): return obj[attr]
if hasattr(obj, attr): return getattr(obj, attr)
return value
[after ]
def attrget(obj, attr, value=None):
if isinstance(obj,db.Model):
try:
if attr == 'key':
return obj.key()
gae_attribute = getattr(obj,attr)
if isinstance(gae_attribute,db.Model):
id_reference = gae_attribute.key().id()
return id_reference
else:
return gae_attribute
except Exception, ex:
logging.debug(ex)
else:
if hasattr(obj, 'has_key') and obj.has_key(attr): return
obj[attr]
if hasattr(obj, attr): return getattr(obj, attr)
return value
And finally, my forms.py (my file with the definitions of the forms
used in the app):
# from web import form
import gae_form as form
import data
def getPostForm():
category_list = data.all_categories()
category_options = [(row.key().id(), row.title) for row in
category_list]
post_form = form.Form(
form.Hidden('key'),
form.Dropdown('category', category_options),
form.Textbox('title'),
form.Textarea('body'),
form.Dropdown('language', [('pt', 'Portuguese'), ('en',
'English')]),
form.Button('Submit!')
)
return post_form
def getCategoryForm():
category_form = form.Form(
form.Textbox('title'),
form.Button('Submit!')
)
return category_form
Well, now I have a form to manipulate a GAE table/entity with a
Dropdown control based in another table/entity that work's fine.
My last question is: This is the best approach / solution
implementation ?
Any suggestion will be very welcome.
Thanks for all help.
-- Leandro.
--
You received this message because you are subscribed to the Google Groups
"web.py" 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/webpy?hl=en.