Skip to content

Commit

Permalink
+пару полей в эндпоинт уведомлений, -комменты
Browse files Browse the repository at this point in the history
  • Loading branch information
Reagent992 committed Jan 27, 2024
1 parent e352ad2 commit 84e9142
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
6 changes: 6 additions & 0 deletions api/v1/serializers/api/notifications_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ class NotificationSerializer(serializers.ModelSerializer):

recipient = CustomUserSerializer(read_only=True, many=False)
actor = CustomUserSerializer(read_only=True, many=False)
target_object_id = serializers.IntegerField(read_only=True)
target_content_type = serializers.CharField(
source="target.__class__.__name__", read_only=True
)

class Meta:
model = Notification
fields = (
"id",
"verb",
"unread",
"target_object_id",
"target_content_type",
"timestamp",
"recipient",
"actor",
Expand Down
16 changes: 2 additions & 14 deletions core/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.dispatch import receiver
from notifications.signals import notify

from comments.models import Comment
from ipr.models import IPR
from tasks.models import Task

Expand All @@ -11,6 +10,7 @@
def created_ipr_notification(sender, instance: IPR, created, **kwargs):
"""Создание уведомления о новом ИПР."""
if created:
# TODO: Улучшить текст
text = "Вам назначен новый ИПР"
notify.send(
sender=instance.creator,
Expand All @@ -19,6 +19,7 @@ def created_ipr_notification(sender, instance: IPR, created, **kwargs):
target=instance,
)
else:
# TODO: Улучшить текст
text = "Изменение в ИПР."
notify.send(
sender=instance.creator,
Expand Down Expand Up @@ -48,16 +49,3 @@ def created_task_notification(sender, instance: Task, created, **kwargs):
verb=text,
target=instance,
)


@receiver(post_save, sender=Comment)
def created_comment_notification(sender, instance: Comment, created, **kwargs):
"""Создание уведомления о новом комментарии."""
if created:
text = "Новый комментарий"
notify.send(
sender=instance.author,
recipient=instance.ipr.executor,
verb=text,
target=instance,
)

0 comments on commit 84e9142

Please sign in to comment.