Esempio n. 1
0
 def put(self, id):
     try:
         asset = db.session.query(AssetAssets).filter(
             AssetAssets.id == id).first()
         if not asset:
             return jsonify({"status": False, "desc": "无法查询到该资产"})
         asset_dict = request.get_json()
         asset.serial_no = asset_dict.get('serial_no')
         asset.name = asset_dict.get('name')
         asset.location = asset_dict.get('location')
         asset.owner = asset_dict.get('owner')
         asset.owner_contact = asset_dict.get('owner_contact')
         asset.type_id = asset_dict.get('type_id')
         asset.ip = asset_dict.get('ip')
         asset.agent_type_id = asset_dict.get('agent_type_id')
         asset.port = asset_dict.get('port')
         asset.network = asset_dict.get('network')
         asset.manufacturer = asset_dict.get('manufacturer')
         asset.describe = asset_dict.get('describe')
         db.session.add(asset)
         db.session.commit()
     except Exception, e:
         logger.error(e)
         db.session.rollback()
         return jsonify({"status": False, "desc": "资产修改失败"})
Esempio n. 2
0
 def delete(self, id):
     try:
         db.session.query(AssetAssets).filter(AssetAssets.id == id).delete()
         db.session.commit()
     except Exception, e:
         logger.error(e)
         db.session.rollback()
         return jsonify({"status": False, "desc": "资产删除失败"})
Esempio n. 3
0
 def get(self, id):
     try:
         asset = db.session.query(AssetAssets).filter(
             AssetAssets.id == id).first()
         if not asset:
             return jsonify({"status": False, "desc": "无法查询到该资产"})
     except Exception, e:
         logger.error(e)
         db.session.rollback()
         return jsonify({"status": False, "desc": "查询资产失败"})
Esempio n. 4
0
    def post(self):
        try:
            asset_dict = request.get_json()
            asset = AssetAssets._from_dict(asset_dict)

            db.session.add(asset)
            db.session.commit()
        except Exception, e:
            logger.error(e)
            db.session.rollback()
            return jsonify({"status": False, "desc": "资产添加失败"})
Esempio n. 5
0
 def get(self):
     try:
         assets_types = db.session.query(AssetType).all()
         if not assets_types:
             return jsonify({"status": False, "desc": "资产类别数目为0"})
         asset_type_list = [
             assets_type._to_dict() for assets_type in assets_types
         ]
     except Exception, e:
         logger.error(e)
         db.session.rollback()
         return jsonify({"status": False, "desc": "获取资产类别失败"})
Esempio n. 6
0
 def get(self):
     try:
         # if 'priv_asset_read' not in session.get('selectors', ()):
         #     return jsonify({"status": False, "desc": "用户无权限查看"})
         page, per_page, offset, search_msg = get_page_items()
         query = db.session.query(AssetAssets)
         assets = query.limit(per_page).offset(offset).all()
         total = query.count()
         if not assets:
             return jsonify({"status": False, "desc": "资产数目为0"})
         asset_list = [asset._to_dict() for asset in assets]
     except Exception, e:
         logger.error(e)
         db.session.rollback()
         return jsonify({"status": False, "desc": "获取资产失败"})
Esempio n. 7
0
    def post(self):
        try:
            files = request.files
            f = files['file']
            data = xlrd.open_workbook(filename=None, file_contents=f.read())
            sheet_data = data.sheets()[0]
            table = sheet_data._cell_values
            for row in table[1:]:
                asset = AssetAssets._from_excel_row(row)
                db.session.add(asset)
                db.session.flush()
            db.session.commit()

        except Exception, e:
            logger.error(e)
            db.session.rollback()
            return jsonify({"status": False, "desc": "资产导入失败"})