def send_privacy_report():
    # retrieve person objects
    msgt('(1) retrieving Person objects')
    lst = Person.objects.filter(visible=True)
    msg('number found: %s' % lst.count())
    
    # filter out objects without privacy information
    msgt('(2) Filtering people without privacy info')    
    no_info = filter(lambda x: x.harvardpersoninfo_set.count()==0, lst)
    no_info = filter(lambda x: not x.email == '*****@*****.**', no_info)
    
    msg('people w/o privacy info: %s' % len(no_info))

    # contruct an email
    msgt('(3) Preparing email with results')
    
    admin_emails = get_admin_email_addresses()    
    from_email = admin_emails[0]
    to_addresses = admin_emails
    
    for email in DirectoryNotificationEmail.objects.all().values_list('email', flat=True):
        to_addresses.append(email)
    
    if len(no_info) == 0:
        subject = 'Personnel Privacy Data: Looks Good!' 
        mail_msg = """Every person has a privacy record. (%s)""" % get_datetime_now()
    else:
        subject = 'Personnel Privacy Data: %s people do not have info' % len(no_info)
        
        person_lst = '\n\n'.join(map(lambda x: '- %s - %s'  % (x, \
'https://webapps.sciences.fas.harvard.edu/mcb/mcb-control-panel/person/person/%s/' % x.id), no_info ))
        
        mail_msg = """The following people lack privacy records: 
        
%s

(time %s)""" % (person_lst,   get_datetime_now() )
    
    msg('from: %s' % from_email)
    msg('to_addresses: %s' % to_addresses)
    msg('mail_msg: %s' % mail_msg)

    msgt('(4) Sending email with results')
    
    send_message(from_email,\
                to_addresses, \
                subject=subject,\
                text_content=mail_msg,\
                html_content=mail_msg.replace('\n', '<br />'))
        
    msg('Email sent!')
    msgt('Done')
    def send_update_report(self):

        msgt('Preparing email with report')
        admin_emails = get_admin_email_addresses()    
        # add susan, kim, and natacha to email notice
        for additional_email in '[email protected] [email protected] [email protected]'.split():
            admin_emails.append(additional_email)
        
        from_email = admin_emails[0]
        to_addresses = admin_emails
        
        if len(self.msg_lines) == 0:
            subject = 'Privacy Data Updates: Looks Good! %s records checked' % self.num_records_updated 
            mail_msg = """Existing privacy records updated.\n\n%s records checked.  No errors.\n\n(%s)""" % (self.num_records_updated,get_datetime_now())
        else:
            subject = 'Privacy Data Updates: %s error notes' % len(self.msg_lines)
            mail_msg = """%s records checked. The following records had error messages: 

    %s

    (time %s)""" % (self.num_records_updated, '\n\n'.join(self.msg_lines),   get_datetime_now() )

        mail_msg += """
        
Note: This is a weekly check to ensure that people in the MCB directory are still in the HU's central directory.  
        
The possible reasons for a person failing the check are:
        
(1) The person has left the University
(2) The last name of the person has changed
"""

        msg('from: %s' % from_email)
        msg('to_addresses: %s' % to_addresses)
        msg('mail_msg: %s' % mail_msg)

        msgt('(4) Sending email with results')

        send_message(from_email,\
               to_addresses, \
               subject=subject,\
               text_content=mail_msg,\
               html_content=mail_msg.replace('\n', '<br />'))

        msg('Email sent!')
        msgt('Done')
def send_privacy_report():
    # contruct an email
    msgt("(3) Preparing email with results")

    admin_emails = get_admin_email_addresses()

    from_email = admin_emails[0]
    to_addresses = admin_emails
    if len(no_info) == 0:
        subject = "Personnel Privacy Data: Looks Good!"
        mail_msg = """Every person has a privacy record. (%s)""" % get_datetime_now()
    else:
        subject = "Personnel Privacy Data: %s people do not have info" % len(no_info)

        person_lst = "\n\n".join(
            map(
                lambda x: "- %s - %s"
                % (x, "https://webapps.sciences.fas.harvard.edu/mcb/mcb-control-panel/person/person/%s/" % x.id),
                no_info,
            )
        )

        mail_msg = """The following people lack privacy records: 
        
%s

(time %s)""" % (
            person_lst,
            get_datetime_now(),
        )

    msg("from: %s" % from_email)
    msg("to_addresses: %s" % to_addresses)
    msg("mail_msg: %s" % mail_msg)

    msgt("(4) Sending email with results")

    send_message(
        from_email, to_addresses, subject=subject, text_content=mail_msg, html_content=mail_msg.replace("\n", "<br />")
    )

    msg("Email sent!")
    msgt("Done")