def post(self, hotel_id): roomtype = ObjectDict(json_decode(self.request.body)) if not self.valid_roomtype(roomtype): return self.finish_json(errcode=401, errmsg="无效的参数") hotel = Hotel.get_by_id(self.db, hotel_id) if not hotel: return self.finish_json(errcode=404, errmsg="无效的Hotel") _roomtype = RoomType.new(self.db, hotel_id, **roomtype) try: module = modules['first_valid'] motivation = motivations['add_roomtype'] operator = self.current_user poi_hotel_id =hotel.id poi_roomtype_id = _roomtype.id otaId = -1 hotel_id = "-1" hotelModel = Hotel.get_by_id(self.db,poi_hotel_id) hotelName = hotelModel.name roomType = RoomType.get_by_id(self.db,id=poi_roomtype_id) operate_content = u"新增"+_roomtype.name+"," + roomtypes[_roomtype.bed_type]+"," + str(_roomtype.floor) + u"楼" PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator, poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id,poi_roomtype_id=poi_roomtype_id) except Exception,e: traceback.print_exc()
def put(self, hotel_mapping_id): Log.info("Second>>Hotel {}>>Valid>> user:{}".format(hotel_mapping_id, self.current_user)) hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id) if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.wait_second_valid\ and hotel_mapping.main_hotel_id != 0: hotels = HotelMapping.get_by_chain_id_and_main_hotel_id(self.db, hotel_mapping.provider_id, hotel_mapping.main_hotel_id) for hotel in hotels: if hotel.id != hotel_mapping.id and hotel.status > hotel_mapping.status: self.finish_json(errcode=402, errmsg=u"已有Hotel{}绑定相同基础酒店".format(hotel.provider_hotel_name)) return hotel_mapping = HotelMapping.set_secondvalid_complete(self.db, hotel_mapping_id) try: module = modules['second_valid'] motivation = motivations['pass_hotel'] operator = self.current_user poi_hotel_id = hotel_mapping.main_hotel_id otaId = hotel_mapping.provider_id hotelName = hotel_mapping.provider_hotel_name hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id) operate_content = hotelName + "<->" + hotelModel.name hotel_id = hotel_mapping_id PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id) except Exception,e: traceback.print_exc() self.finish_json(result=ObjectDict( hotel_mapping=hotel_mapping.todict(), ))
def put(self): req = ObjectDict(json_decode(self.request.body)) Log.info("Polymer>>Hotel>>Online>> user:{} req:{}".format(self.current_user, req)) hotel_mapping_id = req.hotel_mapping_id is_online = req.is_online hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id) if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.valid_complete: hotel_mapping = HotelMapping.set_online(self.db, hotel_mapping_id, is_online) if hotel_mapping.is_online in [0, -1]: RoomTypeMapping.disable_by_provider_hotel_id(self.db, hotel_mapping.provider_hotel_id) try: redisClient.put('poi_online',hotel_mapping.main_hotel_id) except Exception,e: traceback.print_exc() yield self.notify_stock(hotel_mapping.provider_id, hotel_mapping.provider_hotel_id) try: module = modules['merge'] motivation = None if is_online in [0, -1]: motivation = motivations['offline_hotel'] else: motivation = motivations['online_hotel'] operator = self.current_user poi_hotel_id = hotel_mapping.main_hotel_id otaId = hotel_mapping.provider_id hotelName = hotel_mapping.provider_hotel_name hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id) operate_content = hotelName + "<->" + hotelModel.name hotel_id = hotel_mapping_id PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id) except Exception,e: traceback.print_exc()
def post(self): args = self.get_json_arguments() chain_hotel_id, main_hotel_id, merchant_id, merchant_name = get_and_valid_arguments(args, 'chain_hotel_id', 'main_hotel_id', 'merchant_id', 'merchant_name') hotel = HotelModel.get_by_id(self.db, main_hotel_id) hotel_mapping = HotelMappingModel.get_by_provider_hotel(self.db, 6, chain_hotel_id,is_delete=-1) if hotel_mapping: Log.info(">>> modify exist ebooking hotel {}".format(hotel_mapping.todict())) hotel_mapping.merchant_id = merchant_id hotel_mapping.merchant_name = merchant_name hotel_mapping.info = 'update by ebooking' hotel_mapping.status = hotel_mapping.STATUS.valid_complete hotel_mapping.city_id = hotel.city_id hotel_mapping.provider_hotel_name = hotel.name hotel_mapping.provider_hotel_address = hotel.address hotel_mapping.main_hotel_id = hotel.id hotel_mapping.is_delete = 0 self.db.commit() else: hotel_mapping = HotelMappingModel.new_hotel_mapping_from_ebooking(self.db, chain_hotel_id, hotel.name, hotel.address, hotel.city_id, main_hotel_id, merchant_id, merchant_name) self.finish_json(result=dict( hotel_mapping=hotel_mapping.todict(), ))
def merge_main_hotel_info(self, hotels): hotel_ids = [mapping.main_hotel_id for mapping in hotels] main_hotels = Hotel.get_by_ids(self.db, hotel_ids) for hotel in hotels: for main_hotel in main_hotels: if main_hotel.id == hotel.main_hotel_id: hotel['main_hotel'] = main_hotel.todict() break
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return {'message': 'internal server error'}, 500 return {'message': 'hotel deletado'} return {'message': 'hotel não encotrado'}, 404
def delete(self, hotel_id): global hoteis hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except Exception: return {'message', 'An error occurred trying to delete'} return {'message': 'Hotel deleted.'} return {'message': 'Hotel not found'}, 404
def delete(self, id): hotel = HotelModel.find_by_id(id) if hotel: try: hotel.save_hotel() return { 'hoteis': [ hotel.convertToDictionary() for hotel in HotelModel.find_all() ] } except: return { 'Message': 'An internal error ocurred while attempting to save the data' }, 500 return {'Message': 'Hotel not found'}, 404
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return {'message': 'Internal Error while tring to delete'}, 500 return {'message': 'Hotel Deleted'}, 200 return {'message': 'Hotel not found'}, 400
def delete(self, hotel_id: int): hotel = HotelModel.find_hotel(hotel_id) if hotel is None: return {'message': 'The Hotel doesn\'t exist'}, 404 try: hotel.delete() except: return {'message': 'An internal server error'}, 500 return 200
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return {'message:' 'An error ocurred trying to delete hotel.'}, 500 return {'message': 'Hotel deleted.'} return {'message': 'Hotel not found.'}, 404
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() return {'message': f"Hotel '{hotel_id}' deleted."} except Exception as err: return {'message': f'Erro ao Deletar os dados {err}'} return {'message': f"Hotel '{hotel_id}' not found."}, 404
def get(self, hotel_id: int) -> dict: hotel = HotelModel.find_hotel(hotel_id) if hotel: return { 'message': f'Hotel {hotel_id} found.', 'data': hotel.json() }, 200 return {'message': 'Hotel not found.', 'data': {}}, 404
def delete(self, id): hotel = HotelModel.hotel_find_by_id(id) if hotel: try: hotel.delete_hotel() except: return { 'message': 'An internal error ocurred trying to save hotel' }, 500 return {'message': 'Hotel deleted'}, 204 return {'message': 'Hotel not found'}, 404
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return { 'message': 'Erro interno ao tentar deletar hotel.' }, 500 return {'message': 'Hotel deletado.'} return {'message': 'Hotel não existe.'}
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return { 'message': 'An error ocurrend trying to delete hotel.' }, 500 # Internal server error return {'message': 'hotel deletado'} return {'message': 'hotel not found.'}, 404 # not found
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return { 'message': 'An Error Ocurred Trying To Delete Hotel' }, 500 return {'message': 'Hotel deleted.'} return {'message': 'Hotel not found.'}, 404
def delete(self, hotel_id): #global hoteis #hoteis = [hotel for hotel in hoteis if hotel['hotel_id'] != hotel_id ] hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return {'message': 'error ocurred trying to delete hotel.'}, 500 #Internal server 500 return {'message': 'Hotel deleted.'} return {'message': 'Hotel not found.'}
def put(self, hotel_id): dados = Hotel.argumentos.parse_args() hotel_encontrado = HotelModel(hotel_id, **dados) if hotel_encontrado: hotel_encontrado.update_hotel(**dados) # **dados -> kwarg hotel_encontrado.save_hotel() return hotel_encontrado.json(), 200 hotel_encontrado = HotelModel.find_hotel(hotel_id) try: hotel.save_hotel() except: return {'message': 'An internal error ocurred trying to save hotel.'}, 500 return hotel.json(), 201 # created
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if not hotel: return {'message': 'Hotel not found'}, 404 try: hotel.delete_hotel() except: return { 'message': 'An internal error ocurred trying to delete hotel.' }, 500 # Internal server error. return {'message': 'Hotel deleted'}, 200
def delete(self, hotel_id): hotel = HotelModel.findHotel(hotel_id) if hotel is not None: try: hotel.delete_hotel() except: return {"message": "An error ocurred trying to delete"} return make_response(jsonify({"message": "Hotel deleted."}), 202) return make_response(jsonify({"message": "Hotel deleted."}), 404)
def merge_hotels(self, hotel_room): hotel_ids = [hotel['main_hotel_id'] for hotel in hotel_room] self.roomtypes = RoomType.gets_by_hotel_ids(self.db, hotel_ids) self.roomtypes = [roomtype.todict() for roomtype in self.roomtypes] hotels = Hotel.get_by_ids(self.db, hotel_ids) hotel_mapping = {hotel.todict()['id']: hotel.todict() for hotel in hotels} for hotel in hotel_room: if hotel['main_hotel_id'] in hotel_mapping: hotel['main_hotel'] = hotel_mapping[hotel['main_hotel_id']]
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return { "message": "An error occured trying to delete hotel." }, 500 return {"message": "Hotel deleted."}, 200 return {"message": "Hotel not found."}, 404
def put(self, hotel_id): dados = Hotel.atributos.parse_args() # novo_hotel = hotel.json() # novo_hotel = { 'hotel_id': hotel_id, **dados } # hotel = Hotel.find_hotel(hotel_id) hotel_encontrado = HotelModel.find_hotel(hotel_id) if hotel_encontrado: # hotel.update(hotel) # return novo_hotel, 200 hotel_encontrado.update_hotel(**dados) hotel_encontrado.save_hotel() return hotel_encontrado.json(), 200 hotel = (HotelModel(hotel_id, **dados)) try: hotel.save_hotel() except: return { 'message': 'An internal error ocurred trying to save hotel.' }, 500 return hotel.json(), 201
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return { 'message': 'Erro interno ao tentar deletar o hotel.' }, 500 return {'message': 'Hotel deleted.'} return {'message': 'Hotel not found.'}, 404
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() return {'message': 'Hotel deleted'} except: return { 'message': 'An error occurred while deleting the hotel' }, 500 # Internal Server Error return {'message': 'Hotel not found'}, 404 # not found
def post(self) -> dict: data = getInformations() if not SiteModel.find_by_id(data.get('site_id')): return { 'message': 'The hotel must be associated to a valid site id.' }, 400 hotel = HotelModel(**data) try: hotel_id = hotel.save_hotel() return { 'message': f'Hotel {hotel_id} create with success!', 'data': hotel.json() }, 201 except Exception as ex: return { 'message': f'An error ocurred when trying to create hotel: {ex}' }, 500
def delete(hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: traceback.print_exc() return { "message": "An error ocurred trying to create hotel." }, 500 #Internal Server Error return {"message": f"hotel '{hotel_id}' deleted."} return {"message": f"hotel '{hotel_id}' not found."}, 404
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return { 'message', 'internal error trying to delete the hotel' }, 500 return {'message': 'Hotel deleted.'} return {'message': 'Hotel not found'}, 404
def delete(self, hotel_id): hotel = HotelModel.find(hotel_id) if hotel: try: hotel.delete() except: return { 'message': 'An internal error occurred trying to delete hotel.' }, 500 return {'message': 'Hotel deleted.'}, 200 return {'message': 'Hotel not found.'}, 404
def delete(self, hotel_id): obj_hotel = HotelModel.find_hotel(hotel_id) if obj_hotel: try: obj_hotel.delete_hotel() except: return { "message": "An internal error ocurred trying to delete hotel." }, 500 return {"message": "Hotel deleted!"} return {"message": "Hotel not found!"}, 404
def delete(self, hotel_id): # hoteis = [hotel for hotel in hoteis if hotel['hotel_id'] != hotel_id] hotel_encontrado = HotelModel.find_hotel(hotel_id) if hotel_encontrado: try: hotel_encontrado.delete_hotel() except: return { 'message': 'An error ocurred trying to delete hotel.' }, 500 return {"message": "Hotel id '{}' deleted.".format(hotel_id)}, 200 return {"message": "Hotel id '{}' not found.".format(hotel_id)}, 404
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete_hotel() except: return {'msg': 'Erro inesperado.'}, 500 return {'msg': f'Hotel {hotel_id} deleted.'} return {'msg': f'Hotel {hotel_id} not found.'}, 404
def delete(self, hotel_id): hotel = HotelModel.find_hotel(hotel_id) if hotel: try: hotel.delete() except: return { 'message': 'An internal error ocurred, please try again later.' }, 500 return {'message': 'Hotel {} deleted.'.format(hotel.nome)}, 200 return {'message': 'Hotel id {} not found'.format(hotel_id)}, 404
def post(self, hotel_id): """ Cria hotel """ if HotelModel.find_hotel(hotel_id): # bad request return { "message": "Hotel id '{}' already exists.".format(hotel_id) }, 400 dados = Hotel.argumentos.parse_args() hotel = HotelModel(hotel_id, **dados) if not SiteModel.find_by_id(dados.get('site_id')): return { 'message': 'The hotel must be associated to a valid site id.' }, 400 try: hotel.save_hotel() except expression as identifier: return { 'message': 'An internal server error occured trying to save hotel.' } return hotel.json()
def put(self, hotel_id): """ Alterar Hotel """ dados = Hotel.argumentos.parse_args() hotel_encontrado = HotelModel.find_hotel(hotel_id) if hotel_encontrado: hotel_encontrado.update_hotel(**dados) try: hotel.save_hotel() except expression as identifier: return { 'message': 'An internal server error occured trying to save hotel.' } return novo_encontrado.json(), 200 # updated hotel = HotelModel(hotel_id, **dados) try: hotel.save_hotel() except expression as identifier: return { 'message': 'An internal server error occured trying to save hotel.' } return hotel.json(), 201 # created
def put(self, hotel_id): roomtype = ObjectDict(json_decode(self.request.body)) if not self.valid_roomtype(roomtype): return self.finish_json(errcode=401, errmsg="无效的参数") hotel = Hotel.get_by_id(self.db, hotel_id) if not hotel: return self.finish_json(errcode=404, errmsg="无效的Hotel") tempRoomType = RoomType.get_by_id(self.db,roomtype['id']) tempName = tempRoomType.name tempBedType = tempRoomType.bed_type tempFloor = tempRoomType.floor tempArea = tempRoomType.area _roomtype = RoomType.update(self.db, **roomtype) try: module = modules['first_valid'] motivation = motivations['modify_roomtype'] operator = self.current_user poi_hotel_id =hotel.id poi_roomtype_id = _roomtype.id otaId = -1 hotel_id = "-1" hotelModel = Hotel.get_by_id(self.db,poi_hotel_id) hotelName = hotelModel.name roomType = RoomType.get_by_id(self.db,id=poi_roomtype_id) operate_content = '' if tempName != _roomtype.name: operate_content += u'将' + tempName + u"修改为" + _roomtype.name + "," if tempBedType != _roomtype.bed_type: operate_content += u'将' + roomtypes[tempBedType] + u'修改为' + roomtypes[_roomtype.bed_type] + "," if tempFloor != _roomtype.floor: operate_content += u'将' + str(tempFloor) + "楼修改为" + str(_roomtype.floor) + "楼," if tempArea != _roomtype.area: operate_content += u'将' + str(tempArea) + "平米修改为" + str(_roomtype.area) + "平米," PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator, poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id,poi_roomtype_id=poi_roomtype_id) except Exception,e: traceback.print_exc()
def get(self, hotel_id): need_valid = self.get_query_argument('need_valid', 1) need_valid = True if need_valid == 1 else False hotel = Hotel.get_by_id(self.db, hotel_id) if hotel: hotel = hotel.todict() rooms = RoomType.gets_by_hotel_id(self.db, hotel_id, need_valid=need_valid) rooms = [room.todict() for room in rooms] return self.finish_json(result=dict( roomtypes=rooms, hotel=hotel, )) else: return self.finish_json(errcode=404, errmsg="无效的Hotel")
def add_hotel_mapping(self, hotel): Log.info(">>> push ebooking hotel {}".format(hotel)) hotel_mapping = HotelMappingModel.get_by_provider_hotel(self.db, 6, hotel['chain_hotel_id'],is_delete=-1) main_hotel = HotelModel.get_by_id(self.db, hotel['main_hotel_id']) if hotel_mapping: Log.info(">>> modify exist ebooking hotel {}".format(hotel)) hotel_mapping.merchant_id = hotel['merchant_id'] hotel_mapping.merchant_name = hotel['merchant_name'] hotel_mapping.info = 'update by ebooking' hotel_mapping.status = hotel_mapping.STATUS.valid_complete hotel_mapping.city_id = main_hotel.city_id hotel_mapping.provider_hotel_name = main_hotel.name hotel_mapping.provider_hotel_address = main_hotel.address hotel_mapping.main_hotel_id = main_hotel.id hotel_mapping.is_delete = 0 self.db.commit() else: Log.info(">>> new exist ebooking hotel {}".format(hotel)) hotel_mapping = HotelMappingModel.new_hotel_mapping_from_ebooking(self.db, hotel['chain_hotel_id'], main_hotel.name, main_hotel.address, main_hotel.city_id, hotel['main_hotel_id'], hotel['merchant_id'], hotel['merchant_name']) return hotel_mapping
def delete(self, hotel_mapping_id): Log.info("Second>>Hotel {}>>Delete>> user:{}".format(hotel_mapping_id, self.current_user)) hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id) if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.wait_second_valid: hotel_mapping = HotelMapping.revert_to_firstvalid(self.db, hotel_mapping_id) RoomTypeMapping.revert_to_firstvalid_by_provider_hotel_id(self.db, hotel_mapping.provider_hotel_id) try: module = modules['second_valid'] motivation = motivations['back_hotel'] operator = self.current_user poi_hotel_id = hotel_mapping.main_hotel_id otaId = hotel_mapping.provider_id hotelName = hotel_mapping.provider_hotel_name hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id) operate_content = hotelName + "<->" + hotelModel.name hotel_id = hotel_mapping_id PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id) except Exception,e: traceback.print_exc() self.finish_json(result=ObjectDict( hotel_mapping=hotel_mapping.todict(), ))