Notification emails #80
@ -8,3 +8,5 @@ class Verb:
|
||||
COMMENTED = 'commented'
|
||||
REQUESTED_CHANGES = 'requested changes'
|
||||
REQUESTED_REVIEW = 'requested review'
|
||||
|
||||
RATED_EXTENSION = 'rated extension'
|
||||
|
@ -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'))
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user