Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2012, 11:13 PM
admoore admoore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2010
Posts: 11 admoore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 14 m 56 sec
Reputation Power: 0
Flask: problem with complex forms and returning files

I'm trying to port a program I wrote in PHP to Python using Flask. I've run into a somewhat multi-faceted problem, though, so I hope you can bear with me as I explain.

The program is a report generator. The user selects a report from the drop-down menu. Depending on the report chosen, parameter fields are added to the form by javascript. Then the user selects HTML, CSV, or PDF output. If HTML is chosen, the form is submitted using AJAX and the results displayed on the page. Otherwise, the report is submitted as a normal POST and a file is downloaded.

The first problem I run into with Flask is that it doesn't parse the query string like PHP does. If I have inputs named "parameters['some_date']" and "parameters['some_term']", it doesn't organize those into a single hash like PHP. It's important to have the parameters grouped into an array, since (a) I don't know ahead of time how many there will be, (b) I need to loop through them, separately from the other data, and (c) the parameter names are important.

The workaround for the problem was to submit the form as JSON using jquery AJAX. This is not ideal since it doesn't degrade gracefully, but there's a bigger problem -- I can't get AJAX to prompt the user for downloading files.

I've tried the iframe thing, and data URI. The iframe didn't work because my file data is generated on the fly in memory, and there isn't actually a URL that will return the file without resubmitting the POST and processing it twice.

The data URI works, but doesn't allow me to give the user a filename, isn't very cross-browser, and I don't think it'll work with large datasets.

Every solution that comes to mind seems like it'd be an unbelievable hack for something that ought to be relatively simple. Can anyone point me in the right direction, or suggest a different approach to the design?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Flask: problem with complex forms and returning files

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap