Exemple #1
0
def upload_sku():
    '''
    excel导入卖家sku
    '''
    if request.method == 'POST':
        upload_data = request.get_records(field_name='file')
        # 检查卖家sku是否重复
        sku_list = [item['SKU'] for item in upload_data if item['SKU'] != '']
        for i in sku_list:
            if sku_list.count(i) > 1:
                result = {'status': 1, 'msg': '导入失败,卖家SKU:{}重复了'.format(i)}
                return Response(json.dumps(result),
                                mimetype='application/json')
        # sku导入处理
        match_sum, not_match_sum, forty_more_sum = 0, 0, 0
        for item in upload_data:
            ob = T1688Shop.objects(goods_url=item['商品链接'])
            if not ob:
                not_match_sum += 1
            elif len(str(item['SKU'])) > 40:
                forty_more_sum += 1
            else:
                ob.update_one(set__sku_id=str(item['SKU']))
                match_sum += 1

        result = {
            'status': 0,
            'msg': '导入成功!{0}个商品匹配成功,{1}个商品链接无法匹配,{2}个商品的SKU超过40个字符,插入失败'\
                                                    .format(match_sum, not_match_sum, forty_more_sum)
        }
        return Response(json.dumps(result), mimetype='application/json')
    return '''
 def import_excel(self):
     data = request.get_records(field_name='files')
     try:
         self.save_to_database(data)
     except (InvalidRequestError, IntegrityError, OperationalError, UnmappedInstanceError) as e:
         self.session.rollback()
         flash(str(e))
         return make_response(jsonify({'errors': str(e)}), 400)
     else:
         flash('Uploaded Successfully')
         return redirect(self.url)
def import_excel():
    session = db.session
    column_names = ['id', 'pwd']
    records = request.get_records(field_name='file', name_columns_by_row=-1, start_row=1, auto_detect_int=False, colnames=column_names)
    is_or_not_map = common_fun.get_revert_dict_map(const.IS_OR_NOT_DICT_KEY)
    # for r in records:
        # r['isCaiyin'] = is_or_not_map.get(str(r['isCaiyin']), r['isCaiyin'])
    db_util.increment_update(session=session,
                             data_dict_list=records,
                             schema_type=UserSchema,
                             is_src=True,
                             request_id=get_jwt_identity())
    # session.flush()
    return status_code.SUCCESS.d, 200
Exemple #4
0
def import_excel():
    session = db.session
    try:
        column_names = ['id', 'dict_name', 'dict_code', 'dict_desc', 'is_valid', 'org_code', 'create_by', 'create_time', 'update_by', 'update_time', 'revision', ]
        records = request.get_records(field_name='file', name_columns_by_row=-1, start_row=1, auto_detect_int=False, colnames=column_names)
        db_util.increment_update(session=session,
                                 data_dict_list=records,
                                 schema_type=DictSchema,
                                 is_src=False,
                                 request_id=current_user.id)
        session.flush()
    except BaseException as e:
        logger.exception(e)
        return status_code.UNKNOWN_ERROR.set_data(e.args).d
    return status_code.SUCCESS.d, 200
Exemple #5
0
def upload_array(struct_type):
    if struct_type == "array":
        array = request.get_array(field_name='file')
        return excel.make_response_from_array(array, 'xls')
    elif struct_type == "dict":
        adict = request.get_dict(field_name='file')
        return excel.make_response_from_dict(adict, 'xls')
    elif struct_type == "records":
        records = request.get_records(field_name='file')
        return excel.make_response_from_records(records, 'xls')
    elif struct_type == "book":
        book = request.get_book(field_name='file')
        return excel.make_response(book, 'xls')
    elif struct_type == "book_dict":
        book_dict = request.get_book_dict(field_name='file')
        return excel.make_response_from_book_dict(book_dict, 'xls')
Exemple #6
0
def respond_array(struct_type):
    if struct_type == "array":
        array = request.get_array(field_name='file')
        return jsonify({"result": array})
    elif struct_type == "dict":
        adict = request.get_dict(field_name='file')
        return jsonify({"result": adict})
    elif struct_type == "records":
        records = request.get_records(field_name='file')
        return jsonify({"result": records})
    elif struct_type == "book":
        book = request.get_book(field_name='file')
        return jsonify({"result": book.to_dict()})
    elif struct_type == "book_dict":
        book_dict = request.get_book_dict(field_name='file')
        return jsonify({"result": book_dict})
Exemple #7
0
def import_student():
    if request.method == 'POST':
        if request.files.get('file'):
            records = request.get_records(field_name='file')
            if User.import_user(records):
                if TrainStudent.import_student_team(records):
                    flash('导入成功')
                    return redirect(url_for('train.student'))
                else:
                    flash('导入失败,请确保导入前系统学员信息为空且导入的文件组号格式正确')
            else:
                flash('导入失败导入数据格式不正确,注意学号的填写格式')
        else:
            flash('请选择要导入的文件')
    return render_template('train/import_student.html',
                           active_flg=['train', 'student'])
Exemple #8
0
def upload_quantity():
    '''
    excel导入采购数量
    '''
    if request.method == 'POST':
        upload_data = request.get_records(field_name='file')
        # 采购数量导入处理
        match_sum, not_match_sum = 0, 0
        for item in upload_data:
            ob = T1688OrderCart.objects(goods_url=item['商品链接'])
            if not ob:
                not_match_sum += 1
            else:
                ob.update_one(set__quantity=str(item['采购数量']))
                match_sum += 1
        result = {
            'status': 0,
            'msg':
            "导入成功!{0}个商品匹配成功,{1}个商品链接无法匹配".format(match_sum, not_match_sum)
        }
        return Response(json.dumps(result), mimetype='application/json')
    return '''
