|
1 | | -from django.db.models import Value, When, Case, F, Q, OuterRef, Subquery |
| 1 | +from django.db.models import Value, When, Case, Q, OuterRef, Subquery |
2 | 2 | from django.db.models.fields import CharField, IntegerField |
3 | 3 | from django.db.models.functions import Concat, Cast |
4 | 4 | from django.contrib.contenttypes.models import ContentType |
@@ -56,35 +56,38 @@ def get_queryset(self): |
56 | 56 | id=Cast(OuterRef('object_id'), IntegerField()), |
57 | 57 | ).values('guids___id')[:1] |
58 | 58 |
|
59 | | - return NotificationSubscription.objects.filter(user=self.request.user).annotate( |
| 59 | + return NotificationSubscription.objects.filter( |
| 60 | + notification_type__in=[ |
| 61 | + NotificationType.Type.USER_FILE_UPDATED.instance, |
| 62 | + NotificationType.Type.NODE_FILE_UPDATED.instance, |
| 63 | + NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.instance, |
| 64 | + ], |
| 65 | + user=self.request.user, |
| 66 | + ).annotate( |
60 | 67 | event_name=Case( |
61 | 68 | When( |
62 | | - notification_type__name=NotificationType.Type.NODE_FILES_UPDATED.value, |
| 69 | + notification_type=NotificationType.Type.USER_FILE_UPDATED.instance, |
63 | 70 | then=Value('files_updated'), |
64 | 71 | ), |
65 | 72 | When( |
66 | | - notification_type__name=NotificationType.Type.USER_FILE_UPDATED.value, |
| 73 | + notification_type=NotificationType.Type.USER_FILE_UPDATED.instance, |
67 | 74 | then=Value('global_file_updated'), |
68 | 75 | ), |
69 | | - default=F('notification_type__name'), |
70 | | - output_field=CharField(), |
71 | 76 | ), |
72 | 77 | legacy_id=Case( |
73 | 78 | When( |
74 | | - notification_type__name=NotificationType.Type.NODE_FILES_UPDATED.value, |
| 79 | + notification_type=NotificationType.Type.NODE_FILES_UPDATED.instance, |
75 | 80 | then=Concat(Subquery(node_subquery), Value('_file_updated')), |
76 | 81 | ), |
77 | 82 | When( |
78 | | - notification_type__name=NotificationType.Type.USER_FILE_UPDATED.value, |
| 83 | + notification_type=NotificationType.Type.USER_FILE_UPDATED.instance, |
79 | 84 | then=Value(f'{user_guid}_global'), |
80 | 85 | ), |
81 | 86 | When( |
82 | | - Q(notification_type__name=NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.value) & |
| 87 | + Q(notification_type=NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.instance) & |
83 | 88 | Q(content_type=provider_ct), |
84 | 89 | then=Concat(Subquery(provider_subquery), Value('_new_pending_submissions')), |
85 | 90 | ), |
86 | | - default=F('notification_type__name'), |
87 | | - output_field=CharField(), |
88 | 91 | ), |
89 | 92 | ) |
90 | 93 |
|
@@ -144,6 +147,11 @@ def get_object(self): |
144 | 147 |
|
145 | 148 | try: |
146 | 149 | obj = NotificationSubscription.objects.annotate( |
| 150 | + notification_type__in=[ |
| 151 | + NotificationType.Type.USER_FILE_UPDATED.instance, |
| 152 | + NotificationType.Type.NODE_FILE_UPDATED.instance, |
| 153 | + NotificationType.Type.PROVIDER_NEW_PENDING_SUBMISSIONS.instance, |
| 154 | + ], |
147 | 155 | legacy_id=Case( |
148 | 156 | When( |
149 | 157 | notification_type__name=NotificationType.Type.NODE_FILES_UPDATED.value, |
|
0 commit comments