def route_comment_add(request):
    form = request.form()
    c = Comment(form)
    c.save()
    w = Weibo.find(c.weibo_id)
    # 重定向到用户的主页
    return redirect('/weibo?user_id={}'.format(w.user_id))
Beispiel #2
0
def route_comment_add(request):
    form = request.form()
    c = Comment(form)
    log('commentAdd c', c)
    c.save()
    w = Weibo.find(c.weibo_id)
    return redirect('/weibo?user_id={}'.format(w.user_id))
Beispiel #3
0
def route_comment_add(request):
    # username = current_user(request)
    # user = User.find_by(username=username)
    form = request.form()
    c = Comment(form)
    c.save()
    w = Weibo.find(c.weibo_id)
    # 重定向到用户的主页
    return redirect('/weibo?user_id={}'.format(w.user_id))
def route_weibo_delete(request):
    username = current_user(request)
    user = User.find_by(username=username)
    # 删除微博
    weibo_id = request.query.get('id', None)
    weibo_id = int(weibo_id)
    w = Weibo.find(weibo_id)
    if w.user_id == user.id:
        w.delete()
        return redirect('/weibo?user_id={}'.format(user.id))
    else:
        return error(request)
Beispiel #5
0
def route_weibo_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 = Weibo.find(weibo_id)
    if user.id != w.user_id:
        return error(request)
    w.content = content
    w.save()
    return redirect('/weibo?user_id={}'.format(user.id))
Beispiel #6
0
def route_weibo_delete(request):
    headers = {
        'Content-Type': 'text/html',
    }
    username = current_user(request)
    header = response_with_headers(headers)
    user = User.find_by(username=username)
    # 删除微博
    weibo_id = request.query.get('id', None)
    weibo_id = int(weibo_id)
    w = Weibo.find(weibo_id)
    w.delete()
    return redirect('/weibo?user_id={}'.format(user.id))
Beispiel #7
0
def route_weibo_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 = Weibo.find(weibo_id)
    if user.id != w.user_id:
        return error(request)
    w.content = content
    w.save()
    # 重定向到用户的主页
    return redirect('/weibo?user_id={}'.format(user.id))
Beispiel #8
0
def route_weibo_delete(request):
    # headers = {
    #     'Content-Type': 'text/html',
    # }
    username = current_user(request)
    # header = response_with_header(headers)
    user = User.find_by(username=username)
    # 删除微博
    weibo_id = request.query.get('id', None)
    weibo_id = int(weibo_id)
    w = Weibo.find(weibo_id)
    w.delete()
    return redirect('/weibo?user_id={}'.format(user.id))
Beispiel #9
0
def route_weibo_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 = Weibo.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')
Beispiel #10
0
def route_weibo_edit(request):
    headers = {
        'Content-Type': 'text/html',
    }
    header = response_with_header(headers)
    # 这个 query.get 是在 weibo_index路由 里面放上去的
    # 用来指定要修改那一条微博
    weibo_id = request.query.get('id', -1)
    weibo_id = int(weibo_id)
    w = Weibo.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')