#NEWLINE# @ shared_task ( ) #NEWLINE# def send_daily_digest_notification( user_id ) : #NEWLINE# #INDENT# 'Send a daily digest notification for an individual user' #NEWLINE# notifications = Notification . objects . filter ( recipient_id = user_id , consumed = False , message__status = 'approved' , subscription__period = 'daily' ) . select_related ( 'recipient' , 'message' , 'message__thread' , 'message__thread__group' , 'message__thread__group__group' ) . order_by ( '-message__thread' , '-message__pk' ) #NEWLINE# total_notifications = notifications . count ( ) #NEWLINE# if ( not total_notifications ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# recipient = notifications [ 0 ] . recipient #NEWLINE# context = { #NEWLINE# #INDENT# 'notifications' : notifications , #NEWLINE# 'recipient' : recipient , #NEWLINE# 'email' : recipient . email , #NEWLINE# #UNINDENT# } #NEWLINE# text = render_to_string ( 'notifications/email/email_digest.txt' , context ) #NEWLINE# html = render_to_string ( 'notifications/email/email_digest.html' , context ) #NEWLINE# subject = 'Your {brand} {day} Digest - {num} New {word}' . format ( brand = settings . BRAND_TITLE , day = now ( ) . strftime ( '%A' ) , num = total_notifications , word = ngettext ( 'Message' , 'Messages' , total_notifications ) ) #NEWLINE# send_email ( email = recipient . email , from_email = settings . DEFAULT_FROM_EMAIL , subject = subject , text = text , html = html ) #NEWLINE# notifications . update ( consumed = True )