示例#1
0
    def get(self, nick=None):
        posts = None
        if not nick:
            self.redirect('/posts')
            return

        select_user = '******'
        user = db.get(select_user, nick)
        if user:
            default_size = 10
            summary_length = 200
            need_pagination = False
            size = self.get_query_argument('size', default_size)
            count = Post.count_posts(user.id)
            posts = Post.list(user.id, 0, default_size)
            if posts:
                need_pagination = count > len(posts)
                for post in posts:
                    _html = markdown.markdown(post.content)
                    soup = BeautifulSoup(_html, 'html.parser')
                    img = soup.find('img')
                    if img:
                        img['class'] = 'inner-img-limit'
                    _text = soup.get_text()
                    if _text and len(_text) > summary_length:
                        _text = _text[0:summary_length] + '...'
                    post['cover'] = img
                    post['summary'] = _text
                    post['author'] = user

            self.render('main.html', user=user, posts=posts,
                page_size=size, need_pagination=int(need_pagination))
示例#2
0
    def get(self):
        default_size = 10
        summary_length = 200
        need_pagination = False
        cate_id = self.get_query_argument('cate', None)
        size = self.get_query_argument('size', default_size)
        categories = Category.list(self.current_user.id)
        user_id = self.current_user.id
        if cate_id:
            posts = Post.list_by_category(user_id, int(cate_id), 0, int(size))
            count = Post.count_posts_by_category(user_id, cate_id)
        else:
            count = Post.count_posts(user_id)
            posts = Post.list(user_id, 0, int(size))
        if posts:
            need_pagination = count > len(posts)
            for post in posts:
                _html = markdown.markdown(post.content)
                soup = BeautifulSoup(_html, 'html.parser')
                img = soup.find('img')
                last_modified = post.last_modified
                if img:
                    img['class'] = 'inner-img-limit'
                _text = soup.get_text()
                if _text and len(_text) > summary_length:
                    _text = _text[0:summary_length] + '...'
                post['cover'] = img
                post['summary'] = _text
                post['author'] = self.current_user

        self.render('posts.html', cate_id=cate_id, categories=categories,
            posts=posts, page_size=size, need_pagination=int(need_pagination))
示例#3
0
    def get(self, nick=None):
        posts = None
        if not nick:
            self.redirect('/posts')
            return

        select_user = '******'
        user = db.get(select_user, nick)
        if user:
            default_size = 10
            summary_length = 200
            need_pagination = False
            size = self.get_query_argument('size', default_size)
            count = Post.count_posts(user.id)
            posts = Post.list(user.id, 0, default_size)
            if posts:
                need_pagination = count > len(posts)
                for post in posts:
                    _html = markdown.markdown(post.content)
                    soup = BeautifulSoup(_html, 'html.parser')
                    img = soup.find('img')
                    if img:
                        img['class'] = 'inner-img-limit'
                    _text = soup.get_text()
                    if _text and len(_text) > summary_length:
                        _text = _text[0:summary_length] + '...'
                    post['cover'] = img
                    post['summary'] = _text
                    post['author'] = user

            self.render('main.html',
                        user=user,
                        posts=posts,
                        page_size=size,
                        need_pagination=int(need_pagination))
示例#4
0
    def get(self):
        res = {'data': None}
        need_pagination = False
        summary_length = 260
        offset = self.get_query_argument('offset', 0)
        size = self.get_query_argument('size', 10)
        user_id = self.current_user.id
        count = Post.count_posts(user_id)
        posts = Post.list(user_id, int(offset), int(size))
        if posts:
            need_pagination = count > (int(offset) + int(size))
            for post in posts:
                _html = markdown.markdown(post.content)
                soup = BeautifulSoup(_html, 'html.parser')
                _text = soup.get_text()
                if _text and len(_text) > summary_length:
                    _text = _text[0:summary_length] + '...'
                post['summary'] = _text
                post['author'] = self.current_user

            data = {'posts': posts, 'need_pagination': need_pagination}

            self.send_result(True, data, None)