views.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:tingsmen 作者: pasqu4le 项目源码 文件源码
def submit_post(obj_response, files, form_values):
    form = forms.PostForm(**form_values)
    if form.validate():
        parent_id = None
        if form.parent_id.data:
            parent_id = form.parent_id.data
        post = Post.submit(form.content.data, current_user, parent_id)

        if parent_id:
            render_comment = get_template_attribute('macros.html', 'render_comment')
            obj_response.html_prepend(''.join(['#post-', parent_id, '-comments']),
                                      render_comment(post, current_user).unescape())
            # update parent comments counter
            obj_response.script(''.join(['$("#load_comment_button_', parent_id, '").children(".badge").html(',
                                         str(Post.query.filter_by(parent_id=parent_id).count()), ')']))
        else:
            render_post = get_template_attribute('macros.html', 'render_post')
            obj_response.html_prepend('#post-container', render_post(post, current_user).unescape())
        obj_response.script("$('#collapsable_post_form').collapse('hide');")
        form.reset()
    render_post_form = get_template_attribute('macros.html', 'render_post_form')
    obj_response.html('#collapsable_post_form', render_post_form(form, current_user).unescape())
    # register again the sijax upload plugin
    obj_response.script('sjxUpload.registerForm({"callback": "post_form_upload", "formId": "post_form"});')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号