dropdown control don't work's fine with table records in Google App Engine

Bug #582469 reported by Leandro Severino
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
web.py
New
Undecided
Unassigned

Bug Description

To reproduce the error, follow a example code:

# in the forms.py
result = data.all_categories() # this method return all records of table category in GAE/big table format.
args = [(row.key().id(), row.title) for row in result]
new_post = form.Form(
    form.Dropdown('category', args),
    form.Textbox('title'),
    form.Textarea('text'),
    form.Dropdown('language', [('pt', 'Portuguese'), ('en', 'English')]),
    form.Button('Submit!')
# in code.py
class Post:
    def GET(self):
        frm = forms.new_post()
        return render.full(render.form(frm))
    def POST(self):
        global last_updated
        frm = forms.new_post()
        if frm.validates(): # in this point the error occurs.
            data.save_entry(frm.d)
            last_updated = data.last_updated()
            raise web.seeother('/')
        else:
            return render.full(render.form(frm))

IMHO the root cause of the problem is the 'big table' format, I say this because the form generated by the GET method is correct(It has the <option value="1">Category A</option>, <option value="2">Category B</option>) but when I submit the form and the forms.validates() is called the error occurs.

The problem occurs in the forms.py in this function:
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

generate this error:
<type 'exceptions.AttributeError'>: 'unicode' object has no attribute 'has_key'
      args = ("'unicode' object has no attribute 'has_key'",)
      message = "'unicode' object has no attribute 'has_key'"

Tags: appengine
Revision history for this message
Leandro Severino (leandro-professionalit) wrote :

I don't know if this is the best approach, but I have a solution to this problem in this thread:
http://groups.google.com/group/webpy/browse_thread/thread/484cb3fadac5de32/94634856c335d001#94634856c335d001

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.