コード例 #1
0
ファイル: views.py プロジェクト: becomingGuru/bb
def post(req,post_id):
    
    
    is_ajax = req.GET.has_key('xhr')
    
    post = Post.objects.get(pk=post_id)

    if req.method == 'POST':
        comment_form = CommentForm(req.POST)
        comment = comment_form.save(commit=False)
        comment.post = post
        comment.save()
        
    payload = {'post':post,
               'comments':Comment.objects.filter(post__id=post_id),
               'comment_form':CommentForm()}
                              
    return render_to_response('post.html',payload, RequestContext(req))    

    
コード例 #2
0
def comment(request, article_id):
    if request.method == "POST":
        if request.POST['verify_message'].strip() == "sleepycat.org":
            f = CommentForm(request.POST)
            
            if f.is_valid():
                cmt = f.save(commit=False)
                
                cmt.ip = get_client_ip(request)
                cmt.datetime = datetime.datetime.now()
                cmt.to_article = Article.objects.get(id=article_id)
                
                if request.POST['to_comment_id'] != "":
                    cmt.to_comment = Comment.objects.get(id=request.POST['to_comment_id'])
                
                cmt.save()
                
                return HttpResponseRedirect('/blog/%s' % article_id)
            else:
                articles = Article.objects.order_by('datetime').reverse()
                tags     = Tag.objects.order_by('weight')
                
                tag_articles = {}
                for tag in tags:
                    tag_articles[tag.title] = 0
                
                for a in articles:
                    for tag in a.tags.all():
                        tag_articles[tag.title] += 1
                
                for tag in tags:
                    tag.articles = tag_articles[tag.title]
                
                context  = {
                            'tags': tags,
                            'recentcmts': Comment.objects.order_by('datetime').reverse()[:3], 
                            'f': f,
                            }
                
                return render(request, 'blog/error.html', context)
        #not "sleepycat.org"
        else:
            errmsg = u"Verification Message Error. Please Input: sleepycat.org"
            
            articles = Article.objects.order_by('datetime').reverse()
            tags     = Tag.objects.order_by('weight')
            
            tag_articles = {}
            for tag in tags:
                tag_articles[tag.title] = 0
            
            for a in articles:
                for tag in a.tags.all():
                    tag_articles[tag.title] += 1
            
            for tag in tags:
                tag.articles = tag_articles[tag.title]
            
            context  = {
                        'tags': tags,
                        'recentcmts': Comment.objects.order_by('datetime').reverse()[:3], 
                        'errmsg': errmsg,
                        }
            
            return render(request, 'blog/error.html', context)
    
    #not POST
    else:
        return HttpResponseRedirect('/blog/%s' % article_id)