예제 #1
0
def update_by_data(records, update_data, do_commit=True):
    update_data['update_time'] = datetime.now()
    records.update(update_data)
    resp = [True, '', const.code_success]
    if do_commit:
        resp = db_commit()
    return resp
예제 #2
0
def add_by_data(table, data, do_commit=True):
    record = table(**data)
    db.session.add(record)
    resp = [True, '', const.code_success]
    if do_commit:
        resp = db_commit()
    return resp
예제 #3
0
def update_by_data(records, update_data, do_commit=True):
    update_data['update_time'] = datetime.now()
    records.update(update_data)
    resp = [True, '', const.CODE_SUCCESS]
    if do_commit:
        resp = db_commit()
    return resp
예제 #4
0
def add_by_data(table, data, do_commit=True):
    record = table(**data)
    db.session.add(record)
    resp = [True, '', const.CODE_SUCCESS]
    if do_commit:
        resp = db_commit()
    return resp
예제 #5
0
def delete_by_id(table, id, do_commit=True):
    res = is_id_exist(table, id)
    if res[0]:
        delete_info['update_time'] = datetime.now()
        res[1].update(delete_info)
        resp = [True, '', const.code_success]
        if do_commit:
            resp = db_commit()
        return resp
    return False, '记录不存在', const.code_param_illegal
예제 #6
0
def delete_by_id(table, id, do_commit=True):
    res = is_id_exist(table, id)
    if res[0]:
        delete_info['update_time'] = datetime.now()
        res[1].update(delete_info)
        resp = [True, '', const.CODE_SUCCESS]
        if do_commit:
            resp = db_commit()
        return resp
    return False, '记录不存在', const.PARAM_ILLEGAL
예제 #7
0
def after_request(response):
    from models import db_commit, db_end
    db_commit()
    db_end()
    return response