Notification emails #80

Merged
Oleg-Komarov merged 31 commits from notifications into main 2024-04-18 16:11:20 +02:00
4 changed files with 37 additions and 1 deletions
Showing only changes of commit dbaeeddcfd - Show all commits

View File

@ -8,3 +8,5 @@ class Verb:
COMMENTED = 'commented'
REQUESTED_CHANGES = 'requested changes'
REQUESTED_REVIEW = 'requested review'
RATED_EXTENSION = 'rated extension'

View File

@ -7,3 +7,6 @@ class RatingsConfig(AppConfig):
def ready(self):
import ratings.signals # noqa: F401
from actstream import registry
registry.register(self.get_model('Rating'))

View File

@ -1,6 +1,8 @@
from actstream import action
from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver
from constants.activity import Verb
from ratings.models import Rating
@ -17,3 +19,24 @@ def _update_rating_counters(sender, instance, *args, **kwargs):
version = instance.version
version.recalculate_average_score()
@receiver(post_save, sender=Rating)
def create_action_from_rating(
sender: object,
instance: Rating,
created: bool,
raw: bool,
**kwargs: object,
) -> None:
if raw:
return
if not created:
return
action.send(
instance.user,
verb=Verb.RATED_EXTENSION,
action_object=instance,
target=instance.extension,
)

View File

@ -39,7 +39,15 @@ def update_user(
@receiver(post_save, sender=Action)
def create_notification(sender: object, instance: Action, created: bool, **kwargs: object) -> None:
def create_notification(
sender: object,
instance: Action,
created: bool,
raw: bool,
**kwargs: object,
) -> None:
if raw:
return
if not created:
return