示例#1
0
def product_update(product_id):
    try:
        people_tb = DBBaseClass('people')
        product_tb = DBBaseClass('product')
        if request.method == 'GET':
            current_app.logger.debug('Product Update [GET] 开始...')
            peoples_data = people_tb.get({
                'output': ['id', 'name'],
                'where': {
                    'status': 1
                }
            })
            product_data = product_tb.get(
                {'where': {
                    'status': 1,
                    'id': product_id
                }})
            current_app.logger.debug('Product Data: {}'.format(product_data))
            current_app.logger.debug('Product Update [GET] 结束...')
            current_app.logger.debug('Product Update [Render] 开始...')
            return render_template('cmdb/product_update.html',
                                   product=product_data[0],
                                   peoples=peoples_data)
        else:
            current_app.logger.debug('Product Update [POST] 开始...')
            data = json.loads(request.data.decode(), encoding='utf8')
            product_tb.update({'data': data, "where": {'id': product_id}})
            current_app.logger.debug('Product Update [POST] 结束...')
            return json.dumps({'code': 1})
    except Exception as e:
        current_app.logger.warning('Product Update 执行更新时出现错误:{}'.format(e))
        return json.dumps({'code': 0, 'errMsg': str(e)})
示例#2
0
def people_delete():
    try:
        ids = json.loads(request.data.decode(), encoding='utf8')['id']
        people_tb = DBBaseClass('people')
        for id in ids:
            people_tb.update({'data': {'status': 0}, "where": {'id': id}})
        data = {'code': 1}
    except Exception as e:
        data = {'code': 0, 'errMsg': str(e)}
    return json.dumps(data)
示例#3
0
def people_update(people_id):
    people_tb = DBBaseClass('people')
    if request.method == 'GET':
        people_data = people_tb.get({'where': {'id': people_id}})
        return render_template('cmdb/PeopleManageUpdate.html',
                               people=people_data[0])
    else:
        data = request.form.to_dict()
        print(data)
        res = people_tb.update({'data': data, "where": {'id': people_id}})
        if res:
            return redirect('/people')
示例#4
0
def idc_update(idc_id):
    idc_tb = DBBaseClass('idc')
    if request.method == 'GET':
        current_app.logger.debug('IDC Update [GET] method...')
        idc_data = idc_tb.get({'where': {'id': idc_id}})
        if idc_data:
            try:
                people_tb = DBBaseClass('people')
                people_data = people_tb.get({
                    'output': ['id', 'name', 'phone'],
                    'where': {
                        'id': idc_data[0]['ops_interface']
                    }
                })
                peoples_data = people_tb.get({
                    'output': ['id', 'name'],
                    'where': {
                        'status': 1
                    }
                })
                current_app.logger.debug('Start Render Update Template...')
                return render_template('cmdb/IDCManageUpdate.html',
                                       idc=idc_data[0],
                                       people=people_data[0],
                                       peoples=peoples_data)
            except Exception as e:
                current_app.logger.warning(
                    'IDC Update [GET] 出现错误:{}'.format(e))
                return json.dumps({'code': 0, 'errMsg': str(e)})
    else:
        data = json.loads(request.data.decode(), encoding='utf8')
        try:
            idc_tb.update({'data': data, "where": {'id': idc_id}})
            return json.dumps({'code': 1})
        except Exception as e:
            current_app.logger.warning(
                'IDC Update [POST] 执行更新时出现错误:{}'.format(e))
            return json.dumps({'code': 0, 'errMsg': str(e)})