Changeset View
Changeset View
Standalone View
Standalone View
blog/signals.py
- This file was added.
| import logging | |||||
| from actstream import action | |||||
| from django.db.models.signals import post_save | |||||
| from django.dispatch import receiver | |||||
| from blog.models import PostComment | |||||
| logger = logging.getLogger(__name__) | |||||
| @receiver(post_save, sender=PostComment) | |||||
| def notify_about_comment( | |||||
| sender: object, instance: PostComment, created: bool, **kwargs: object | |||||
| ) -> None: | |||||
| """ | |||||
| Generate notifications about comments under blog posts. | |||||
| Because PostComment is created separately, this cannot be done in post_save of a Comment. | |||||
| """ | |||||
| if not created: | |||||
| return | |||||
| comment = instance.comment | |||||
| target = comment.get_action_target() | |||||
| action.send(comment.user, verb='added', action_object=comment, target=target) | |||||