コード例 #1
0
ファイル: routes_tweet.py プロジェクト: KiwiShow/PythonWeb
def delike(tweet_id):
    user = current_user()
    t = Tweet.find(tweet_id)
    if Tweet.check_token():
        t.delike(user.id)
        user.delike_tweet(tweet_id)
        return redirect(
            url_for('.detail', tweet_id=tweet_id, token=gg.token[user.id]))
コード例 #2
0
 def wrapper(rq):
     tweet_id = int(rq.query.get('id', -1))
     t = Tweet.find(tweet_id)
     user = current_user(rq)
     if t is not None and t.user_id == user.id:
         response_msg = route_func(rq)
     else:
         response_msg = redirect('/login')
     return response_msg
コード例 #3
0
ファイル: routes_tweet.py プロジェクト: KiwiShow/PythonWeb
def edit(tweet_id):
    user = current_user()
    if Tweet.check_token():
        # tweet_id = int(request.args.get('id', -1))
        t = Tweet.find(tweet_id)
        Tweet.check_id(id=tweet_id)
        return render_template('tweet/tweet_edit.html',
                               t=t,
                               token=gg.token[user.id],
                               user=user)
コード例 #4
0
def edit(request):
    u = current_user(request)
    tweet_id = int(request.query.get('id', -1))
    t = Tweet.find(tweet_id)
    if u.id == t.user_id:
        body = template('tweet_edit.html',
                        tweet_id=t.id,
                        tweet_content=t.content)
        return http_response(body)
    return redirect('/tweet/index?user_id={}'.format(u.id))
コード例 #5
0
def delete(request):
    u = current_user(request)
    tweet_id = int(request.query.get('id'))
    t = Tweet.find(tweet_id)
    if u.id == t.user_id:
        # 这里只是删除了tweet,但是其所拥有的comment的deleted字段变成False
        t.remove(tweet_id)
        for c in t.comments():
            c.deleted = True
            c.save()
    # redirect有必要加query吗
    return redirect('/tweet/index?user_id={}'.format(u.id))
コード例 #6
0
def edit(tweet_id):
    u = current_user()
    token = request.args.get('token')
    if Tweet.check_token(token, gg.csrf_tokens):
        # tweet_id = int(request.args.get('id', -1))
        t = Tweet.find(tweet_id)
        if u.id == t.user_id:
            body = render_template('tweet_edit.html',
                                   tweet_id=t.id,
                                   tweet_content=t.content,
                                   token=token)
            return make_response(body)
        return redirect(url_for('.index'))
コード例 #7
0
def delete(tweet_id):
    u = current_user()
    # tweet_id = int(request.args.get('id'))
    token = request.args.get('token')
    if Tweet.check_token(token, gg.csrf_tokens):
        # gg.delete_value()
        # csrf_tokens.pop(token)
        t = Tweet.find(tweet_id)
        if u.id == t.user_id:
            # 这里只是删除了tweet,但是其所拥有的comment的deleted字段变成False
            t.remove(tweet_id)
            for c in t.comments():
                c.deleted = True
                c.save()
        # redirect有必要加query吗
        # return redirect('/tweet/index?user_id={}'.format(u.id))
        return redirect(url_for('.index'))
コード例 #8
0
ファイル: routes_tweet.py プロジェクト: KiwiShow/PythonWeb
def delete(tweet_id):
    if Tweet.check_token():
        t = Tweet.find(tweet_id)
        Tweet.check_id(id=tweet_id)
        t.remove_with_comments(tweet_id)
        return redirect(url_for('.index'))
コード例 #9
0
def delete(rq):
    tweet_id = int(rq.query.get('id', -1))
    t = Tweet.find(tweet_id)
    t.remove()
    return redirect('/tweet')
コード例 #10
0
def update(rq):
    tweet_id = int(rq.query.get('id', -1))
    t = Tweet.find(tweet_id)
    d = rq.form()
    t.update(d)
    return redirect('/tweet')
コード例 #11
0
def edit(rq):
    tweet_id = int(rq.query.get('id', -1))
    t = Tweet.find(tweet_id)
    body = template(env, 'edit.html', tweet=t)
    response_msg = make_response_msg(body=body)
    return response_msg