Пример #1
0
 def auto_commit(self):
     try:
         yield
         self.session.commit()
     except Exception:
         self.session.rollback()
         raise ClientException()
Пример #2
0
    def validate_for_api(self):
        valid = super(BaseValidator, self).validate()

        if not valid:
            raise ClientException(msg=self.errors)

        return self
Пример #3
0
 def validate_authorization_code(self, field):
     authorization_code = current_app.config['AUTHORIZATION_CODE']
     if field.data != authorization_code:
         raise ClientException(401)
Пример #4
0
 def get_articles_with_category(cls, category_id):
     if not category_id:
         raise ClientException()
     return cls.query.filter_by(category_id=category_id).all()
Пример #5
0
 def get_or_404(self, ident, description=None):
     rv = self.get(ident)
     if rv is None:
         raise ClientException(code=404, msg=description)
     return rv
Пример #6
0
 def first_or_404(self, description=None):
     rv = self.first()
     if rv is None:
         raise ClientException(code=404, msg=description)
     return rv
Пример #7
0
 def check_password(self, password):
     if not check_password_hash(self.password, password):
         raise ClientException(code=401, msg='密码或用户名错误')