[web2py] stale session with FORM and its kin
Somewhere along the way, and that probably includes the manual, Massimo has noted that the use of the family of FORM helpers is generally used to get parameters for an action whose results are then displayed on another page as a redirect. "What picture do you want to look at? Okay, let's go to that picture...". I do that with some of my forms, but in others, I just let the action happen and return the form for the next set of parameters. "what do you want to change the tag to? Okay, done, Change another tag?" When I do that, and then let the session expire before I get around to changing another tag (having youtube going on the other computer can do that to you), the major browsers will say something like "Confirm Form Resubmission". That's sort of acceptable if it's just an app for me, myself, and I, but if I have actual users I will have confused users. I know which ones I can resubmit safely, and which ones chopping the '#' off the end of the URL is a good way forward, but that isn't something I should be telling users to do. I have one of the repetitive forms as a LOAD block in a page, and doing that hides the expiration issue, but it seems hokey to do that for all such forms. However, about the only other idea I've come up with is to use a timer to cause a "redirect" to self, thus doing a fresh GET of the form. Has anyone else come up with a better than either of those choices? Thanks for your thoughts. Dave /dps -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/9468ab4e-41c9-4e88-9210-ec8bd6e58ff8n%40googlegroups.com.
[web2py] Re: Failing to download search results as csv
On Tuesday, August 22, 2023 at 2:32:48 AM UTC-7 mostwanted wrote: Hi guys, i need help downloading results as csv, i am failing dismally I dont know what to do After the search results return values I want to download those results into my computer somewhere the current version of my code is giving me an error: * string indices must be integers* Here is my code *FROM THE SEARCH VIEW:* * Download Results as CSV* *DOWNLOAD CONTROLLER:* *import csvfrom io import StringIOdef download_results():# Retrieve the filtered recordsrecords = request.vars* Isn't request.vars an array of strings? *# CSV datacsv_data = []csv_data.append(['First Name', 'Last Name', 'Program', 'Study Mode']) # Header rowfor record in records: csv_data.append([record['first_name'], record['last_name'], record['program'], record['study_mode']])* If request.vars, and hence records, is an array of strings, then each record is a string, and you're trying to index into that string with 'f*irst_name*', etc. You either need to repeat the search using request.vars, or pass the records that the search got from request.vars.to download_results() *# Create a response to download the CSV file response.headers['Content-Type'] = 'text/csv' response.headers['Content-Disposition'] = 'attachment; filename=registration_results.csv'# Write CSV data to a StringIO objectoutput = StringIO()csv_writer = csv.writer(output)for row in csv_data:csv_writer.writerow(row)# Return the content as bytesreturn output.getvalue().encode('utf-8')* /dps -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/93ed5077-9868-4659-800f-c7ced7dcda12n%40googlegroups.com.