Ejemplo n.º 1
0
def upload():
    if not portal_requests.FireCloud.get_health().ok:
        return flask.redirect(flask.url_for('terra_down'))

    display = flask_login.current_user.display
    oncotree = dict_manager.Oncotree.create_oncotree()

    credentials = dict_manager.Credentials.for_google(flask_login.current_user, SECRETS)
    if dict_manager.DateTime.time_to_renew_token(flask_login.current_user.time_authorized):
        response = refresh_token(credentials)
        token = response
    else:
        token = flask_login.current_user.access_token

    form = forms.UploadForm()
    form.billingProject.choices = portal_requests.Launch.list_billing_projects(token)
    if flask.request.method == 'POST' and form.validate_on_submit():
        profile = dict_manager.Form.populate_patient(form)
        portal_requests.Launch.submit_patient(token, profile, credentials)
        return flask.redirect(flask.url_for('user'))
    return flask.render_template('upload.html',
                                 display=display,
                                 CONFIG=CONFIG,
                                 form=form,
                                 billing_projects=form.billingProject.choices,
                                 oncotree_list=oncotree)
Ejemplo n.º 2
0
def upload():
    form = forms.UploadForm()
    if request.method == 'POST':
        # Validate form on submit
        if form.validate_on_submit():
            photoData = form.photo.data
            photo = secure_filename(photoData.filename)

            #save property photo to folder
            photoData.save(os.path.join(app.config['UPLOAD_FOLDER'],photo))
            
            info = 
            [{
                "message": "File Uploaded Sucessfully",
                "filename": photo,
                "description": form.description.data
            }]

            return jsonify(info)
        else:
            info = 
            [{
                "errors":[{form_errors(form)},{}]
            }]

            return jsonify(info)

    return render_template('',form = form)
Ejemplo n.º 3
0
def index():
    # init 2 forms
    upform = forms.UploadForm()
    fl = getFileList()
    deform = forms.DeleteFormBuilder(fl)

    return render_template('filepage.html',
                           title='My Files',
                           upform=upform,
                           deform=deform)
Ejemplo n.º 4
0
def home():
    shp_choices = [(row.rowid, row.name) for row in Shapefiles.query.all()]
    form = forms.UploadForm()
    form.selection.choices = shp_choices
    if form.validate_on_submit():
        file = form.upload.data
        shp_list = form.selection.data
        proj = form.projection.data
        shp_paths, join_cols = get_paths_n_joincol(shp_list)
        f = file.stream.read()
        lines = BytesIO(f)
        org = csv_to_gdf(lines, proj)
        org_cols = list(org.columns)
        org_cols.remove('geometry')
        org_cols = [name.lower() for name in org_cols]
        new_cols = org_cols + join_cols

        input_frames = [gpd.read_file(path) for path in shp_paths]
        new_input_frames = []
        for gdf in input_frames:
            gdf = gdf.to_crs(org.crs)
            new_input_frames.append(gdf)
        input_frames = new_input_frames
        input_frames.insert(0, org)
        sjoin = reduce(sjoin_no_index, input_frames)
        sjoin.columns = sjoin.columns.str.lower()
        for col in list(sjoin.columns):
            if col.endswith('_left'):
                sjoin.rename(columns={col: col[:-5]}, inplace=True)
            if col.endswith('_right'):
                sjoin.rename(columns={col: col[:-6]}, inplace=True)
            else:
                pass
        sjoin = sjoin.loc[:, ~sjoin.columns.duplicated()]
        sjoin2 = sjoin[new_cols]
        result = df_2_geojson(sjoin, properties=new_cols, proj=proj)
        # make_result_map(sjoin)
        # result = pd.DataFrame(sjoin).to_csv(index=False, encoding='utf-8')

        result_id = uuid.uuid4()
        result_dict = {str(result_id): sjoin2.to_json(orient='split')}
        session['tempdir'] = tempfile.mkdtemp()
        outfile = open(session['tempdir'] + '/filename', 'wb')
        pickle.dump(result_dict, outfile)
        outfile.close()

        return render_template('success.html',
                               result_id=list(result_dict)[0],
                               result=result)

        # return Response(result, mimetype="text/csv",
        #                 headers={"Content-disposition": "attachment; filename=output.csv"})
    else:
        return render_template('form.html', form=form)
Ejemplo n.º 5
0
def upload():
    upform = forms.UploadForm()

    uname = current_user.username
    upath = app.config['UPLOAD_FOLDER_ROOT'] + uname

    if upform.validate_on_submit():
        f = upform.userfile.data
        filename = secure_filename(f.filename)
        f.save(os.path.join(upath, filename))
    return redirect(url_for('index'))
Ejemplo n.º 6
0
def upload():
    form = forms.UploadForm()
    print()
    if request.method == "POST" and form.validate_on_submit():
        description = form.description.data

        upload = request.files['photo']
        filename = secure_filename(upload.filename)
        upload.save(os.path.join(
            app.config['UPLOAD_FOLDER'], filename
        ))
        return jsonify(message="File Upload Successful", filename=filename, description=description)
    else:
    # print('hello')
        return form_errors(form)
