def DownloadLogFile(request, taskid): filename = Task.objects.using(request.database).get(id=taskid).logfile if (filename.lower().endswith(".dump") and request.user.username not in settings.SUPPORT_USERS) or not filename.lower().endswith( (".log", ".dump")): return HttpResponseNotFound(force_text(_("Error"))) return sendStaticFile( request, settings.FREPPLE_LOGDIR, filename, headers={ "Content-Type": "application/octet-stream", "Content-Disposition": 'inline; filename="%s"' % filename, }, )
def DownloadLogFile(request, taskid): # if request.database == DEFAULT_DB_ALIAS: # filename = 'frepple.log' # else: # filename = 'frepple_%s.log' % request.database filename = Task.objects.using(request.database).get(id=taskid).logfile if not filename.lower().endswith(".log"): return HttpResponseNotFound(force_text(_("Error"))) return sendStaticFile( request, settings.FREPPLE_LOGDIR, filename, headers={ "Content-Type": "application/octet-stream", "Content-Disposition": 'inline; filename="%s"' % filename, }, )
def downloadFilefromFolder(request, foldercode, filename=None): if request.method != "GET": return HttpResponseNotAllowed( ["get"], content="Only GET request method is allowed") folder, extensions = FileManager.getFolderInfo(request, foldercode) if not extensions: extensions = FileManager.all_extensions if filename: # Download a single file try: clean_filename = filename.split("/")[0] return sendStaticFile( request, folder, clean_filename, headers={ "Content-Type": "application/octet-stream", "Content-Disposition": 'inline; filename="%s"' % filename, }, ) except Exception as e: logger.error("Failed file download: %s" % e) return HttpResponseNotFound(force_text(_("Error"))) else: # Download all files b = BytesIO() with ZipFile(file=b, mode="w", compression=ZIP_DEFLATED) as zf: if os.path.isdir(folder): for filename in os.listdir(folder): fullfilename = os.path.join(folder, filename) if filename.endswith(extensions) and os.access( fullfilename, os.R_OK): zf.write( filename=fullfilename, arcname=os.path.basename(filename), ) response = HttpResponse(b.getvalue(), content_type="application/zip") response[ "Content-Disposition"] = 'attachment; filename="frepple.zip"' return response