Ejemplo n.º 1
0
def add_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')
    ip = request.form.get('ip')
    idc_id = request.form.get('idc_id')
    idc_value = request.form.get('idc_value')
    print idc_id
    print idc_value

    _is_ok, _error = asset.validate_create(sn, warranty, cpu, ram, disk, ip)
    if _is_ok:
        asset.create(sn, warranty, cpu, ram, disk, ip, idc_id)
    return json.dumps({'is_ok': _is_ok, 'error': _error})
Ejemplo n.º 2
0
def asset_add():
    _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_create(_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_model,_warranty,_vendor)
    if _is_ok:
        asset.create([_sn,_ip,_hostname,_os,_cpu,_ram,_disk,_idc_id,_admin,_business,_purchase_date,_warranty,_model,_vendor])
    return json.dumps({'_is_ok':_is_ok,'error':_error})
Ejemplo n.º 3
0
def add_asset():
    params = request.form
    Flag, errors = asset.validate_create(dict(params))
    if not Flag:
        return json.dumps({'_is_ok': False, 'errors': errors})
    Flag = asset.create(dict(params))
    if Flag:
        return json.dumps({
            '_is_ok': True,
            'errors': {
                'successful': u'数据插入成功!'
            }
        })
    else:
        return json.dumps({'_is_ok': False, 'errors': {'error': u'数据插入失败!'}})
Ejemplo n.º 4
0
def add_asset():
    asset_info = request.form
    _is_ok, _errors = asset.validate(asset_info)
    if _is_ok:
        if asset.create(asset_info):
            _is_ok = True
        else:
            _is_ok = False
            _errors = {"add": "添加不成功"}
    return json.dumps({
        "is_ok": _is_ok,
        "success": "添加成功",
        "errors": _errors,
        "asset_info": asset_info
    })
Ejemplo n.º 5
0
def asset_add():
    lists = [
        'sn', 'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty',
        'vendor', 'model', 'admin', 'business', 'os', 'cpu', 'ram', 'disk'
    ]
    asset_dict = {}
    for i in lists:
        asset_dict['_' + i] = request.form.get(i, '')
    # 检查资产信息
    _is_ok, _error = asset.validate_create(asset_dict)
    status = None
    if _is_ok:
        if asset.create(asset_dict):
            status = '添加资产成功!'
        else:
            status = '添加资产失败!'
    return json.dumps({'is_ok': _is_ok, 'status': status, 'error': _error})
Ejemplo n.º 6
0
def asset_add():
    if request.method == 'GET':
        # 返回新建资产模版给dialog页面
        # idc = [(1, u'数北'), (2, u'兆维'), (3, u'亦庄')]
        idc = asset.get_idc()
        return render_template('asset/asset_create.html', idcs=idc)
    else:
        # print request.form
        # POST传过来的数据太多了,我们使用for循环遍历获取所有数据,存放到一个dict中。
        lists = ['sn','ip','hostname','idc_id','purchase_date','warranty','vendor','model','admin','business','os','cpu','ram','disk']
        asset_dict = {}
        for i in lists:
            asset_dict['_'+i] = request.form.get(i, '')
        # 检查资产信息
        is_ok, error = asset.validate_create(asset_dict)
        msg = ''
        if is_ok:
            if asset.create(asset_dict):
                msg = '添加资产成功!'
            else:
                msg = '添加资产失败!'
        return json.dumps({'is_ok': is_ok,  'msg': msg, 'error': error})
Ejemplo n.º 7
0
def add_asset():
    _is_ok, _errors = asset.validate_create(request.form)
    if _is_ok:
        asset.create(request.form)
    return json.dumps({'is_ok': _is_ok, 'errors': _errors, 'success': '添加成功'})