def create_comment_and_status_notification(request, pk):
    # Get the status that has been commented on
    status = Status.objects.get(pk=pk)

    # Create the new comment and save it to the database
    users_comment = request.POST.get('comment')
    author = request.user
    author_profile = UserProfile.objects.get(user=request.user)

    comment = Comment(
        comment = users_comment,
        author = author,
        author_profile = author_profile,
    )
    comment.save()

    # Add the comment to the status
    status.comment.add(comment)

    # Send a notification to the status owner to tell them their status has been commmented on.
    comment_notification = CommentNotification(
        user = status.user,
        status = status,
        commenter = request.user,
    )
    comment_notification.save()

    user_profile = UserProfile.objects.get(user=status.user)
    user_profile.status_notification += 1
    user_profile.save()

    return None
Пример #2
0
def comment(request):
	if request.method == 'GET':
		if 'post' in request.GET:
			return _returnJSON(Comment.objects.filter(post_id = request.GET['post']))
		return _returnJSON(Comment.objects.all())
	
	elif request.method == 'POST':
		postId = request.POST['postId']
		message = request.POST['message']
		if postId and message:
			comment = Comment(post_id = postId, message = message, user = request.user)
			comment.save()
			return HttpResponse(JsonResponse(comment.serialize()))
		else:
			return HttpResponseBadRequest(JsonResponse({'message':'Please supply the associated status and a message'}))
Пример #3
0
def add_comment(event, title, author, description):
    c = Comment(event = event, title = title)
    c.author = author
    c.description = description
    c.save()
    return c