Ejemplo n.º 1
0
def item_del(post_id, item_id):

    post = backend.get_post(post_id)
    item = backend.get_item(item_id)

    if g.user_id != post['author_id'] or item['post_id'] != post_id:
        abort(403)

    backend.set_item(item_id, {'show': False})

    return redirect('/post/%d' % post_id)
Ejemplo n.º 2
0
    def test_get_item(self):
        user = backend.add_user('user02', '*****@*****.**', 'pass02')
        post1 = backend.add_post('title01', user['id'], content='content01')

        item1 = Item(post_id=post1['id'], title='title01', content='content01')

        db.session.add(item1)
        db.session.commit()

        item = backend.get_item(item1.id)
        assert item['title'] == item1.title
Ejemplo n.º 3
0
    def test_get_item(self):
        user = backend.add_user('user02','*****@*****.**','pass02')
        post1 = backend.add_post('title01',user['id'],content='content01')
    
        item1 = Item(post_id=post1['id'],title='title01',content='content01')

        db.session.add(item1)
        db.session.commit()

        item = backend.get_item(item1.id)
        assert item['title'] == item1.title
Ejemplo n.º 4
0
def item_del(post_id, item_id):

    post = backend.get_post(post_id)
    item = backend.get_item(item_id)

    if g.user_id != post["author_id"] or item["post_id"] != post_id:
        abort(403)

    backend.set_item(item_id, {"show": False})

    return redirect("/post/%d" % post_id)
Ejemplo n.º 5
0
def item_edit(post_id, item_id):

    post = backend.get_post(post_id)
    item = backend.get_item(item_id)

    if g.user_id != post["author_id"] or item["post_id"] != post_id:
        abort(403)

    form = ItemForm(**item)
    if form.validate_on_submit():
        title = form.title.data.encode("utf-8")
        author_id = g.user_id
        atype = ""
        content = form.content.data

        try:
            item = backend.set_item(post_id, {"title": title, "content": content})
        except BackendError, ex:
            flash("内容修改失败,请检查重试", "error")
Ejemplo n.º 6
0
def item_edit(post_id, item_id):

    post = backend.get_post(post_id)
    item = backend.get_item(item_id)

    if g.user_id != post['author_id'] or item['post_id'] != post_id:
        abort(403)

    form = ItemForm(**item)
    if form.validate_on_submit():
        title = form.title.data.encode('utf-8')
        author_id = g.user_id
        atype = ''
        content = form.content.data

        try:
            item = backend.set_item(post_id, {
                'title': title,
                'content': content
            })
        except BackendError, ex:
            flash('内容修改失败,请检查重试', 'error')