views:

66

answers:

1

Hello,

This is my first time working with django signals and I would like to hook the "comment_was_flagged" signal provided by the comments app to notify me when a comment is flagged.

This is my code, but it doesn't seem to work, am I missing something?

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

def comment_flagged_notification(sender, **kwargs):
  send_mail('testing moderation', 'testing', 'test@localhost', ['[email protected]',])

comment_was_flagged.connect(comment_flagged_notification)

(I am just testing the email for now, but I have assured the email is sending properly.)

Thanks!

+2  A: 

I'm guessing you've thrown this code in a signals.py module, or something similar.

You have to make sure your module code is actually getting executed at runtime. If none of your model modules import your signals module, your signal listeners won't be getting connected.

Stealing a snippet from Django's signals documentation:

... you'll need to make sure that the module it's in gets imported early on so that the signal handling gets registered before any signals need to be sent. This makes your app's models.py a good place to put registration of signal handlers.

SmileyChris