Exemple #1
0
    def get(self):
        post_id = self.request.get('post_id')

        if not self.user or not post_id:
            self.redirect('/blog/%s' % post_id)
        post = Post.by_id(post_id)

        if post and post.created_by == self.user.key().id():
            Post.delete(post_id)

        self.redirect('/blog')
Exemple #2
0
    def get(self):
        post_id = self.request.get('post_id')
        
        if not self.user or not post_id:
            self.redirect('/blog/%s' % post_id)
        post = Post.by_id(post_id)
        
        if post and post.created_by == self.user.key().id():
            Post.delete(post_id)

        self.redirect('/blog')
Exemple #3
0
def post(id=None):
    if request.method == 'POST':
        setting = request.form.get('setting')
        post_id = request.form.get('value_0')
        value = request.form.get('value_1')

        if not setting or not post_id:
            abort(400)
        try:
            post_id = int(post_id)
        except:
            abort(400)

        post = Post(post_id=post_id)

        if not post.id:
            abort(400)

        if setting == 'delete':
            post.delete()
            flash(messages.post_deleted)

            if request.form.get('next'):
                return redirect(request.form['next'])
            return redirect(url_for('admin_post'))

        elif setting == 'public':
            if not value:
                abort(400)

            if value == 'True':
                post.set_public()
                flash(messages.post_marked_public)
            else:
                post.update('is_public', False)
                flash(messages.post_marked_private)

        return redirect(url_for('admin_post_id', id=post_id))

    else:
        if id:
            post = Post(post_id=id)
            post = post.get_post()

            if not post:
                flash(messages.post_not_found)
        else:
            post = None

        return render_template('admin/post.html', post=post)
Exemple #4
0
def delete(post_id):
    Post.delete(post_id)
    return redirect(url_for('list_posts'))
Exemple #5
0
def del_post(args):
    Post.delete(args.postid)
Exemple #6
0
    def handle_procedure(self, token, procedure_number, data):
        procedure = procedures[procedure_number]
        posts = sessions[token].get_posts()
        result = None

        if token == admin_token:
            if procedure not in (Post.list, Post.read):
                self.send_msg('Invalid procedure number')
                return None

        if procedure == Post.list:
            result = b'Notice-%d|%s|%s\n' % (notice_post.idx, str(now).encode(), str(now).encode())
            result += Post.list(posts)
        elif procedure == Post.write:
            if len(posts) >= 5:
                self.send_msg('Excess in the maximum number of posts')
                return None

            type_ = data[0]
            content = data[1:]
            if not Post.is_valid_type(data[0]):
                self.send_msg('Invalid post type: %r' % type_)
                return None

            post = Post.write(token, type_, len(posts) + 2, content)
            if post is None:
                self.send_msg('Timeout to fetch %r' % content)
                return None

            sessions[token].add_post(post)
            result = b'created'
        elif procedure == Post.read:
            idx = data[0]
            if idx == 0:
                result = notice_post.content
            else:
                result = Post.read(posts, idx)
        elif procedure == Post.update:
            idx = data[0]
            type_ = data[1]
            content = data[2:]
            if not Post.is_valid_type(data[1]):
                self.send_msg('Invalid post type: %r' % type_)
                return None

            post = Post.update(posts, idx, type_, content)
            if post is None:
                self.send_msg('Not found post matches with idx:%r/type:%r' % (idx, type_))
                return None
            result = b'updated'
        elif procedure == Post.delete:
            idx = data[0]
            is_deleted = Post.delete(posts, idx)
            if not is_deleted:
                self.send_msg('Not found post matches with idx:%r' % idx)
                return None
            result = b'deleted'
        elif procedure == get_admin_token:
            result = get_admin_token(data)
            if result is None:
                self.send_msg('Failed to get admin token. The message must satisfy MAC=%s' %
                              hexlify(challenge_mac).decode())
        return result