0001-notifications-don-t-make-ack-imply-forget-25186.patch
combo/apps/notifications/models.py | ||
---|---|---|
42 | 42 |
return qs.filter(search_id) |
43 | 43 | |
44 | 44 |
def ack(self): |
45 |
self.filter(end_timestamp__isnull=True).update(acked=True, end_timestamp=now() - timedelta(seconds=5)) |
|
46 |
self.filter(end_timestamp__isnull=False).update(acked=True) |
|
45 |
self.update(acked=True) |
|
47 | 46 | |
48 | 47 |
def visible(self, user=None, n=None): |
49 | 48 |
qs = self |
... | ... | |
149 | 148 |
notification = Notification.objects.create(user=user, **defaults) |
150 | 149 |
return notification |
151 | 150 | |
152 |
@property |
|
153 |
def visible(self): |
|
154 |
return self.end_timestamp > now() |
|
155 | ||
156 | 151 |
def forget(self): |
157 | 152 |
self.end_timestamp = now() - timedelta(seconds=5) |
158 | 153 |
self.acked = True |
159 | 154 |
self.save(update_fields=['end_timestamp', 'acked']) |
160 | 155 | |
161 | 156 |
def ack(self): |
162 |
if self.end_timestamp: |
|
163 |
self.acked = True |
|
164 |
self.save(update_fields=['acked']) |
|
165 |
else: |
|
166 |
self.acked = True |
|
167 |
self.end_timestamp = now() - timedelta(seconds=5) |
|
168 |
self.save(update_fields=['acked', 'end_timestamp']) |
|
157 |
self.acked = True |
|
158 |
self.save(update_fields=['acked']) |
|
169 | 159 | |
170 | 160 | |
171 | 161 |
@register_cell_class |
tests/test_notification.py | ||
---|---|---|
458 | 458 | |
459 | 459 |
Notification.objects.visible(john_doe).ack() |
460 | 460 | |
461 |
# acking a notification without and end_timestamp, forget it
|
|
461 |
# acking a notification without and end_timestamp, still visible
|
|
462 | 462 |
freezer.move_to(start + timedelta(days=365, seconds=1)) |
463 | 463 |
content = cell.render(context) |
464 |
assert Notification.objects.visible(john_doe).count() == 0
|
|
465 |
assert 'notibar' not in content
|
|
464 |
assert Notification.objects.visible(john_doe).count() == 1
|
|
465 |
assert 'notibar' in content |
|
466 | 466 |
assert 'notifoo' not in content |
467 |
- |