Exemple #9
0
def upload_array(struct_type):
    if struct_type == "array":
        array = request.get_array(field_name="file")
        return excel.make_response_from_array(array,
                                              "xls",
                                              sheet_name="test_array")
    elif struct_type == "dict":
        adict = request.get_dict(field_name="file")
        return excel.make_response_from_dict(adict,
                                             "xls",
                                             sheet_name="test_array")
    elif struct_type == "records":
        records = request.get_records(field_name="file")
        return excel.make_response_from_records(records,
                                                "xls",
                                                sheet_name="test_array")
    elif struct_type == "book":
        book = request.get_book(field_name="file")
        return excel.make_response(book, "xls")
    elif struct_type == "book_dict":
        book_dict = request.get_book_dict(field_name="file")
        return excel.make_response_from_book_dict(book_dict, "xls")
Exemple #10
0
def upload_excel():

    title = "Swaps Upload"
    header = "Swaps Upload"
    description = Markup("Swaps<br>Upload")
    form = UploadForm()
    if request.method == 'POST' and form.validate_on_submit():

        record_dict = request.get_records(field_name='upload',
                                          name_columns_by_row=0)

        month_year = datetime.datetime.now().strftime('%b-%Y')
        month_year_folder = app.config[
            "VANTAGE_UPLOAD_FOLDER"] + "/" + month_year

        filename = secure_filename(request.files['upload'].filename)

        filename_postfix_xlsx = Check_File_Exist(
            month_year_folder, ".".join(filename.split(".")[:-1]) +
            ".xlsx")  # Checks, Creates folders and return AVAILABLE filename

        # Want to Let the users download the File..
        # return excel.make_response_from_records(record_dict, "xls", status=200, file_name=filename_without_postfix)

        pyexcel.save_as(records=record_dict,
                        dest_file_name=filename_postfix_xlsx)

        column_name = []
        file_data = []
        for cc, record in enumerate(record_dict):
            if cc == 0:
                column_name = list(record_dict[cc].keys())
            buffer = dict()
            #print(record)
            for i, j in record.items():
                if i == "":
                    i = "Empty"
                buffer[i] = j
                #print(i, j)
                #print(i, j)
            file_data.append(buffer)
        print(file_data)
        T = create_table()
        # table = T(file_data, classes=["table", "table-striped", "table-bordered", "table-hover"])
        # if (len(file_data) > 0) and isinstance(file_data[0], dict):
        #     for c in file_data[0]:
        #         if c != "\n":
        #             table.add_column(c, Col(c, th_html_attrs={"style": "background-color:# afcdff"}))
        #

        table_col = list(file_data[0].keys())
        table_values = [list(d.values()) for d in file_data]

        #return render_template("upload_form.html", form=form, table=table)
        return render_template("Single_Table_FixedBG.html",
                               backgroud_Filename='css/Charts.jpg',
                               form=form,
                               Table_name="Swaps",
                               header=header,
                               description=description,
                               title=title,
                               html=Markup(
                                   Array_To_HTML_Table(
                                       table_col,
                                       table_values,
                                       Table_Class=[
                                           'table', 'table-striped',
                                           'table-hover', 'table-bordered',
                                           'table-light', 'table-sm'
                                       ])))

    return render_template(
        "Single_Table_FixedBG.html",
        backgroud_Filename='css/Charts.jpg',
        form=form,
        Table_name="Swaps",
        header=header,
        description=description,
        title=title,
        html=Markup(
            Array_To_HTML_Table(Table_Header=[str(i) for i in range(20)],
                                Table_Data=[[
                                    "{:.4f}".format(random.random())
                                    for i in range(20)
                                ] for j in range(100)],
                                Table_Class=[
                                    'table', 'table-striped', 'table-hover',
                                    'table-bordered', 'table-light', 'table-sm'
                                ])))
Exemple #11
0
def upload_file():
    if request.method == 'POST':
        return jsonify({"result": request.get_records(field_name='file')})
    return '''