Exemple #1
0
def create_notification(sender, instance, created, **kwargs):
    """This receiver creates notifications whenever a comment is saved
  """
    if created:
        parent = instance.content_object
        # Some Events don't have authors. In such cases, no need to create notifications.
        try:
            user = parent.author
        except:
            user = None

        if user and not user == instance.user:
            parent_comment = instance.parent
            # If this is a comment alert the commenter instead
            if parent_comment:
                notify_type = "comment"
                user = parent_comment.user
            else:
                notify_type = parent.type_name().lower()
            read = NotificationRead.objects.get(user=user)
            notify = Notification(user=user,
                                  author=instance.user,
                                  content_object=parent,
                                  time=datetime.datetime.utcnow(),
                                  notification_type=notify_type)
            notify.save()
            read.unread = read.unread + 1
            read.save()
Exemple #2
0
def create_notification(sender, instance, created, **kwargs):
    """This receiver creates notifications whenever a comment is saved
  """
    if created:
        parent = instance.content_object
        # Some Events don't have authors. In such cases, no need to create notifications.
        try:
            user = parent.author
        except:
            user = None

        if user and not user == instance.user:
            parent_comment = instance.parent
            # If this is a comment alert the commenter instead
            if parent_comment:
                notify_type = "comment"
                user = parent_comment.user
            else:
                notify_type = parent.type_name().lower()
            read = NotificationRead.objects.get(user=user)
            notify = Notification(
                user=user,
                author=instance.user,
                content_object=parent,
                time=datetime.datetime.utcnow(),
                notification_type=notify_type,
            )
            notify.save()
            read.unread = read.unread + 1
            read.save()