Exemple #1
0
def upload(file, project_id):
    if file:
        filename = gen_file_name(file.filename)
        mimetype = file.content_type
        # 保存文件到服务器
        uploaded_file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
        file.save(uploaded_file_path)
        size = os.path.getsize(uploaded_file_path)
        # 保存到数据库
        database_config = current_app.config['DATABASE_URI']
        conn = MySQLdb.connect(
            host=database_config['host'],
            user=database_config['user'],
            passwd=database_config['passwd'],
            port=database_config['port'],
            db=database_config['db'],
            charset=database_config['charset'])
        cur = conn.cursor()
        cur.execute('insert into project_requirement(requirement_url, project_id, create_time) values (%s, %s, %s)',
            (current_app.config['UPLOAD_BASE_URL'] + filename, project_id, time.time()))
        insert_id = cur.lastrowid
        conn.commit()
        cur.close()
        conn.close()

        requirements = readxls(uploaded_file_path)
        insertToDB(requirements, insert_id)
        print u'更新需求列表成功'
        # js回调数据
        result = uploadfile(name=filename, type=mimetype, size=size)
        return {"files": [result.get_file()], "last_id": insert_id}
    else:
        return None
Exemple #2
0
def upload(file, project_id):
    if file:
        filename = gen_file_name(file.filename)
        mimetype = file.content_type
        # 保存文件到服务器
        uploaded_file_path = os.path.join(current_app.config['UPLOAD_FOLDER'],
                                          filename)
        file.save(uploaded_file_path)
        size = os.path.getsize(uploaded_file_path)
        # 保存到数据库
        database_config = current_app.config['DATABASE_URI']
        conn = MySQLdb.connect(host=database_config['host'],
                               user=database_config['user'],
                               passwd=database_config['passwd'],
                               port=database_config['port'],
                               db=database_config['db'],
                               charset=database_config['charset'])
        cur = conn.cursor()
        cur.execute(
            'insert into project_requirement(requirement_url, project_id, create_time) values (%s, %s, %s)',
            (current_app.config['UPLOAD_BASE_URL'] + filename, project_id,
             time.time()))
        insert_id = cur.lastrowid
        conn.commit()
        cur.close()
        conn.close()

        requirements = readxls(uploaded_file_path)
        insertToDB(requirements, insert_id)
        print u'更新需求列表成功'
        # js回调数据
        result = uploadfile(name=filename, type=mimetype, size=size)
        return {"files": [result.get_file()], "last_id": insert_id}
    else:
        return None
Exemple #3
0
def get_uploaded():
    files = [f for f in os.listdir(current_app.config['UPLOAD_FOLDER'])
             if os.path.isfile(os.path.join(current_app.config['UPLOAD_FOLDER'], f))]
    file_display = []

    for f in files:
        size = os.path.getsize(os.path.join(current_app.config['UPLOAD_FOLDER'], f))
        file_saved = uploadfile(name=f, size=size)
        file_display.append(file_saved.get_file())

    return simplejson.dumps({"files": file_display})
Exemple #4
0
def get_uploaded():
    files = [
        f for f in os.listdir(current_app.config['UPLOAD_FOLDER'])
        if os.path.isfile(os.path.join(current_app.config['UPLOAD_FOLDER'], f))
    ]
    file_display = []

    for f in files:
        size = os.path.getsize(
            os.path.join(current_app.config['UPLOAD_FOLDER'], f))
        file_saved = uploadfile(name=f, size=size)
        file_display.append(file_saved.get_file())

    return simplejson.dumps({"files": file_display})