示例#1
0
def save(p="",s="save_as"):
    # print(p,s)
    # sys.stdout.flush()
    p=cleanP(p)
    if s == "save_as":
        filename=secure_filename(request.form["file_name"])
        ext=request.form['action']
        session_=session_to_file(session,ext)
        path = UserFolder(current_user) + "/"+p +"/"+ filename+"."+ext
        if ext == "ses":
            session["session_file"]=path
    elif "session_file" not in list(session.keys()):
        return redirect( '/storage/' )
    else:
        ext="ses"
        session_=session_to_file(session,ext)
        path=session["session_file"]

    session_file = io.BytesIO()
    session_file.write(json.dumps(session_).encode())
    session_file.seek(0,os.SEEK_END)
    session_file=session_file.tell()           
    if session_file > session["available_disk_space"]:
        flash("'%s': you do not have enough space to save this file." %(filename+"."+ext),'error')
        return redirect( '/storage/'+p )
    with open(path,"w") as fout:
        json.dump(session_, fout)
    
    if s == "save_as":
        return redirect( '/storage/'+p )
    elif s == "save":
        app_redirect=session["app"]
        flash("`%s` saved." %os.path.basename(path),'info')
        return redirect(url_for(app_redirect))
示例#2
0
def download(json_type="arg"):
    # READ INPUT DATA FROM SESSION JSON
    session_ = session_to_file(session, json_type)

    session_file = io.BytesIO()
    session_file.write(json.dumps(session_).encode())
    session_file.seek(0)

    plot_arguments = session["plot_arguments"]

    eventlog = UserLogging(email=current_user.email,
                           action="download %s %s" %
                           (json_type, session["app"]))
    db.session.add(eventlog)
    db.session.commit()

    return send_file(session_file,
                     mimetype='application/json',
                     as_attachment=True,
                     attachment_filename=plot_arguments["session_argumentsn"] +
                     "." + json_type)
示例#3
0
def download(json_type="arg"):
    # READ INPUT DATA FROM SESSION JSON
    session_ = session_to_file(session, json_type)

    # debug=False
    # if debug:
    #     for i in list( session_["plot_arguments"].keys() ):
    #         try:
    #             session_file = io.BytesIO()
    #             session_file.write(json.dumps({i:session_["plot_arguments"][i]}).encode())
    #             session_file.seek(0)
    #         except:
    #             print("FAILED ON:", i)
    #             print(session_["plot_arguments"][i])
    #             sys.stdout.flush()

    session_file = io.BytesIO()
    session_file.write(json.dumps(session_).encode())
    session_file.seek(0)

    plot_arguments = session["plot_arguments"]

    eventlog = UserLogging(email=current_user.email,
                           action="download %s %s" %
                           (json_type, session["app"]))
    db.session.add(eventlog)
    db.session.commit()

    if json_type == "arg":
        file_name = plot_arguments["session_argumentsn"] + "." + json_type
    elif json_type == "ses":
        file_name = plot_arguments["session_downloadn"] + "." + json_type

    return send_file(session_file,
                     mimetype='application/json',
                     as_attachment=True,
                     attachment_filename=file_name)
示例#4
0
def askforhelp():
    import tempfile
    page = session["app"]
    tb_str = session["traceback"]

    session_ = session_to_file(session, "ses")
    if not os.path.isdir(app.config['USERS_DATA'] + "/tmp/"):
        os.makedirs(app.config['USERS_DATA'] + "/tmp/")

    session_file_name = tempfile.mkstemp(dir=app.config['USERS_DATA'] +
                                         "/tmp/",
                                         suffix='.ses')[1]
    with open(session_file_name, "w") as session_file:
        json.dump(session_, session_file)

    send_help_email(user=current_user,
                    eapp=page,
                    emsg=tb_str,
                    etime=str(datetime.now()),
                    session_file=session_file_name)
    flash(
        "Your scream for help has been sent. We will get in contact with you as soon as possible."
    )
    return redirect(url_for(page))