How to download content from my Django webpage? - django

I have a table on one of my Django webpage. I want to give the user the ability to download the content of the table in xl format.
What would be an efficient and good way of doing this?
I was thinking of creating an xlsx file using the xldr library. Writing the data on the file. making the file available for download and then deleting the file at the end, so that my drive stays clean.
but it doesn't feel like a very efficient way.
I'm new in web development, so open to all kind of ideas.
Thanks

There's an example in the python doc of generating a pdf response. Apart from using xldr I don't suppose it needs to be much different, though I haven't done this. It uses io.BytesIO in-memory buffering to avoid creating temporary files, and sends that back using FileResponse instead of HttpResponse

Related

Django Upload File, Analyise Conents and write to DB or update form

I'm pretty new to Django, Trying to get my grips with it, and expand what I think its capable of doing, and maybe one of you more intelligent people here can point me in the right direction.
I'm basically trying to build a system similar to a so called "Asset Management" system, to track software version of a product, so when an engineer updates the software version, they run a script which gathers all the information (Version, Install date, Hardware etc), which is stored in a .txt file, The engineer then comes back to the website and upload this .txt file for that customer, and it automatically updates the fields in the form, or directly to the database.
While, I've search a bit on here for concepts, I haven't been able to find something similar (Maybe my search terms aren't correct?), and wanted to ask if anyone knows, what I'm doing is even feasible, or am I lost down the rabbit hole of limitations :) Maybe its not do-able within Django, Any suggestions on how I should approach such a problem would be greatly appreciated.
What you're asking is doable both in the form and post-submit of a form or file upload.
In the form approach you'll want a live-reload of the form should the data come from a .txt file. That can be done with JavaScript. This will mean that the data will come from the text file and be input into the forms in the manner you define. This also means form validation will work as you want it to.
Another option is to require a txt file in a specified format, and parse it in the view, form_valid() for Class-Based Views, and request.FILES[] for function based views, and then perform all the required validations and then save the values to the database as the model instance.

Difference in file size of an Excel file when downloading directly as opposed to open and saving it

May be the title of my question is really awful but I couldn't figure a better way to frame it. So the problem is I have a Silverlight web app that does some processing and generates an Excel file as output. THe Excel generation code uses OpenXML format to create various XML parts and packages and using System.Packaging.CompressionOptions I compress the file generated. Now, when the browser (IE 9) shows a download options box, if I click Open to open the file in Excel and then do a SaveAs, it saves the file with a further reduced size as opposed to if I hit Save directly on the download box in which case it saves it with whatever size the file was created with.
Any ideas why these 2 ways of saving the same file result in different sizes?
Cheers
Depending on how you used the OpenXML library, there might be some inefficiencies or errors. Resaving the file in Excel will fix any duplicate formatting, update the metadata (possibly reducing it) and fix any validation errors. I encourage getting the Open XML SDK 2.0 Productivity Tool provided with the OpenXML SDK to check for any validation errors and to better understand where more inefficiencies might lie. It is possible to automatically resave the file using Excel by using Interop (using C# anyways).

Read csv file from website into c++

I'd like to read the contents of a .csv file from a website, into a c++ program. Specifically, it is financial data of the form from google finance.
http://www.google.com/finance/historical?cid=22144&startdate=Nov+1%2C+2011&enddate=Nov+14%2C+2011
(If you append "&output=csv" to the above link it will download the data as a csv file)
I know that I can use something like libcurl to download the file and then read it in from there, but I wanted to read it directly into the program without having to write it to a file first.
Can I get some suggestions on the best way to do this? I was thinking boost.asio but I have no experience with it (or network programming in general).
If you are trying to download it from a web resource you will need to implement at least some part of the HTTP protocol. libcurl will do this for you.
You don't need to save it as a file. This example will show you how to download and store it in a memory buffer.

Django big file transfers

I am looking for a django app that can help smooth the process of uploading big size documents by using HTTP Post.
Documents ranging anything from 150mb to 500mb.
I wrote a small library that handles PDF uploads and parses it to my scribd library and through that embed it onto my site.
Currently my model is quite simple, it takes a FileField, preferably PDF and just and uploads the PDF File, through that makes use of the scribd library and send it directly to scribd for encoding.
The problem is, somewhere along the actual upload process, it times out, no errors in the log, I have adjusted my django apps size for files, Apache's size for files, and I am a bit lost at the moment not knowing where to go from here.
Although I want to eliminate the manual work, so ideally I'd still like to use it through my site.
Any help or pointers would be appreciated.
Probably a bit too late, but, have you tried django-bft

excel in django

How can i make user to downlaoad a excel from the django app.i HAVE A MODEL WHICH gives the report.Now i want a option from user can download the file in excel form.ANy Solution
You can output the data as .csv which is easily imported into MS Excel.
http://docs.djangoproject.com/en/dev/howto/outputting-csv/
EDIT
After I wrote that I got curious if there actually was some way to do it directly to excel format and found:
http://www.python-excel.org/
That made me wonder why you didn't google your question before posted it here.....
I'm not sure quite what you're asking. If you're asking how can you generate output that's able to be read into Excel, IMO your best bet is using a CSV (see amoeba's response) as that's pretty generic. There are ways of using true Excel formats as well.
I'm thinking though that perhaps you're asking how you can have a user click a link (or whatever) and have Excel pop up with your data in it? (IOW, you've already generated the output).
I suppose I'd say a few things:
1) It shouldn't be specific to Excel, many users use things like OO.o (thus my CSV suggestion)
2) It's going to vary depending on their browser and how they have it set up. Personally, I don't like pages opening up the "proper application" so I turn all of that off - other people enable it.