def delete(self, id): """ 删除用户 :return: """ self.arguments['id'] = id try: validate.users_delete(self.arguments) users = self.service.delete(self.arguments['id']) if users is False or users is 0: raise peewee.DoesNotExist( exceptions.data_not_existed, exceptions.get_error_message(exceptions.data_not_existed)) self.echoJson(0, {"info": "success"}) except error.RequestData as e: self.echo_error(e.code, e.message) except peewee.DoesNotExist: self.echoJson( exceptions.data_not_existed, exceptions.get_error_message(exceptions.data_not_existed)) except exceptions.Database as e: self.echoJson(e.code, e.message) except Exception as e: self.echoJson(exceptions.exception, str(e)) except error.Database as e: self.echoJson(e.code, e.message) self.close_connect_and_finish()
def put(self, id): """ 更新case :return: """ self.arguments['id'] = id try: validate.cases_update(self.arguments) del self.arguments['id'] cases = self.service.update(id, **self.arguments) if cases is False or cases is 0: raise peewee.DoesNotExist( exceptions.data_not_existed, exceptions.get_error_message(exceptions.data_not_existed)) self.echoJson(0, {"info": "success"}) except error.RequestData as e: self.echo_error(e.code, e.message) except peewee.DoesNotExist: self.echoJson( exceptions.data_not_existed, exceptions.get_error_message(exceptions.data_not_existed)) except exceptions.Database as e: self.echoJson(e.code, e.message) except Exception as e: self.echoJson(exceptions.exception, str(e)) self.close_connect_and_finish()
def read_item(self, item_id): assert self._model_class item = self._model_class.get(self._model_class.id == item_id, self._model_class.is_deleted == False) if not item: raise peewee.DoesNotExist() return item
def put(self, email): """ 修改用户密码 :param email: :return: """ try: validate.users_update(self.arguments) password = self.service.update_password(**self.arguments) if password is False or password is 0: raise peewee.DoesNotExist( exceptions.data_not_existed, exceptions.get_error_message(exceptions.data_not_existed)) self.echoJson(0, {"info": "success"}) except error.RequestData as e: self.echo_error(e.code, e.message) except peewee.DoesNotExist: self.echoJson( exceptions.data_not_existed, exceptions.get_error_message(exceptions.data_not_existed)) except exceptions.Database as e: self.echoJson(e.code, e.message) except Exception as e: self.echoJson(exceptions.exception, str(e)) self.close_connect_and_finish()
def ls( self, path: str = ".", refresh: bool = False, recursive: bool = False ) -> Tuple[List["Folder"], List["Job"]]: """ Lists the current directory content. :param path: The path to list the content for :param refresh: FLag to indicate whether job statuses should be refreshed :param recursive: Descend into the folder hierarchy to find all jobs to list :return: List of folders and list of jobs found """ logger.debug("%s", list(self.cwd.children)) folder = Folder.find_by_path(path, self.cwd) if folder is None: raise pw.DoesNotExist() if recursive: jobs = folder.jobs_recursive() else: jobs = folder.jobs if refresh: jobs = self.refresh_jobs(list(jobs)) return list(folder.children), list(jobs)
async def _get_existing(self, entity: dict, existing: Source = None) -> Source: if existing: return existing if entity['id'] is not None: return await self._manager.get( Source.select().where(Source.id == entity['id']), ) # type: Source raise peewee.DoesNotExist()
def delete_item(self, item_id): assert self._model_class my_item = self._model_class.select().where( self._model_class.id == item_id, self._model_class.is_deleted == False).get() if my_item: my_item.is_deleted = True my_item.changed() my_item.save() return my_item raise peewee.DoesNotExist()
def test_get_failure(self): mock = MagicMock() mock.side_effect = peewee.DoesNotExist('Not found') vegadns.api.endpoints.apikey.ApiKey.get_apikey = mock self.mock_auth('*****@*****.**', 'test') response = self.open_with_basic_auth('/apikeys/1', 'GET', '*****@*****.**', 'test') self.assertEqual(response.status, "404 NOT FOUND")
async def _get_existing(self, entity: dict, existing: Item = None) -> Item: if existing: return existing logger.debug('find existing db record for %s', entity) candidates = await self._manager.prefetch( Item.select().where(Item.id == entity['id']), Item2Source.select().where(Item2Source.item_id == entity['id']) ) # type: list[Item] for x in candidates: if x.id == entity['id']: return x raise peewee.DoesNotExist()
def check(cls, login, password): q = cls.select(cls.id, cls.password).where( cls.disabled == False, cls.login == str(login), ) user = q.limit(1) user = user[0] if user else None if user and user.password.check_password(password): return cls.get(id=user.id) else: raise p.DoesNotExist("User doesn't exists")
def cd(self, target: Union[str, Folder] = ".") -> None: """ Change the current working directory. :param target: String path or folder instance to change into. """ if isinstance(target, str): if target == "": folder = Folder.get_root() else: _folder = Folder.find_by_path(target, self.cwd) if _folder is None: raise pw.DoesNotExist() folder = _folder self.cwd = folder elif isinstance(target, Folder): self.cwd = target else: raise TypeError(f"{target} is not str or Folder")