Exemplo n.º 1
0
def post_comment(user_id):
    if 'user_id' in session:
        current_user = get_user(session['user_id'])
        user = get_user(user_id)
        if user:
            if request.method == 'GET':
                form = CommentForm(wall_owner=user, author=current_user)
                return render_template('wall_comment.html', form=form)
            else:
                form = CommentForm.from_request(request,
                                                wall_owner=user,
                                                author=current_user)
                if form.is_valid():
                    form.post_comment()
                    return redirect('/wall/{}'.format(user_id))
                else:
                    return render_template('wall_comment.html', form=form)
        else:
            return render_template('user_not_found.html'), 404
    else:
        return redirect('/login')