Exemplo n.º 1
0
def comment(req):
    r = {
        'err':'invalid'
    }
    if req.get_method() == "POST":
        blog_id = req.get_form_var('bid', '')
        blog = Blog.get(blog_id)
        content = req.get_form_var('content', '').strip()
        single = req.get_form_var('single', '0')
        single = single == '1'
        upload_file = req.get_form_var("update_file", None)
        #print 'j comment', blog_id, content
        if blog and req.user and content:
            filename = ''
            ftype = ''
            if upload_file:
                filename = upload_file.tmp_filename
                ftype = upload_file.content_type
            blog.comment(req.user.id, content, filename, ftype)
            blog = Blog.get(blog.id)
            r = {
                'err':'ok',
                'inner_html': stf("/blog/utils.html", "blog_ui_inline", b=blog, req=req, single=single),
            }
            for t in blog.topics:
                html = str(stf("/blog/utils.html", "blog_ui_inline", b=blog, single=False, req=req))
                data = {
                        'blog_id': blog.id,
                        'inner_html': html
                        }
                publish_channel_msg('me-topic-%s' % t.id, data)
    return json.dumps(r)
Exemplo n.º 2
0
def like(req):
    r = {
        'err':'invalid'
    }
    if req.get_method() == "POST":
        blog_id = req.get_form_var('bid', '')
        single = req.get_form_var('single', '0')
        single = single == '1'
        blog = Blog.get(blog_id)
        if blog and req.user and not blog.is_liked(req.user.id):
            blog.like(req.user.id)
            blog = Blog.get(blog.id)
            r = {
                'err':'ok',
                'inner_html': stf("/blog/utils.html", "blog_ui_inline", b=blog, req=req, single=single),
            }
            for t in blog.topics:
                html = str(stf("/blog/utils.html", "blog_ui_inline", b=blog, single=False, req=req))
                data = {
                        'blog_id': blog.id,
                        'inner_html': html
                        }
                publish_channel_msg('me-topic-%s' % t.id, data)

    return json.dumps(r)