I'm getting incorrect CSV output from a controller function that
selects from a table and then filters the results before returning it
as a list.  The CSV output contains a spurious 'update_record' column
where the values seem to be lambda functions.

Here is my controller function:

@service.csv
def download():
    requests = db().select(db.guest_request.ALL)
    requests_today = [request for request in requests if
request.created.date() == datetime.date.today()]
    return requests_today

db.guest_request.created is a datetime field.  I want the download
function to return exactly those rows where the 'created' datetime
value is a time in the current day.  I could not figure out how to
pass that criterion through the web2py DAL so I settled on doing it
explicitly with python datetime functions.  The list comprehension is
resulting in the right rows.

But the resulting CSV file looks like this:

    description,created,update_record,mac_address,requester,id
    Fred testing,2009-08-13 10:57:31,<function <lambda> at 0xb8b085a4>,
223344556677,fcy-st,29

The column headings all make sense except for the spurious
'update_record' one which does not correspond to any field in my
guest_request table.

If I return the unfiltered 'requests' object from the function the
resulting CSV data is fine with no spurious column.  But it has too
many rows then.

So, what is going wrong?  Is it wrong to return a list from a
service.csv function?  Do I have to turn it back into a SQLRows object
first somehow (and if so, then how?)  Is there some way to filter a
SQLRows object in place to do what I need?  Is the csv.service tool
borked?

This is all happening in version 1.65.11.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to