예제 #1
0
    def _get_posts_by_tag(cls, identifier):
        if not identifier:
            return []
        if not is_numeric(identifier):
            tag = Tag.get_by_name(identifier)
            if not tag:
                return
            identifier = tag.id
        at_ids = cls.query.with_entities(
            cls.post_id).filter(cls.tag_id == identifier).all()

        query = Post.query.filter(Post.id.in_(id for id, in at_ids)).order_by(
            Post.id.desc())
        return query
예제 #2
0
 def get(cls, identifier):
     if is_numeric(identifier):
         return cls.cache.get(identifier)  # get post via title
     return cls.cache.filter(title=identifier).first()
예제 #3
0
 def get(cls, identifier):
     post = cls.objects.filter(title=identifier).first()
     if post:
         return post
     if is_numeric(identifier):
         return cls.objects.get(pk=identifier)
예제 #4
0
 def get(cls, identifier):
     return super().get(identifier) if is_numeric(identifier) \
         else cls.get_by_title(identifier)