Coverage for website/facedetection/signals.py: 50.00%

14 statements  

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

1from django.db.models.signals import post_save 

2 

3from photos.tasks import album_uploaded 

4from utils.models.signals import suspendingreceiver 

5 

6from .models import FaceDetectionPhoto, ReferenceFace 

7from .services import trigger_facedetection_lambda 

8 

9 

10@suspendingreceiver( 

11 post_save, sender=ReferenceFace, dispatch_uid="trigger_reference_face_analysis" 

12) 

13def trigger_reference_face_analysis(sender, instance, created, **kwargs): 

14 """Start the facedetection Lambda to extract a face encoding from the reference.""" 

15 if created and instance.status == ReferenceFace.Status.PROCESSING: 

16 trigger_facedetection_lambda([instance]) 

17 

18 

19@suspendingreceiver(album_uploaded, dispatch_uid="trigger_album_analysis") 

20def trigger_album_analysis(sender, album, **kwargs): 

21 """Start the facedetection Lambda on any new photos in the album.""" 

22 photos = FaceDetectionPhoto.objects.bulk_create( 

23 FaceDetectionPhoto(photo=photo) 

24 for photo in album.photo_set.filter( 

25 facedetectionphoto__isnull=True, 

26 ) 

27 ) 

28 

29 if photos: 

30 trigger_facedetection_lambda(photos)