Example #1
0
    def get(self):
        page = int(self.get_argument('page', '1'))
        key = self.get_argument('key', '')
        act = self.get_argument('act', '')
        if act == 'delete':
            Post.delete_post_by_id(int(self.get_argument('id', 0)))
        pagesize = 20
        count, blogs = Post.get_post(page=page, pagesize=pagesize, showall=True, keyword=key, onlypost=False)

        for x in blogs:
            x.length = len(x.content)
        self.datamap['count'] = count
        self.datamap['posts'] = blogs
        self.datamap['page'] = int(page)
        self.datamap['pagecount'] = int(math.ceil(float(count) / pagesize))
        self.write(render_admin.post(self.datamap))
Example #2
0
    def get(self, postId):
        post = None

        act = self.get_argument('act', '')
        if act == 'del_comment' and self.islogin:
            cid = self.get_argument('cid', 0)
            Comment.delete_comment_by_id(cid)

            self.add_header('content-type', 'application/json;charset=utf-8')
            self.write(json.dumps({'code': 0, 'msg': 'OK'}))
            return

        if isint(postId):
            post = Post.get_post_by_id(postId, ignorestatus=True)
        else:
            post = Post.get_post_by_alias(postId, ignorestatus=True)

        if not post or post.status != 0:
            self.set_error(404)
        act = self.get_argument('act', '')
        if act == 'clear':
            self.set_secure_cookie('post_' + str(postId), '', expires_days=-10)
        self.datamap['valid'] = True
        if post.password.strip() != "":
            if self.get_secure_cookie('post_' + str(postId)) != post.password:
                self.datamap['valid'] = False
        if act and self.islogin:
            if act == 'delete':
                Post.delete_post_by_id(postId)
                self.redirect('/')
                return
            elif act == 'edit':
                self.redirect('/admin/?url=/admin/post/edit/%s/' % post.id)
                return
        self.datamap['post'] = post
        self.datamap['recent'] = Post.get_recent_post()
        comment = Comment.get_comments_by_postid(post.id, isAdmin=self.islogin)
        self.datamap['commentcount'] = comment[0]
        self.datamap['comments'] = comment[1]
        if self.islogin:
            self.datamap['curr_user_info'] = self.get_current_user_info
        self.write(render.post(self.datamap))