예제 #1
0
def comment_add(request):
    user = current_user(request)
    form = request.form()
    comment = Comment(form)
    comment.user_id = user.id
    comment.save()
    return redirect('/weibo/index?user_id={}'.format(user.id))
예제 #2
0
def delete_weibo(request):
    """
    通过下面这样的链接来删除一个 todo
    /delete?id=1
    """
    weibo_id = int(request.query.get('id'))
    t = Weibo.delete(weibo_id)
    Comment.remove_by_weiboid(weibo_id)
    return json_response(t.json())
예제 #3
0
def delete_comment(request):
    """
    通过下面这样的链接来删除一个 todo
    /delete?id=1
    """
    comment_id = int(request.query.get('id'))
    c = Comment.delete(comment_id)
    cs = Comment.find_all(weibo_id=c.weibo_id)  # 加载属于该微博的所有comment
    cs_list = [c.json() for c in cs]  # 每一个对象转成dict
    return json_response(cs_list)
예제 #4
0
def comment_add(request):
    uname = current_user(request)
    user = User.find_by(username=uname)
    if user is None:
        return redirect('/login')
    form = request.form()
    c = Comment(form)
    c.user_id = user.id
    c.save()
    return redirect('/weibo')
예제 #5
0
def comment_add(request):
    uid = current_user_id(request)
    form = request.form()
    weibo_id = form.get('weibo_id', -1)
    new_form = {
        'weibo_id': weibo_id,
        'user_id': uid,
    }
    form.update(new_form)
    comment = Comment(form)
    Comment.add(comment)
    return redirect(f'/weibo/index?user_id={str(uid)}')
예제 #6
0
def add_comment(request):
    """
    接受浏览器发过来的添加 todo 请求
    添加数据并返回给浏览器
    """
    # 得到浏览器发送的 json 格式数据
    # 浏览器用 ajax 发送 json 格式的数据过来
    # 所以这里我们用新增加的 json 函数来获取格式化后的 json 数据
    form = request.json()  # 字符串格式转化成dict
    c = Comment.new(form)
    cs = Comment.find_all(weibo_id=c.weibo_id)  # 加载属于该微博的所有comment
    cs_list = [c.json() for c in cs]  # 每一个对象转成dict
    return json_response(cs_list)
예제 #7
0
def comment_add(request):
    headers = {
        'Content-Type': 'text/html',
    }
    uid = current_user(request)
    header = response_with_headers(headers)
    user = User.find(uid)
    # 创建微博
    form = request.form()
    w = Comment(form)
    w.user_id = user.id
    w.save()
    return redirect('/weibo/index?user_id={}'.format(user.id))
예제 #8
0
def add_comment(request):

    form = request.json()
    # 创建一个 model
    c = Comment.new(form)
    # 把创建好的 model 返回给浏览器
    return json_response(c.json())
예제 #9
0
def delete_comment(request):
    """
    通过下面这样的链接来删除一个 comment
    /delete?id=1
    """
    comment_id = int(request.query.get('id'))
    w = Comment.delete(comment_id)
    return json_response(w.json())
예제 #10
0
def delete_comment(request):
    """
    通过下面这样的链接来删除一个 todo
    /delete?id=1
    """
    id = int(request.query.get('id'))
    t = Comment.delete(id)
    return json_response(t.json())
예제 #11
0
def add_comment(request):
    """
    接受浏览器发过来的添加 comment 请求
    添加数据并返回给浏览器
    """
    form = request.json()
    # 创建一个 model
    m = Comment.new(form)
    # 把创建好的 model 返回给浏览器
    return json_response(m.json())
예제 #12
0
def delete_comment(request):
    """
    通过下面这样的链接来删除一个 comment
    先不考虑权限认证的问题
    /delete?id=1
    """
    comment_id = int(request.query.get('id'))
    t = Comment.delete(comment_id)
    return json_response(t.json())
    pass
