AttributeError: 'Rows' object has no attribute 'append'

254 views
Skip to first unread message

Annet

unread,
Aug 12, 2012, 2:46:52 AM8/12/12
to web...@googlegroups.com
I have the following function:

def classes():
    response.view='site/classes.html'
    alert=''
    if session[request.args(0)].tab_1:
        weekday=request.now.weekday()+1
        query1=db((db.Timetable.nodeID==session[request.args(0)].id)&(db.Timetable.dayID==db.Day.id)&\
        (((db.Timetable.dayID==weekday)&(db.Timetable.startTime>request.now))|(db.Timetable.dayID>weekday)))
        if int(query1.count())<8:
            i=query1.count()
            rows=query1.select(db.Timetable.ALL,db.Day.name,orderby=db.Timetable.dayID|db.Timetable.startTime,limitby=(0,i))
            morerows=db((db.Timetable.nodeID==session[request.args(0)].id)&(db.Timetable.dayID==db.Day.id)&(db.Timetable.dayID>=1))\
            .select(db.Timetable.ALL,db.Day.name,orderby=db.Timetable.dayID|db.Timetable.startTime,limitby=(0,8-i))
            for row in morerows:
                rows.append(row)
        else:
            rows=query1.select(db.Timetable.ALL,db.Day.name,orderby=db.Timetable.dayID|db.Timetable.startTime,limitby=(0,8))
        if not rows:
            response.flash='Geen informatie over lessen beschikbaar'
            alert='alert-info' # to set alert class for flash
    return dict(rows=rows,alert=alert)

When I run this function I get the following error:

Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
File "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/site.py", line 190, in <module>
File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 173, in <lambda>
self._caller = lambda f: f()
File "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/site.py", line 146, in classes
rows.append(row)
AttributeError: 'Rows' object has no attribute 'append'

When I comment out row.append(row) and return rows and morerows rows contains 3 records and morerows 5. Why doesn't this work?


Kind regards,

Annet

Alan Etkin

unread,
Aug 12, 2012, 8:42:35 AM8/12/12
to web...@googlegroups.com
When I comment out row.append(row) and return rows and morerows rows contains 3 records and morerows 5. Why doesn't this work?

If you want a unified Rows class instance to be handled by the action view, I think that you need a complete db query as input before calling .select, because, I'm almost sure that adding rows on the fly to a Rows instance is not supported.

An alternative would be to use a list object as result instead of Rows to add the Row instances, in that case you will be able to do <list object>.append(row).

Anthony

unread,
Aug 12, 2012, 10:46:52 AM8/12/12
to web...@googlegroups.com
Instead of rows.append(morerows), you can do:

rows &= morerows

rows1 & rows2 will append rows2 to rows1, and rows1 | rows2 does the same but removes from rows2 any duplicates of rows that appear in rows1. In addition to & and |, you can also use &= and |=, as in the above example.

This information is top secret, so please don't tell anyone. ;-)

Anthony

Annet

unread,
Aug 12, 2012, 12:08:20 PM8/12/12
to web...@googlegroups.com
Hi Anthony,

Thanks for your reply. Problem solved!


This information is top secret, so please don't tell anyone. ;-)

My lips are sealed ;-)


Best regards,

Annet.
Reply all
Reply to author
Forward
0 new messages