Coverage for website/pushnotifications/signals/photos.py: 93.55%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2025-08-14 10:31 +0000

1from django.conf import settings 

2from django.db.models.signals import post_save 

3from django.utils import timezone 

4 

5from members.models import Member 

6from utils.models.signals import suspendingreceiver 

7 

8from ..models import Category, NewAlbumMessage 

9 

10 

11@suspendingreceiver( 

12 post_save, 

13 sender="photos.Album", 

14 dispatch_uid="schedule_new_album_pushnotification", 

15) 

16def schedule_new_album_pushnotification(sender, instance, **kwargs): 

17 """Create, update or delete a scheduled message for the saved album if necessary.""" 

18 message = getattr(instance, "new_album_notification", None) 

19 

20 if instance.hidden or instance.is_processing: 

21 # Remove existing not-sent notification if there is one. 

22 if message is not None and not message.sent: 

23 instance.new_album_notification = None 

24 message.delete() 

25 elif message is None or not message.sent: 25 ↛ exitline 25 didn't return from function 'schedule_new_album_pushnotification' because the condition on line 25 was always true

26 # Update existing notification or create new one. 

27 

28 if message is None: 28 ↛ 31line 28 didn't jump to line 31 because the condition on line 28 was always true

29 message = NewAlbumMessage(album=instance) 

30 

31 message.title = "New album uploaded" 

32 message.body = f"A new photo album '{instance.title}' has just been uploaded" 

33 message.url = f"{settings.BASE_URL}{instance.get_absolute_url()}" 

34 message.time = timezone.now() + timezone.timedelta(hours=1) 

35 message.category = Category.objects.get(key=Category.PHOTO) 

36 message.save() 

37 

38 message.users.set(Member.current_members.all())