Пример #1
0
def delete(request):
    user = current_user(request)
    # 删除评论
    comment_id = int(request.query.get('id', -1))
    c = Comment.find(comment_id)
    t = Tweet.find(c.tweet_id)
    uid = t.user_id
    if user.id == t.user_id:
        Comment.delete(comment_id)
    return redirect('/tweet/index?user_id={}'.format(uid))
Пример #2
0
def add(request):
    user = current_user(request)
    # 创建评论
    form = request.form()
    c = Comment(form)
    c.user_id = user.id
    c.save()
    log('comment add', c, c.tweet_id)
    t = Tweet.find(c.tweet_id)
    u = User.find(t.user_id)
    return redirect('/tweet/index?user_id={}'.format(u.id))
Пример #3
0
def delete(request):
    headers = {
        'Content-Type': 'text/html',
    }
    uid = current_user(request)
    header = response_with_headers(headers)
    user = User.find(uid)
    # 删除微博
    weibo_id = request.query.get('id', None)
    weibo_id = int(weibo_id)
    w = Tweet.find(weibo_id)
    w.delete()
    return redirect('/tweet?user_id={}'.format(user.id))
Пример #4
0
def update(request):
    username = current_user(request)
    user = User.find_by(username=username)
    form = request.form()
    content = form.get('content', '')
    weibo_id = int(form.get('id', -1))
    w = Tweet.find(weibo_id)
    if user.id != w.user_id:
        return error(request)
    w.content = content
    w.save()
    # 重定向到用户的主页
    return redirect('/tweet?user_id={}'.format(user.id))
Пример #5
0
def edit(request):
    headers = {
        'Content-Type': 'text/html',
    }
    header = response_with_headers(headers)
    weibo_id = request.query.get('id', -1)
    weibo_id = int(weibo_id)
    w = Tweet.find(weibo_id)
    if w is None:
        return error(request)
    # 生成一个 edit 页面
    body = template('weibo_edit.html', weibo_id=w.id, weibo_content=w.content)
    r = header + '\r\n' + body
    return r.encode(encoding='utf-8')