Ejemplo n.º 1
0
def edit_photos():
    upload = FileForm()
    set_loop = Set.query.order_by(Set.id.desc()).all()
    if upload.validate_on_submit():
        for loop in set_loop:
            if request.form["select_set"] == loop.tag:
                file = request.files['file']
                bucket.put_object(Key='Tractor Show/' + loop.name + '/' +
                                  file.filename,
                                  Body=file)
                newFile = Images(name=file.filename, set=loop)
                db.session.add(newFile)
                db.session.commit()
                return redirect('/dashboard/photos#' + loop.tag)

    add_set = AddSet()
    if add_set.validate_on_submit():
        render_tag = tag_generator(request.form["set"])
        new_set = Set(name=request.form["set"], tag=render_tag)
        db.session.add(new_set)
        db.session.commit()
        return redirect(url_for('edit_photos'))
    return render_template('authentication/edit-photos.html',
                           upload=upload,
                           add_set=add_set,
                           set_loop=set_loop,
                           s3projects=s3projects)
Ejemplo n.º 2
0
def hello():
    form = FileForm()
    if form.validate_on_submit():
        f = request.files['file']
        f.save(secure_filename('test.pdf'))
        Parse()
        flash('Parsed successfully', 'success')
        return redirect('/')
    return render_template('index.html', title='Pdf Parser', form=form)
Ejemplo n.º 3
0
def index():
    form = FileForm()
    if form.validate_on_submit():
        filename = secure_filename(form.file.data.filename)
        print(filename)
        if filename.split('.')[1] in ALLOWED_EXT:
            form.file.data.save('uploads/' + filename)
        else:
            flash('Incorrect format selected, please try again!')
        return redirect(url_for('index'))
    return render_template('index.html', form=form)
Ejemplo n.º 4
0
def home():
    feature_form = FeatureForm()
    file_form = FileForm()
    with open ("static/final_svm_model.pkl",'rb') as pickle_file:
          model = pickle.load(pickle_file)

    if feature_form.validate_on_submit():
        sepal_length= feature_form.sepal_length.data
        sepal_width = feature_form.sepal_width.data
        petal_length = feature_form.petal_length.data
        petal_width = feature_form.petal_width.data

        data = np.array([sepal_length,sepal_width, petal_length, petal_width]).reshape(1,-1)
        prediction= model.predict(data)
        predict_result = ""

        if prediction == 0:
            predict_result = 'setosa'
        elif prediction == 1:
            predict_result =  'versicolor'
        else :
            predict_result = 'virginica'

        #image_file_name = str(uuid.uuid4())
        #image_file = image_file_name + ".png"
        #search_image(predict_result, image_file)

        return render_template("home.html", feature_form=feature_form, file_form = file_form, result = predict_result)

    elif file_form.validate_on_submit():
        file = file_form.test_file.data #FileStorage object

        try:
            data= pd.read_csv(file,sep=' ', delimiter=r"\s+",index_col=False)
            prediction = model.predict(data)

        except Exception:
            return  "Something went worng. PLEASE CHECK THE FILE AGAIN"
        prediction = prediction.astype(str)
        prediction[prediction == '0'] = 'setosa'
        prediction[prediction == '1'] = 'versicolor'
        prediction[prediction == '2'] = 'virginica'

        prediction_file_name = str(uuid.uuid4())
        predict_result_file = prediction_file_name + ".txt"
        np.savetxt("static/prediction/"+ predict_result_file,  prediction, newline="\r\n" , fmt="%s")
        return redirect(url_for('predict_txt', filename=predict_result_file))

    return render_template("home.html", feature_form=feature_form, file_form = file_form)
Ejemplo n.º 5
0
def file_edit(id):
    fileobj = g.db.files.find_one({'_id': id})

    if fileobj is None:
        abort(404)

    if fileobj.get('owner') != g.username or not (g.is_admin):
        # abort if owner doesn't match current user or current is not admin
        abort(403)

    form = FileForm()

    if form.validate_on_submit():
        fileobj = form2object(form, fileobj)
        flash('not implemented', category="warning")

    if request.method == 'GET':
        # get the data from the page-object into the form
        form = object2form(fileobj, form)

    return render_template('generic_form.html', form=form, title='Edit File')
