Upload CSV file and run an algo based on it

Hello everyone,

I would like to create a web application where a user can upload a csv file in its account, push a run button and receive results. When applying the run button, an algorithm on python is called, process things and return results (like tables).

The user should do this work everyday and upload a different csv each time.

As a beginner in Django, any advice to create this task? I would also like to keep the csv file somewhere (as a database) and also store the results (to do KPIs based on previous user works).

Thanks in advance,

Best,

It appears from what you describe, you’ve got the following steps:

  • Present a page to accept a file upload
  • Handle an uploaded file
  • Present a page to present a “Run” button.
    • (Perhaps selecting from multiple files that have been uploaded?)
  • Process the file
  • Display results

What of these steps are you already familiar with or comfortable with?

Are you sure you want to keep the file in the database? Or do you want to keep the files as files somewhere in the filesystem?

What sort of security is going to be needed? Will each individual have their own files?

Hello @KenWhitesell,

Thank you a lot for your response, you’ve totally understand my request.
Where I’m familiar:

  • Present a page to accept a file upload → I read a lot ab/ creating forms and store it in my DB, but not sure it is appropriate. This page is already created with the 2 upload button + a run button
  • Handle an uploaded file : not confortable with
  • Present a page to present a “Run” button.
    • (Perhaps selecting from multiple files that have been uploaded?) → Exactly 2 files must to be uploaded.
  • Process the file : I think I can manage it
  • Display results: not confortable with

Are you sure you want to keep the file in the database? Or do you want to keep the files as files somewhere in the filesystem? → very good point!! As I mentionned, every posts about this subject explain to create a form and add info of the csv file. But what I really want is the 2nd part of your explanation. I would like to keep files as files (because 2 files from 2 different days can integrate/keep same information and must not be duplicate if store in database with forms). Not really confortable with storing in filesystem but very open to learn it.

What sort of security is going to be needed? Will each individual have their own files?
→ Yes every user has their own files. Don’t really sure what you mean about security.

Thank you again, I really appreciate,

Respectfully,

So break this down step-by-step.

Do not try to do this all at once.

Read File Uploads | Django documentation | Django to see how to handle uploaded files.

Get your app working to the point where you can see the page to upload files, upload the files, then visually verify that the files are uploaded to the expected directory.

Once you’re comfortable with how that all works, then add the code to process the data, writing the results to your models.

Visually inspect the tables (either using the Django shell or your database’s native tools) to prove that the processing has completed and the results are as you expect.

Once you’re done with that, then you can build your output from that data.

Regarding the security, that’s by intent, a broad and general question. Will people need to log in to the site? Will the results of the calculations need to be restricted by user?
Effectively, you need to identify “who can do what” for every page available in the system, and whether there are any restrictions that might need to be applied.
(e.g. You may want to store each user’s files in a per-user directory.)

Re: security.

You may also want to ensure anything uploaded does not contain malicious stuff.

Depending on your server-side, you could use clamd/clamav or any other AV software appropriate (free?) for you.
But do not underestimate the amount of evil s**t that will end up being uploaded, even behind an auth-only page. :slight_smile:

Also worth reading: EICAR test file - Wikipedia

Again thank you very much. I’ve the right path to learn and apply thanks to your advices. I will apply based on your recommandation and will keep you in touch of my progress.

Will people need to log in to the site? Will the results of the calculations need to be restricted by user? → in the futur, I need to develop user account (already did authentification and worked well but not sure that it is the best way to do it)

(e.g. You may want to store each user’s files in a per-user directory.) → also, I would like after each run, the possibility to store the results and give an history access to the user

Again thanks, have a great day and I will keep you in touch,

Respectfully,