def delete(self, uuid): device = DeviceModel.find_by_uuid(uuid) if device: return {"device": device_schema.dump(device)}, 200 return {"message": "No device found"}, 404
def put(self, uuid): try: device = DeviceModel.find_by_uuid(uuid) device.robot_uuid = None device.save_to_db() except: return {"message": "no device found"}, 400 return {"device": 'device disconnected!'}, 200
def load_data(self): sheet = self.origin_excel.sheets()[0] upload_excel_head_fields = sheet.row_values(0) self.__check_excel_head_fields(upload_excel_head_fields) title_dict = {item: list(upload_excel_head_fields).index(item) for item in self.head_fields_cn} row_list = self.__load_data_by_row(sheet) # 按行读取,生成二级数据[[],[]] row_list = self.__place_data_by_regular(row_list, title_dict) # 将每一行的数据放置到正确的位置,生成[{}, {}] row_list = self.__filter_data(row_list) # 去掉不符合规范的数据 device_list = DeviceModel.objects.insert([DeviceModel(**item) for item in row_list]) return device_list
def put(self, uuid): data = request.get_json(silent=True) try: device = DeviceModel.find_by_uuid(uuid) device.robot_uuid = data["robot_uuid"] device.save_to_db() except: return {"message": "no device found"} return { "device": f'device connected to robot_uuid {data["robot_uuid"]}' }, 200
def post(self): data = request.get_json(silent=True) try: device = DeviceModel.find_by_uuid(data["device_uuid"]) if device: if device.check_password(data["password"]): token = create_access_token(identity=device.uuid, fresh=True) return {"token": token}, 200 return {"message": "Wrong password"}, 401 return {"message": "No device found"}, 401 except: return {"message": "Cannot write Data"}, 500
def get(self): return { "users": device_schema_list.dump(DeviceModel.find_all_devices()) }
def add_claims_to_access_token(device): device = DeviceModel.find_by_uuid(device) return {'robot_uuid': device.robot_uuid, 'device_uuid': device.uuid}