예제 #13
0
def delete_weibo(request):
    """
    通过下面这样的链接来删除一个 weibo及其comments
    /delete?id=1
    """
    weibo_id = int(request.query.get('id'))
    w = Weibo.delete(weibo_id)  # 删除这个weibo
    cs = w.comments()
    for c in cs:
        cdel = Comment.delete(c.id)  # 删除这个weibo关联的所有commnets
    return json_response(w.json())
예제 #14
0
def comment_add():
    u = current_user()
    if u is not None:
        # log('comment_add', u.id, u.username)
        form = request.form
        c = Comment(form)
        c.user_id = u.id
        c.username = u.username
        c.weibo_id = int(form.get('weibo_id', -1))
        if c.valid_add():
            c.save()
        return redirect(url_for('.index', username=u.username))
    else:
        abort(401)
예제 #15
0
def add_comment(request):
    """
    接受浏览器发过来的添加 weibo 请求
    添加数据并返回给浏览器
    """
    log('add')
    form = request.json()
    # 创建一个 model
    c = Comment.new(form)
    # 把创建好的 model 返回给浏览器
    log('return comment:', c.json())
    log('***********', c)
    return json_response(c.json())
예제 #16
0
def add_comment(request):
    """
    接受浏览器发过来的添加 comment 请求
    添加数据并返回给浏览器
    """
    # 得到浏览器发送的表单, 浏览器用 ajax 发送 json 格式的数据过来
    # 所以这里我们用新增加的 json 函数来获取格式化后的 json 数据
    form = request.json()
    print('api add comment form', form)
    # 创建一个 comment
    c = Comment.new(form)
    # 把创建好的 weibo 返回给浏览器
    return json_response(c.json())
예제 #17
0
def add_comment(request):
    """
    接受浏览器发过来的添加 comment 请求
    添加数据并返回给浏览器
    """
    # 将获得的请求转换为 json 格式的字符串
    form = request.json()
    log('add_comnent form: ', form)
    # 创建一个 model
    m = Comment.new(form)
    log('m: ', m)
    # 把创建好的 model 返回给浏览器
    log('add_weibo json_response(m.json()): ', json_response(m.json()))
    return json_response(m.json())
예제 #18
0
def comment():
    form = request.form
    u = current_user()
    c = Comment(form)
    print('request comment', c.comment)
    c.name = u.username
    if c.valid():
        c.save()
    return redirect(url_for('.index'))
예제 #19
0
def add_comment(request):
    # 添加评论
    """
    接受浏览器发过来的添加 comment 请求
    添加数据并返回给浏览器
    """
    log('路由到了添加评论({})'.format(request))
    form = request.json()
    log('接收到的前端的数据', form)
    # 创建一个 model
    m = Comment.new(form)
    log('创建的评论对象', m)
    # 把创建好的 model 返回给浏览器
    return json_response(m.json())
    pass
예제 #20
0
def comment_weibo(request):
    form = request.json()
    # wid = int(form.get('id'))
    cmt = Comment.new(form)
    return json_response(cmt.json())
예제 #21
0
def comment_add(user):
    form = request.form
    c = Comment(form)
    status, data, msg = c.save_comment(user)
    return api_response(status, data, msg)
예제 #22
0
def commentShow():
    w_id = request.form.get('weibo_id', None)
    user = current_user()
    status, data, msg = Comment.show_comments(w_id, user)
    return api_response(status, data, msg)
예제 #23
0
def comment_delete_weibo(request):
    cmt_id = int(request.query.get('id'))
    # print('cmt_id', cmt_id)
    cmt = Comment.delete(cmt_id)
    return json_response(cmt.json())
예제 #24
0
def delete_comment(request):
    comment_id = int(request.query.get('id'))
    c = Comment.delete(comment_id)
    return json_response(c.json())
예제 #25
0
def remove_comment(request):
    comment_id = int(request.query.get('id'))
    comment = Comment.remove(comment_id)
    return json_response(comment.json())
예제 #26
0
def add_comment(request):
    form = request.json()
    comment = Comment.new(form)
    return json_response(comment.json())