Ejemplo n.º 6
0
def teacher_resource(id):
    course = Course.query.get(id)
    resources = course.resources.all()
    form = FileForm()
    #:如果当前登录的教师没有教授这门课程,则禁止访问
    if current_user.id != course.teacher.id:
        abort(403)
    if form.validate_on_submit():
        name = form.file.data.filename
        addr = 'upload/' + str(id) + '/' + 'resource/'
        url = upload(
            form.file.data,
            ['zip', 'rar', 'doc', 'txt', 'docx', 'pdf', 'ppt', 'pptx'], addr)
        if url is None:
            flash(
                u'请选择正确的文件格式上传文件,文件格式可以是["zip", "rar", "doc", "txt", "docx", "pdf", "ppt", "pptx"]'
            )
            return render_template('teacherResource.html',
                                   form=form,
                                   course=course,
                                   resources=resources)
        resource = Resource.query.filter(
            and_(Resource.course_id == id, Resource.name == name)).first()
        #:如果是同名文件,则覆盖,即删除原文件,保留新文件
        if resource is not None:
            #:删除原文件
            if os.path.exists(resource.url):
                os.remove(resource.url)
            resource.url = url
            db.session.commit()
        else:
            resource = Resource(name=name, url=url, course_id=id)
            db.session.add(resource)
            db.session.commit()
        flash(u'文件上传成功')
        return redirect(url_for('teacher_resource', id=id))
    return render_template('teacherResource.html',
                           form=form,
                           course=course,
                           resources=resources)
Ejemplo n.º 7
0
def student_homework_details(id):
    homework = Homework.query.get(id)
    student_homework = Student_Homework.query.filter(
        and_(Student_Homework.student_id == current_user.id,
             Student_Homework.homework_id == id)).first()
    feedbacks = homework.feedbacks.all()
    form = FileForm()
    feedbackForm = FeedbackForm()
    #: 如果当前学生没有选择该课程,但是要访问该课程的作业内容,则禁止访问
    if current_user not in homework.course.students:
        abort(403)
    #:上传文件
    if form.validate_on_submit():
        name = form.file.data.filename
        addr = 'upload/' + str(
            homework.course_id) + '/homework/' + str(id) + '/' + str(
                current_user.id) + '/'
        url = upload(
            form.file.data,
            ['zip', 'rar', 'doc', 'txt', 'docx', 'pdf', 'ppt', 'pptx'], addr)
        if url is None:
            flash(
                u'请选择正确的文件格式上传文件,文件格式可以是["zip", "rar", "doc", "txt", "docx", "pdf", "ppt", "pptx"]'
            )
            return render_template('studentHomeworkDetails.html',
                                   homework=homework,
                                   form=form,
                                   course=homework.course,
                                   student_homework=student_homework,
                                   feedbacks=feedbacks,
                                   feedbackForm=feedbackForm)
        #:如果重复上传,则覆盖原先的文件,即删除原先的文件,保留现有的文件
        if student_homework is not None:
            if student_homework.url != url and os.path.exists(
                    student_homework.url):
                os.remove(student_homework.url)
            student_homework.name = name
            student_homework.url = url
            student_homework.time = datetime.datetime.now()
            db.session.commit()
        else:
            student_homework = Student_Homework(name=name,
                                                url=url,
                                                homework_id=id,
                                                student_id=current_user.id)
            db.session.add(student_homework)
            db.session.commit()
        flash(u'文件上传成功')
        return redirect(url_for('student_homework_details', id=id))
    #:发布反馈内容
    if feedbackForm.validate_on_submit():
        content = feedbackForm.content.data
        feedback = Feedback(content=content,
                            student_id=current_user.id,
                            homework_id=id)
        db.session.add(feedback)
        db.session.commit()
        flash(u'反馈内容成功发表')
        return redirect(url_for('student_homework_details', id=id))
    return render_template('studentHomeworkDetails.html',
                           homework=homework,
                           form=form,
                           course=homework.course,
                           student_homework=student_homework,
                           feedbacks=feedbacks,
                           feedbackForm=feedbackForm)