Ejemplo n.º 7
0
def upload():
    #if not session.get('logged_in'):
    #abort(401)

    # Instantiate your form class
    filesupload = forms.UploadForm()

    if request.method == 'GET':
        return render_template('upload.html', form=filesupload)

    # Validate file upload on submit
    if request.method == 'POST' and filesupload.validate_on_submit():
        image = filesupload.image.data
        filename = secure_filename(image.filename)
        image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        flash('File Saved', 'success')
        return redirect(url_for('home'))
    return render_template('upload.html', form=filesupload)
Ejemplo n.º 8
0
def upload():

    # Instantiate your form class
    uploadform = forms.UploadForm()

    # GET request handling
    if request.method == 'GET':
        return render_template('upload.html', form=uploadform)

    # Validate file upload on submit
    if request.method == 'POST' and uploadform.validate_on_submit():
        # Get file data and save to your uploads folder
        photo = uploadform.photo.data
        description = uploadform.description.data

        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        flash('File Saved', 'success')
        return redirect(url_for('home'))
    return render_template('upload.html', form=uploadform)
Ejemplo n.º 9
0
def upload():
    md5 = request.form['md5']
    saveto = request.form['saveto']
    name = request.form['name']
    path = os.path.join(app.config['UPLOADED_FOLDER'], md5[0:2])
    if not os.path.exists(path):
        os.makedirs(path)
    path = os.path.join(path, md5)
    files = getFiles(saveto)
    for file in files:
        if file[0] == name and file[1] is not None:
            flash("文件已存在")
            return redirect("index")
    if os.path.isfile(path):
        flash("秒传成功")
        file = models.File(userid=current_user.id,
                           virtualpath=saveto + name,
                           md5=md5)
        db.session.add(file)
        db.session.commit()
    else:
        form = forms.UploadForm(request.form)
        file = request.files[form.file.name]
        if file:
            file.save(path)
            status = models.Status(md5=md5, status=1)
            db.session.add(status)
            db.session.commit()
            file = models.File(userid=current_user.id,
                               virtualpath=saveto + name,
                               status=status)
            db.session.add(file)
            db.session.commit()
            flash("文件上传成功")
        else:
            flash("文件上传失败")
    return redirect(url_for('index', path=request.args.get('path')))
Ejemplo n.º 10
0
def course_management():
    from app.forms import create_student_checkbox_list

    course_student_list = keystone.get_course_users(current_user.course)
    course_form = create_student_checkbox_list(course_student_list)
    upload_form = forms.UploadForm()
    adduser_form = forms.AddUserForm()

    if adduser_form.add_user.data and adduser_form.validate_on_submit():
        if len(str(adduser_form.username.data)) == 6:
            username = '******' + str(adduser_form.username.data)
        else:
            adduser_form.username.errors.append(
                'Your input must be 6 characters long')
            return redirect(url_for('course_management'))

        if adduser_form.is_ta.data == True:
            email = adduser_form.email.data + '@ontariotechu.ca'
        else:
            email = adduser_form.email.data + '@ontariotechu.net'
        print(username)
        print(email)

        keystone.add_user_manual(current_user.course,
                                 '100' + adduser_form.username.data, email,
                                 is_ta)

        flash('User has been successfully added.')
        return redirect(url_for('course_management'))

    elif course_form.reset_password.data or \
            course_form.toggle_ta_status.data or \
            course_form.delete_student.data and \
            course_form.validate_on_submit():
        print('INSIDE COURSE FORM VALIDATE')
        if course_form.reset_password.data is True:
            for submitted in course_form:
                if submitted.data is True and submitted.type == "BooleanField":
                    email.send_password_reset_info.delay(
                        clean_html_tags(str(submitted.label)))
            flash("User password(s) have been reset")

        elif course_form.toggle_ta_status.data is True:
            for submitted in course_form:
                if submitted.data is True and submitted.type == "BooleanField":
                    field_id = clean_html_tags(str(submitted.id))
                    if 'student' in field_id:
                        current_role = 'student'
                    elif 'ta' in field_id:
                        current_role = 'ta'
                    keystone.toggle_ta_status(
                        clean_html_tags(str(submitted.label)),
                        current_user.course, current_role)
            flash("Role(s) have been modified.")
            return redirect(url_for('course_management'))

        elif course_form.delete_student.data is True:
            to_delete = {}
            for submitted in course_form:
                if submitted.data is True and submitted.type == "BooleanField":
                    to_delete[clean_html_tags(str(
                        submitted.label))] = clean_html_tags(
                            str(submitted.description))
            session['to_delete'] = to_delete
            return redirect(url_for('delete_students'))

    elif upload_form.upload.data and upload_form.validate_on_submit():
        filename = secure_filename(upload_form.file.data.filename)
        upload_form.file.data.save('uploads/' + filename)
        process_csv(current_user.course, 'uploads/' + filename)
        flash('Course list upload in progress')
        return redirect(url_for('index'))

    return render_template(
        'course_management.html',
        title='Course Management',
        course_student_list=course_student_list,
        course=current_user.course,
        course_form=course_form,
        upload_form=upload_form,
        adduser_form=adduser_form,
        navbar_text='Course Management: ' + current_user.course,
        project_info=keystone.get_project_info(current_user.course))