def get_claim_by_name(self, claim_name): q = self.default_query(AppClaim) q = q.filter(AppClaim.claim_name == claim_name) result = q.one_or_none() if result is None: raise HttpNotFoundException(message='Claim does not exist') return result
def get_role_by_name(self, role_name): q = self.default_query(AppRole) q = q.filter(AppRole.role_name == role_name) result = q.one_or_none() if result is None: raise HttpNotFoundException(message='Role does not exist') return result
def get_article_comment_by_id(self, article_comment_id): q = self.default_query(ArticleComment) q = q.filter(ArticleComment.article_comment_id == article_comment_id) result = q.one_or_none() if result is None: raise HttpNotFoundException(message='ArticleComment does not exist') return result
def get_article_group(self, article_group_id): self.object_exists_or_404( ArticleGroup.article_group_id == article_group_id, ArticleGroup, article_group_id) q = self.default_query(ArticleGroup).filter( ArticleGroup.article_group_id == article_group_id) q = q.filter(ArticleGroup.is_deleted == False) result = q.one_or_none() if result is None: raise HttpNotFoundException(message='Article group does not exist') return result
def get_tag(self, tag_id=None): if tag_id is not None: self.object_exists_or_404(Tag.tag_id == tag_id, Tag, tag_id) q = self.default_query(Tag) if tag_id is not None: q = q.filter(Tag.tag_id == tag_id) if tag_id is not None: result = q.one_or_none() else: result = q.all() if result is None: raise HttpNotFoundException(message='Tag does not exist') return result
def get_article(self, article_id=None): if article_id is not None: self.object_exists_or_404(Article.article_id == article_id, Article, article_id) q = self.default_query(Article) if article_id is not None: q = q.filter(Article.article_id == article_id) q = q.filter(Article.is_deleted == False) if article_id is not None: result = q.one_or_none() else: result = q.all() if result is None: raise HttpNotFoundException(message='Article does not exist') return result
def object_exists_or_404(self, exists_criteria, db_class=None, object_id=None): if not self.object_exists(exists_criteria): if db_class is not None and object_id is not None: raise HttpNotFoundException(message='{} ID {} does not exist'.format(db_class.__name__, object_id)) else: raise HttpNotFoundException(message='Requested object does not exist')
def get_single_object_or_404(self, query_object, db_class, object_id): try: data = query_object.one() return data except (NoResultFound, MultipleResultsFound): raise HttpNotFoundException(message='{} ID {} does not exist'.format(db_class.__name__, object_id))