当前位置: 首页>>代码示例>>Python>>正文


Python Comment.blog方法代码示例

本文整理汇总了Python中models.Comment.blog方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.blog方法的具体用法?Python Comment.blog怎么用?Python Comment.blog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Comment的用法示例。


在下文中一共展示了Comment.blog方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: comment_add

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import blog [as 别名]
def comment_add():
    log('发送评论')
    user_now = current_user()
    form = request.get_json()
    print('form, ', form)
    c = Comment(form)
    blog_id = form.get('blog_id', '')
    # 设置是谁发的
    c.sender_name = user_now.username
    c.blog = Blog.query.filter_by(id=blog_id).first()
    # 保存到数据库
    c.save()
    blog = c.blog
    blog.com_count = len(Comment.query.filter_by(blog_id=blog.id).all())
    blog.save()
    log('写评论')
    status = {
        'content': c.content,
        'sender_name': c.sender_name,
        'created_time': formatted_time(c.created_time),
        'id': c.id,
    }
    r = json.dumps(status, ensure_ascii=False)
    print('r, ', r)
    return r
开发者ID:Maluscore,项目名称:tweet_js,代码行数:27,代码来源:app.py

示例2: save_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import blog [as 别名]
def save_comment(request):
    """保存评论"""
    article_id = request.POST.get("article_id", "").strip()
    try:
        _int_article_id = int(article_id)
    except Exception:
        return HttpResponseRedirect("/")

    username = request.POST.get("username", "").strip()
    content = request.POST.get("content", "").strip()
    if len(username) < 4 or len(content) < 4:
        return HttpResponseRedirect("/")

    comment = Comment()

    comment.blog = Blog.objects.get(id=_int_article_id)
    comment.blog.comment_times += 1
    comment.blog.save()

    comment.submit_name = username
    comment.content = content
    comment.ip = gcommon.get_remote_addr(request)  # request.META['REMOTE_ADDR']
    comment.save()

    return HttpResponseRedirect("/blog/%d.html" % _int_article_id)
开发者ID:xeon2007,项目名称:mycode,代码行数:27,代码来源:views.py

示例3: comment_add

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import blog [as 别名]
def comment_add(blog_id):
    user_now = current_user()
    c = Comment(request.form)
    # 设置是谁发的
    c.sender_name = user_now.username
    c.blog = Blog.query.filter_by(id=blog_id).first()
    # 保存到数据库
    c.save()
    blog = c.blog
    blog.com_count = len(Comment.query.filter_by(blog_id=blog.id).all())
    blog.save()
    log('写评论')
    return redirect(url_for('blog_view', blog_id=blog_id))
开发者ID:Maluscore,项目名称:tweet,代码行数:15,代码来源:app.py

示例4: blog

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import blog [as 别名]
def blog(request, blogid):
    try:
        article = Blog.objects.get(id=blogid)
        article.visit_times += 1
        article.save()
    except Blog.DoesNotExist:
        return HttpResponseRedirect('/')
    
    page = request.GET.get('page', '1')
    try:
        page_num = int(page)
    except:
        page_num = 1
    
    qs = article.comment_set.all().order_by('id')
    
    html_dict = {'article': article,}
    db_tools.get_category_latelyblogs(html_dict)

    #分页
    PAGE_MSG_NUM = 10
    split_dict = gcommon.split_page(request, page_num, PAGE_MSG_NUM, qs)
    html_dict.update(split_dict)

    username = request.POST.get('username', '').strip()
    content = request.POST.get('content', '').strip()
    if not username and not content:
        return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
        
    if len(username) < 4 or len(content) < 4:
        html_dict['remind_msg'] = u'名称和内容不能少于4个字符'
        return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
    
    comment = Comment()
    comment.blog = Blog.objects.get(id=blogid)
    comment.blog.comment_times += 1
    comment.blog.save()
    comment.submit_name = username
    comment.content = content
    comment.ip = gcommon.get_remote_addr(request) #request.META['REMOTE_ADDR']
    comment.save()

    return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
开发者ID:lvshuchengyin,项目名称:mycode,代码行数:45,代码来源:views.py

示例5: createComment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import blog [as 别名]
def createComment(request, blog_key):
    if not current_user():
        return HttpResponseRedirect(users.create_login_url('/blogs'))
    form = CommentForm(request.POST)
    if form.is_valid():
        comment = Comment()
        comment.blog = Blog.get(blog_key)
        comment.author = current_user()
        comment.content = form.cleaned_data['content']
        comment.put()
        context = Context({
            'blog':comment.blog,
            'comment':comment,
            'admin':admin(),
        })
        template = loader.get_template('blogs/_comment.html')
        return HttpResponse(template.render(context))
    else:
        return HttpResponse('')
开发者ID:qubic,项目名称:myblogongae,代码行数:21,代码来源:views.py

示例6: createComment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import blog [as 别名]
def createComment(request, blog_key):
    form = CommentForm(request.POST)
    if form.is_valid():
        comment = Comment()
        comment.blog = Blog.get(blog_key)
        comment.author = form.cleaned_data["author"]
        comment.email = form.cleaned_data["email"]
        comment.content = form.cleaned_data["content"]
        comment.put()
        context = Context({"blog": comment.blog, "comment": comment, "admin": admin()})
        template = loader.get_template("blogs/_comment.html")
        reponse = dict(msg=1, data=template.render(context))
        return HttpResponse(json.dumps(reponse), mimetype="application/json")
    else:
        data = ""
        for errItem in form.errors.items():
            errTitle = str(errItem[0])
            errContent = errItem[1].as_text()
            if data == "":
                data = "<div>" + errTitle + ":" + errContent + "</div>"
            else:
                data = "\n<div>" + errTitle + ":" + errContent + "</div>"
        reponse = dict(msg=0, data=data)
        return HttpResponse(json.dumps(reponse), mimetype="application/json")
开发者ID:proming,项目名称:myblogongae,代码行数:26,代码来源:views.py


注:本文中的models.Comment.blog方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。