Esempio n. 1
0
    def get(self):
        default_size = 10
        summary_length = 200
        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:
            drafts = Post.drafts_by_category(user_id, int(cate_id), 0, int(size))
            count = Post.count_drafts_by_category(user_id, cate_id)
        else:
            drafts = Post.drafts(user_id, 0, int(size))
            count = Post.count_drafts(user_id)
        for draft in drafts:
            draft['author'] = self.current_user
            _html = markdown.markdown(draft.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] + '...'
            draft['cover'] = img
            draft['summary'] = _text

        self.render('drafts.html', cate_id=cate_id, categories=categories, drafts=drafts)