Exemple #1
0
def submit_post(request):
    if request.is_ajax():
        if request.user.is_authenticated():
            form = PostForm(request.POST)
        else:
            form = AnonymousPostForm(request.POST)

        if form.is_valid():
            post = form.save(commit=False)
            if request.user.is_authenticated():
                post.user = request.user
            post.is_spam = spam.is_spam(request, post.missed_opportunity, post.get_username())
            post.save()

            if post.is_spam:
                return json_http.render_to_json_response('spam.html', {'is_post': True})

            return json_http.render_to_json_response('posts/post.html', 
                                                    {'post': post, 'comment_form': CommentForm()}, 
                                                    context_instance=RequestContext(request))
        

        return json_http.render_to_json_response('form.html', 
                {'form': form}, 
                status="failure", 
                context_instance=RequestContext(request))
    else:
        return HttpResponse(status=400)
Exemple #2
0
def submit_feedback(request):
    if request.method == 'GET':
        return render_to_response('feedback/feedback_form.html', 
            {'form': FeedbackForm()},
            context_instance=RequestContext(request))

    elif request.method == 'POST':
        form = FeedbackForm(request.POST)

        if form.is_valid():
            feedback = form.save(commit=False)
            feedback.is_spam = spam.is_spam(request, feedback.name, feedback.comment)
            feedback.save()
            return render_to_response('feedback/feedback_success.html',context_instance=RequestContext(request))

        return render_to_response('feedback/feedback_form.html',
                {'form':form},
                context_instance=RequestContext(request))
Exemple #3
0
def add_comment(request, post_id):
    if request.is_ajax():
        if request.user.is_authenticated():
            form = CommentForm(request.POST)
        else:
            form = AnonymousCommentForm(request.POST)

        if form.is_valid():
            post = get_object_or_404(Post, pk=int(post_id))
            comment = form.save(commit=False)
            comment.post = post
            if request.user.is_authenticated():
                comment.user = request.user
            comment.is_spam =  spam.is_spam(request, comment.comment, comment.get_username())
            comment.save()
            if comment.is_spam:
                return json_http.render_to_json_response('spam.html', {'is_post': False})
            
            return json_http.render_to_json_response('posts/comment.html', {'comment': comment}, context_instance=RequestContext(request))
        else:
            return json_http.render_to_json_response('form.html', {'form': form}, status="failure", context_instance=RequestContext(request))
    else:
        return HttpResponse(status=400)