Пример #1
0
 def mark_seen(self, request):
     """Mark all notifications as seen"""
     self.check_permissions(request)
     meta, _ = NotificationMeta.objects.update_or_create(
         {'marked_at': timezone.now()}, user=request.user)
     serializer = NotificationMetaSerializer(meta)
     return Response(serializer.data)
Пример #2
0
def notification_meta_saved(sender, instance, **kwargs):
    meta = instance
    payload = NotificationMetaSerializer(meta).data
    for subscription in ChannelSubscription.objects.recent().filter(
            user=meta.user):
        send_in_channel(subscription.reply_channel,
                        topic='notifications:meta',
                        payload=payload)
Пример #3
0
    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        page = self.paginate_queryset(queryset)
        serializer = self.get_serializer(page, many=True)

        meta = NotificationMeta.objects.get(user=request.user)
        meta_serializer = NotificationMetaSerializer(meta, context=self.get_serializer_context())

        return self.get_paginated_response({
            'notifications': serializer.data,
            'meta': meta_serializer.data,
        })