示例#1
0
def submit_comment(request):
    if request.is_ajax():
        result = {}
        form = CommentForm(dict(user=request.user.id, post = request.POST['post'], content=request.POST['content'])) #We use a ModelForm for validation
        if form.is_valid():
            post = form.cleaned_data['post']
            content = form.cleaned_data['content']
            new_comment = Comment(user = request.user, post = post, content = content)
            new_comment.save()

            result['status'] = 'OK'
            result['comment'] = '<b>%s: </b>%s <span class="post-end"> | 3 seconds ago </span>' % (request.user.username, content)
            
            to_user_list = [post.user]
            for comment in post.comment_set.all():
                if comment.user not in to_user_list:
                    to_user_list.append(comment.user)
            
            to_user_list.remove(request.user)
            
            
            message_to_post(request.user, to_user_list, action = 'comment', content=None, page_link = post.activity_page.url_code)
            
        else:
            result['status'] = 'invalid'
    
        return HttpResponse(simplejson.dumps(result))
    else:
        return HttpResponse(simplejson.dumps({'status':'invalid request'}))
示例#2
0
def send_message_to_post(request):
    if request.is_ajax:
        form = SendMessageForm(request.POST)
        if form.is_valid():
            post = Post.objects.select_related().get(pk = form.cleaned_data['post_id'])
            if post.activity_page.show_email:
                message_to_post(request.user, [post.user], content = form.cleaned_data['post_message'])
                return HttpResponse(simplejson.dumps({'status':'OK'}))
            else:
                return HttpResponse(simplejson.dumps({'status':"this page doesn't support message feature"}))
        else:
            return HttpResponse(simplejson.dumps({'status':'the message is invalid'}))
    return HttpResponse(simplejson.dumps({'status':'invalid request'}))