Beispiel #1
0
def create(**kwargs):
    #1.获取参数信息
    check_field_exists(RaidType, kwargs)
    #2.传参个数验证
    obj = RaidType(**kwargs)
    #3.插入数据库
    db.session.add(obj)
    db.session.commit()
    return obj.id
Beispiel #2
0
def create(**kwargs):
    # 1. 获取参数
    # 2. 验证参数是否合法
    check_field_exists(RaidType, kwargs)
    raidtype = RaidType(**kwargs)
    db.session.add(raidtype)
    try:
        db.session.commit()
    except Exception as e:
        current_app.logger.warning("插入错误: {} ".format(e.message))
        raise Exception("commit error")
    # 3. 插入到数据库
    # 4. 返回插入的状态
    return raidtype.id
Beispiel #3
0
def create(**kwargs):
    # 1 获取参数
    # print kwargs

    # 2 检查参数
    check_field_exists(RaidType, kwargs)

    # 3 插入到数据库
    raidtype = RaidType(**kwargs)
    db.session.add(raidtype)
    try:
        db.session.commit()
    except Exception, e:
        # logging
        current_app.logger.warning("commit error: {}".format(e.message))
        raise Exception("commit error")
Beispiel #4
0
def create(**kwargs):
    #1获取参数
    check_field_exists(RaidType, kwargs)

    #2处理数据
    #print inspect.getmembers(RaidType, predicate=inspect.is)
    #return 1
    print kwargs
    #3实例化record
    record = RaidType(**kwargs)
    #4插入到数据库
    db.session.add(record)
    try:
        db.session.commit()
    except Exception,e:
        raise Exception(e.message.split(") ")[1])
Beispiel #5
0
def create(**kwargs):
    # 1  获取用户传入参数
    print kwargs
    # 2  验证参数的合法性
    for field in kwargs.keys():
        if not hasattr(RaidType, field):
            current_app.logger.warning("参数错误,{},不再idc这张表中".format(field))
            raise Exception("params error: {}".format(field))
        if not kwargs.get(field, None):
            current_app.logger.warning("参数错误,{},不能为空".format(field))
            raise Exception("{} 不能为空".format(field))
    # 3  插入到数据库
    idc = RaidType(**kwargs)
    db.session.add(idc)

    try:
        db.session.commit()
    except Exception, e:
        current_app.logger.warning("commit error: {}".format(e.message))
        raise Exception("commit error")
Beispiel #6
0
def create(**kwargs):
    check_field_exists(RaidType, kwargs)
    obj = RaidType(**kwargs)
    db.session.add(obj)
    db.session.commit()
    return obj.id