def auto_commit(self): try: yield self.session.commit() except Exception: self.session.rollback() raise ClientException()
def validate_for_api(self): valid = super(BaseValidator, self).validate() if not valid: raise ClientException(msg=self.errors) return self
def validate_authorization_code(self, field): authorization_code = current_app.config['AUTHORIZATION_CODE'] if field.data != authorization_code: raise ClientException(401)
def get_articles_with_category(cls, category_id): if not category_id: raise ClientException() return cls.query.filter_by(category_id=category_id).all()
def get_or_404(self, ident, description=None): rv = self.get(ident) if rv is None: raise ClientException(code=404, msg=description) return rv
def first_or_404(self, description=None): rv = self.first() if rv is None: raise ClientException(code=404, msg=description) return rv
def check_password(self, password): if not check_password_hash(self.password, password): raise ClientException(code=401, msg='密码或用户名错误')