Coverage for website/promotion/emails.py: 30.30%

25 statements  

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

1import logging 

2 

3from django.conf import settings 

4from django.utils import timezone 

5 

6from promotion.models import PromotionChannel, PromotionRequest 

7from utils.snippets import send_email 

8 

9logger = logging.getLogger(__name__) 

10 

11 

12def send_weekly_overview(): 

13 new_requests = PromotionRequest.new_requests.all() 

14 upcoming_requests = PromotionRequest.upcoming_requests.all() 

15 

16 send_email( 

17 to=[settings.PROMO_REQUEST_NOTIFICATION_ADDRESS], 

18 subject="[PROMO] Weekly request overview", 

19 txt_template="promotion/email/weekly_overview.txt", 

20 html_template="promotion/email/weekly_overview.html", 

21 context={ 

22 "new_requests": new_requests, 

23 "upcoming_requests": upcoming_requests, 

24 }, 

25 ) 

26 

27 

28def send_daily_overview(): 

29 for email in ( 

30 PromotionChannel.objects.filter(publisher_reminder_email__isnull=False) 

31 .values_list("publisher_reminder_email", flat=True) 

32 .distinct() 

33 ): 

34 daily_promotion = PromotionRequest.objects.filter( 

35 channel__publisher_reminder_email=email, 

36 status=PromotionRequest.FINISHED, 

37 publish_date=timezone.now(), 

38 ).order_by("channel__name") 

39 

40 if daily_promotion.exists(): 

41 send_email( 

42 to=[email], 

43 subject="[PROMO] Daily overview", 

44 txt_template="promotion/email/daily_overview.txt", 

45 context={ 

46 "daily_promotion": daily_promotion, 

47 }, 

48 ) 

49 

50 

51def send_status_update(updated_request): 

52 if updated_request.event is None: 

53 return 

54 

55 event = updated_request.event 

56 

57 send_email( 

58 to=[organiser.contact_address for organiser in event.organisers.all()], 

59 subject="[PROMO] Status update", 

60 txt_template="promotion/email/status_update.txt", 

61 context={ 

62 "updated_request": updated_request, 

63 }, 

64 ) 

65 

66 

67def send_daily_update_overview(): 

68 updated_requests = PromotionRequest.objects.filter(status_updated=True) 

69 

70 if updated_requests: 

71 send_email( 

72 to=[settings.PROMO_REQUEST_NOTIFICATION_ADDRESS], 

73 subject="[PROMO] Daily update overview", 

74 txt_template="promotion/email/daily_update_overview.txt", 

75 html_template="promotion/email/daily_update_overview.html", 

76 context={ 

77 "updated_requests": updated_requests, 

78 }, 

79 ) 

80 updated_requests.update(status_updated=False)