3

I am making use of Django's contrib.comments and want to know the following.

Are there any utils or app out there that can be plugged into an app that sends you a notification when a comment is posted on an item?

I haven't really worked with signals that much, so please be a little bit descriptive.

This is what I came up with.

from django.contrib.comments.signals import comment_was_posted
from django.core.mail import send_mail

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

def comment_notification(request):
    user = request.user
    message = "123"
    notification.send([user], "new comment", {'message': message,}) 

    comment_was_posted.connect(comment_notification)
ApPeL
  • 4,801
  • 9
  • 47
  • 84

3 Answers3

3

Connect django.contrib.comments.signals.comment_was_posted to notification.models.send() as appropriate.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

You have to register your comment_notification function with comment_was_posted signal.

from django.contrib.comments.signals import comment_was_posted

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

    def comment_notification(sender, comment, request):
        user = request.user
        message = "123"
        notification.send([user], "new comment", {'message': message,}) 

    comment_was_posted.connect(comment_notification)
Dominik Szopa
  • 1,909
  • 1
  • 15
  • 16
  • where does this code actually go if I'm using the built-in comment tags to render my forms and list of comments? – meder omuraliev Oct 04 '10 at 08:02
  • You have to put it somewhere, so the code is initiated, ex put at the bottom of models.py. This way it will be initiated when django validates models during runserver – Dominik Szopa Oct 04 '10 at 08:50
0

I don't know of an app (pretty sure there'll be something out there) but it is fairly straightforward to roll your own. You can tap the Comment model's comment_was_posted signal to call a function that will send you an email.

Manoj Govindan
  • 72,339
  • 21
  • 134
  • 141
  • I added some code to the original post, maybe you can take a quick look to see why it's not working, I have no real dealing with the notification or signals network before. – ApPeL Sep 27 '10 at 15:12