I may not be able to provide you anything regarding code I tried. But none of searches or research could get me a working result.
What I am trying to do? I have a form where user submit a CSV file. This file is processed in backend to retrieve data from DB. Data recovered from DB is again written in CSV and mailed to user.
This processing takes around 5-10 minutes. So I want to show a message to user that your work is under process and you will get CSV file once it is completed.
My code as of now.
def bulkserachpro(request):
with request.FILES['searchnum'] as csvfile:
spamreader = csv.reader(csvfile,dialect=excel)
next(spamreader)
a = []
b = []
for row in spamreader:
a.append((row[0]).upper())
data_list = nummodel.objects.filter(number__in=a)
csvfile = StringIO.StringIO()
csvwriter = csv.writer(csvfile)
csvwriter.writerow(['a','b'])
for data in data_list:
csvwriter.writerow([data.a,data.b])
message = EmailMessage("Hello","Your report","email@gmail.com",["emailto@gmail.com"])
message.attach('invoice.csv', csvfile.getvalue(), 'text/csv')
message.send()
return render(request,'bulkpro.html',messages.add_message(request, messages.SUCCESS,'File uploaded Succesfully.'))
This code does its job. But as user cannot wait for 5-10 minutes, he will get timeout error message. What should I change here so that user gets following message and once processing is done he receives email with attachment.
Your file is received, it will be processed and sent to your mail id.