def addupdate_assets(): sn = request.form.get('sn') warranty = request.form.get('warranty') cpu = request.form.get('cpu') ram = request.form.get('ram') disk = request.form.get('disk') _is_ok, _error = asset.validate_update(sn, warranty, cpu, ram, disk) if _is_ok: asset.update(warranty, cpu, ram, disk, sn) return json.dumps({'is_ok': _is_ok, 'error': _error})
def asset_update(): if request.method == 'GET': # 返回更新资产模版给dialog页面 _id = request.args.get('aid', '') _asset_list = [] for i in asset.get_list(): if i.get('id') == int(_id): _asset_list.append(i) print asset.get_idc() return render_template('asset/asset_update.html', asset_list=_asset_list, idcs=asset.get_idc()) else: print request.form # POST传过来的数据太多了,我们使用for循环遍历获取所有数据,存放到一个dict中。 lists = ['ip','hostname','idc_id','purchase_date','warranty','vendor','model','admin','business','os','cpu','ram','disk','id'] asset_dict = {} for i in lists: asset_dict['_'+i] = request.form.get(i, '') # 检查资产信息 is_ok, error = asset.validate_update(asset_dict) msg = '' if is_ok: if asset.update(asset_dict): msg = '更新资产成功!' else: msg = '更新资产失败!' return json.dumps({'is_ok': is_ok, 'msg': msg, 'error': error})
def asset_modify(): _id = request.form.get('id','') _sn = request.form.get('sn','') _ip = request.form.get('ip','') _hostname = request.form.get('hostname','') _os = request.form.get('os','') _cpu = request.form.get('cpu','') _ram = request.form.get('ram','') _disk = request.form.get('disk',) _idc_id = request.form.get('idc_id','') _admin = request.form.get('admin','') _business = request.form.get('business','') _purchase_date = request.form.get('purchase_date','') _warranty = request.form.get('warranty') _model = request.form.get('model','') _vendor = request.form.get('vendor','') _is_ok,_error = asset.validate_update(_id,_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_model,_warranty,_vendor) if _is_ok: asset.update([_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_warranty,_model,_vendor,_id]) return json.dumps({'_is_ok':_is_ok,'error':_error})
def update_asset(): asset_info = request.form print '更新资产', asset_info repeat = False _is_ok, _errors = asset.validate(asset_info, repeat) if _is_ok: if asset.update(asset_info): _is_ok = True else: _is_ok = False _errors = {"update": "更新不成功"} return json.dumps({ "is_ok": _is_ok, "success": "更新成功", "errors": _errors, "asset_info": asset_info })
def asset_upd(): _id = request.form.get('id', '') assets = [ 'sn', 'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty', 'vendor', 'model', 'admin', 'business', 'os', 'cpu', 'ram', 'disk' ] asset_dict = {} for i in assets: asset_dict['_' + i] = request.form.get(i, '') # 检查资产信息 _is_ok, _error = asset.validate_update(asset_dict) _status = None if _is_ok: if asset.update(asset_dict, _id): _status = '更新资产成功!' else: _status = '更新资产失败!' return json.dumps({'is_ok': _is_ok, 'status': _status, 'error': _error})
def change_asset(): params = request.form Flag, errors = asset.validate_update(dict(params)) if not Flag: return json.dumps({'_is_ok': False, 'errors': errors}) else: Flag = asset.update(dict(params)) if Flag: return json.dumps({ '_is_ok': True, 'errors': { 'successful': u'数据更新成功!' } }) else: return json.dumps({ '_is_ok': False, 'errors': { 'error': u'数据更新失败!' } })
def update_asset(): _is_ok, _errors = asset.validate_update(request.form) if _is_ok: asset.update(request.form) return json.dumps({'is_ok': _is_ok, 'errors': _errors, 'success': '更新成功'})