Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.conf import settings
- def serve_file(path, filename):
- with open(path, "rb") as excel:
- data = excel.read()
- response = HttpResponse(data,content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
- response['Content-Disposition'] = 'attachment; filename=%s' % filename
- return response
- def excel_report(request, id):
- # we assume that settings.VAR_PATH is set to some ABSOLUTE path
- # to a readable / writable directory outside the code base
- folder = os.path.join(settings.VAR_PATH, 'excel', 'reports')
- filename = '%s_Report.xlsx' % id
- path = os.path.join(folder, filename)
- if not os.path.exists(path):
- # XXX
- # whatever jar_wrapper do, it should do it in a known absolute path - one should
- # NEVER rely on current working directory - AND it should be outside the
- # code base.
- # here we assume that one can pass the desired path to jar_wrapper.
- tmp = os.path.join(settings.VAR_PATH, 'excel', 'tmp', filename)
- args = ['ServerExcel.jar', id, tmp]
- result = jar_wrapper(*args)
- if not result:
- return HttpResponse(json.dumps({"no":"excel","no one": "cry"}))
- shutil.move(tmp, folder)
- return serve_file(path, filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement