Beispiel #1
0
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)
Beispiel #2
0
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))