Signal to notify new saved comments

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
#
# Copyright (c) 2009 Arthur Furlan <arthur.furlan@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# On Debian systems, you can find the full text of the license in
# /usr/share/common-licenses/GPL-2

def new_comment_notifier(sender, comment, request, *args, **kwargs):
    """
    Signal to notify new saved comments.

    Example:
        from django.contrib.comment import models, signals
        signals.comment_was_posted.connect(new_comment_notifier,
            sender=models.Comment)
    """

    # get the new comment url
    site = Site.objects.get_current()
    content_object = comment.content_object
    url = 'http://%s?c=%d' % (site.domain + content_object.get_absolute_url(),
        comment.id)

    # send the mail message
    subject = "New comment posted on '%s'" % str(content_object)
    message = "%s:\n%s" % (subject, url)
    mail_admins(subject, message)

More like this

  1. Signal to post new saved objects to Twitter by arthurfurlan 5 years, 1 month ago
  2. Class ModelInfo for show object info by marinho 5 years, 9 months ago
  3. Support for {% macro %} tags in templates, version 2 by mludvig 6 years, 8 months ago
  4. Model Hooks by jakecr 4 years, 3 months ago
  5. Binding signals to abstract models by andreterra 1 year, 11 months ago

Comments

(Forgotten your password?)