Want to delete the excel data after saving the data into database in Django - django-views

Want to delete the excel data after saving the data into database in Django

To delete the excel file, you can import os and use the os.remove method to delete a file.
Since the variable path appears to contain the file path to your csv file, all you need to do to delete the file is to use os.remove(path).
Alternatively, to clear the contents of the csv file instead, you can open the file for writing and close it immediately.
open(path, "w").close()

Related

Django conventional filestore location for miscellaneous files read by an app's views?

Is there a convention for where to put miscellaneous files which are opened and read by Django views, but which aren't python code or html templates and aren't processed by the temmplate renderer?
(In my case, I have a View which returns an application/excel .xlsx file to the user. It is generated by reading in a "template" xlsx file with lots of tricky formatting and formulae but no data values. Openpyxl is used to insert selected data from the db, and the resulting workbook is saved and sent to the user.)
I would say this might be the media root dir, which itself is called "media", respectively some subdir of it. So in your app this is a subdirectory at <app-dir>/media or maybe /media/xlsx/.
See also here in the documentation: https://docs.djangoproject.com/en/4.1/topics/files/#file-storage

How to change the data of a sample .pbix?

I want to change the data of a sample .pbix but when I'm updating the data can not find the path of the Excel since I don't have it. Is there a way without having it?
You can check exists source from Transform data --> data source settings and find the path of exists excel and in case if you did not found you can add other data sources to replace it.

How to create and write to an XLSX file on Google Cloud Storage

I'm having trouble with my XLSX file process on Google Cloud Storage. The following code is what I have so far:
import cloudstorage
mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
filehandle = cloudstorage.open('/default/temp_export.xlsx', 'w', content_type=mime)
filehandle.write('some data1,some data2\n')
filehandle.write('some data3, somedata4\n')
filehandle.close()
This will create an XLSX file temp_export.xlsx on my storage bucket with the XLSX format using the mime type. When I tried reading the file with the following command, it works fine:
import cloudstorage
filehandle = cloudstorage.open('/default/temp_export.xlsx')
print filehandle.read()
# Output:
# some data1,some data2
# some data3, somedata4
But when I tried going to my storage bucket and downloading the temp_export.xlsx and try to open it, it throws this excel error:
Excel cannot open this file.
The file format or file extension is not valid.
Verify that the file has not been corrupted and that
the file extension matches the format of the file.
Anyone know what I'm doing wrong or how I can fix it? Thanks.
Any reason for not using the latest library for Cloud Storage? That one is only for App Engine with Python 2.7.
There is an example here on how to upload an object and how to download it, and then you must read your xlsx file with a proper library for it, like the ones mentioned here.

How to load from a folder without combining files

I'm trying to load several csv files from a folder that aren't connected.
Its not allowing me to load them without combining them.
Get Data > File > Folder
When they load it automatically tries to combine them which creates NULLs in one of the file rows.
When you get data from folder, it will combine all file into one table. To load each file into it's own table, you should get data from a Text/CSV file instead and import each of the files you want.

Is it possible to write back to data file in postman?

While working with postman, data.someVariable returns data from within a csv file that can also be used as {{someVariable}} in uri/json.
This gives us the data for that variable from that row/iteration.
Is there a mechanism to write back to the data file by doing something like postman.setData('responseCode') = responseCode.
This would be really helpful to store response code in the data file and to record call wise details in same format as the input within csv.
The only solution I figured out is
to populate json objects in the environment with information about the data file name and structure/values of information to be added
to create a separate web service (maybe in node.js) that exposes an http call to write to a file and takes in as parameter a json input as the one created in the environment as mentioned above and writes that to a file / original data file (or a copy of it) in the desired format
to call the above mentioned web service call at the end of each run or desired rest call execution to generate step wise information/debug report
There is no way to write back to data file in postman as of now .
However, you can populate that in your environment file at run time using
pm.environment.set("varname")
keep varname in such a way that you understand this is the variable you wanted to write back into data file.