Esempio n. 1
0
def notify_event_owners_to_input_metrics():
    """Send an email to event creators.

    After an event has finished event creators are notified
    that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(days=-1), datetime.min.time())
    end = datetime.combine(get_date(days=-1), datetime.max.time())
    events = Event.objects.filter(end__range=[start, end],
                                  has_new_metrics=True,
                                  eventmetricoutcome__outcome__isnull=True)
    events = events.distinct()

    event_model = ContentType.objects.get_for_model(Event)
    for event in events:
        # Before sending an email check that an action item already exists.
        # If it does, then we have already sent this email.

        action_item = ActionItem.objects.filter(content_type=event_model,
                                                object_id=event.id)
        if not action_item.exists():
            subject = ('[Reminder] Please add the actual metrics for event {0}'
                       .format(event.name))
            template = 'email/event_creator_notification_to_input_metrics.txt'
            data = {'event': event}
            send_remo_mail(subject=subject,
                           email_template=template,
                           recipients_list=[event.owner.id],
                           data=data)
            ActionItem.create(instance=event)
Esempio n. 2
0
File: tasks.py Progetto: flaki/remo
def notify_event_owners_to_input_metrics():
    """Send an email to event creators.

    After an event has finished event creators are notified
    that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(days=-1), datetime.min.time())
    end = datetime.combine(get_date(days=-1), datetime.max.time())
    events = Event.objects.filter(
        end__range=[start, end], has_new_metrics=True, eventmetricoutcome__outcome__isnull=True
    )
    events = events.distinct()

    event_model = ContentType.objects.get_for_model(Event)
    for event in events:
        # Before sending an email check that an action item already exists.
        # If it does, then we have already sent this email.

        action_item = ActionItem.objects.filter(content_type=event_model, object_id=event.id)
        if not action_item.exists():
            subject = "[Reminder] Please add the actual metrics for event {0}".format(event.name)
            template = "email/event_creator_notification_to_input_metrics.txt"
            data = {"event": event}
            send_remo_mail(subject=subject, email_template=template, recipients_list=[event.owner.id], data=data)
            ActionItem.create(instance=event)
Esempio n. 3
0
    def test_without_recipients(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject, sender=from_email, message=message, recipients_list=None)
        ok_(not mocked_email_message.called)
Esempio n. 4
0
    def test_without_message_and_template(self):
        recipient = UserFactory.create()
        subject = 'This is the subject'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject, recipients_list=[recipient.id], sender=from_email,)
        ok_(not mocked_email_message.called)
Esempio n. 5
0
    def test_send_to_invalid_email_address(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject, recipients_list=['Not an address'], sender=from_email,
                           message=message)
        ok_(not mocked_email_message.called)
Esempio n. 6
0
    def test_send_to_invalid_email_address(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject,
                           recipients_list=['Not an address'],
                           sender=from_email,
                           message=message)
        ok_(not mocked_email_message.called)
Esempio n. 7
0
    def test_without_recipients(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject,
                           sender=from_email,
                           message=message,
                           recipients_list=None)
        ok_(not mocked_email_message.called)
Esempio n. 8
0
    def test_without_message_and_template(self):
        recipient = UserFactory.create()
        subject = 'This is the subject'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(
                subject,
                recipients_list=[recipient.id],
                sender=from_email,
            )
        ok_(not mocked_email_message.called)
Esempio n. 9
0
    def test_send_email_from_remobot(self):
        recipient = UserFactory.create()
        subject = 'This is the subject'
        message = 'This is the message'
        to = u'%s %s <%s>' % (recipient.first_name, recipient.last_name, recipient.email)

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject, recipients_list=[recipient.id], message=message)

        mocked_email_message.assert_called_once_with(body=message,
                                                     to=[to],
                                                     subject=subject,
                                                     headers={},
                                                     from_email=settings.FROM_EMAIL)
Esempio n. 10
0
    def test_send_to_valid_email_address(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject, recipients_list=['*****@*****.**'], sender=from_email,
                           message=message)

        mocked_email_message.assert_called_once_with(body=message,
                                                     to=['*****@*****.**'],
                                                     cc=[from_email],
                                                     subject=subject,
                                                     headers={'Reply-To': from_email},
                                                     from_email=settings.FROM_EMAIL)
Esempio n. 11
0
def send_rotm_nomination_reminder():
    """ Send an email reminder to all mentors.

    The first day of each month, the mentor group receives an email reminder
    in order to nominate Reps for the Rep of the month voting.
    """

    now_date = now().date()
    if now_date.day == ROTM_REMINDER_DAY:
        data = {'month': number2month(now_date.month)}
        subject = 'Nominate Rep of the month'
        template = 'emails/mentors_rotm_reminder.txt'
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[settings.REPS_MENTORS_LIST],
                       data=data)
Esempio n. 12
0
    def test_headers(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'
        headers = {'Reply-To': '*****@*****.**'}

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject, recipients_list=['*****@*****.**'],
                           sender=from_email, message=message, headers=headers)

        mocked_email_message.assert_called_once_with(body=message,
                                                     to=['*****@*****.**'],
                                                     cc=[from_email],
                                                     subject=subject,
                                                     from_email=from_email,
                                                     headers=headers)
Esempio n. 13
0
def send_rotm_nomination_reminder():
    """ Send an email reminder to all mentors.

    The first day of each month, the mentor group receives an email reminder
    in order to nominate Reps for the Rep of the month voting.
    """

    now_date = now().date()
    if now_date.day == ROTM_REMINDER_DAY:
        data = {'month': number2month(now_date.month)}
        subject = 'Nominate Rep of the month'
        template = 'emails/mentors_rotm_reminder.txt'
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[settings.REPS_MENTORS_LIST],
                       data=data)
Esempio n. 14
0
    def test_send_to_valid_email_address(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject,
                           recipients_list=['*****@*****.**'],
                           sender=from_email,
                           message=message)

        mocked_email_message.assert_called_once_with(body=message,
                                                     to=['*****@*****.**'],
                                                     cc=[from_email],
                                                     subject=subject,
                                                     headers={},
                                                     from_email=from_email)
Esempio n. 15
0
    def test_base(self):
        recipient = UserFactory.create()
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'
        to = u'%s %s <%s>' % (recipient.first_name, recipient.last_name, recipient.email)

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject, recipients_list=[recipient.id],
                           sender=from_email, message=message)

        mocked_email_message.assert_called_once_with(body=message,
                                                     to=[to],
                                                     cc=[from_email],
                                                     subject=subject,
                                                     headers={'Reply-To': from_email},
                                                     from_email=settings.FROM_EMAIL)
Esempio n. 16
0
    def test_send_email_from_remobot(self):
        recipient = UserFactory.create()
        subject = 'This is the subject'
        message = 'This is the message'
        to = u'%s %s <%s>' % (recipient.first_name, recipient.last_name,
                              recipient.email)

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject,
                           recipients_list=[recipient.id],
                           message=message)

        mocked_email_message.assert_called_once_with(
            body=message,
            to=[to],
            subject=subject,
            headers={},
            from_email=settings.FROM_EMAIL)
Esempio n. 17
0
def notify_event_owners_to_input_metrics():
    """Send an email to event creators after an event
    has finished that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(), datetime.min.time())
    end = datetime.combine(get_date(), datetime.max.time())
    events = Event.objects.filter(end__range=[start, end],
                                  has_new_metrics=True,
                                  eventmetricoutcome__outcome__isnull=True)
    events = events.distinct()

    for event in events:
        subject = ('[Reminder] Please add the actual metrics for event {0}'
                   .format(event.name))
        template = 'email/event_creator_notification_to_input_metrics.txt'
        data = {'event': event}
        send_remo_mail(subject=subject, email_template=template,
                       recipients_list=[event.owner.id], data=data)
Esempio n. 18
0
def send_report_notification(reps, weeks):
    """Send notification to inactive reps."""
    rep_subject = '[Reminder] Please share your recent activities'
    rep_mail_body = 'emails/reps_ng_report_notification.txt'
    mentor_subject = ('[Report] Mentee without report for the last %d weeks'
                      % weeks)
    mentor_mail_body = 'emails/mentor_ng_report_notification.txt'

    for rep in reps:
        ctx_data = {'mentor': rep.userprofile.mentor,
                    'user': rep,
                    'SITE_URL': settings.SITE_URL,
                    'weeks': weeks}

        rep_message = render_to_string(rep_mail_body, ctx_data)
        mentor_message = render_to_string(mentor_mail_body, ctx_data)
        send_remo_mail(rep_subject, [rep.email], message=rep_message)
        send_remo_mail(mentor_subject, [rep.userprofile.mentor.email],
                       message=mentor_message)
Esempio n. 19
0
def send_rotm_nomination_reminder():
    """ Send an email reminder to all mentors.

    The first day of each month, the mentor group receives an email reminder
    in order to nominate Reps for the Rep of the month voting.
    """

    now_date = now().date()
    if (now_date.day == ROTM_REMINDER_DAY
            or waffle.switch_is_active('enable_rotm_tasks')):
        data = {'month': number2month(now_date.month)}
        subject = 'Nominate Rep of the month'
        template = 'emails/mentors_rotm_reminder.jinja'
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[settings.REPS_MENTORS_LIST],
                       data=data)
        mentors = User.objects.filter(groups__name='Mentor')
        for mentor in mentors:
            ActionItem.create(mentor.userprofile)
Esempio n. 20
0
def send_rotm_nomination_reminder():
    """ Send an email reminder to all mentors.

    The first day of each month, the mentor group receives an email reminder
    in order to nominate Reps for the Rep of the month voting.
    """

    now_date = now().date()
    if (now_date.day == ROTM_REMINDER_DAY or
            waffle.switch_is_active('enable_rotm_tasks')):
        data = {'month': number2month(now_date.month)}
        subject = 'Nominate Rep of the month'
        template = 'emails/mentors_rotm_reminder.jinja'
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[settings.REPS_MENTORS_LIST],
                       data=data)
        mentors = User.objects.filter(groups__name='Mentor')
        for mentor in mentors:
            ActionItem.create(mentor.userprofile)
Esempio n. 21
0
    def test_headers(self):
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'
        headers = {'Reply-To': '*****@*****.**'}

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject,
                           recipients_list=['*****@*****.**'],
                           sender=from_email,
                           message=message,
                           headers=headers)

        mocked_email_message.assert_called_once_with(
            body=message,
            to=['*****@*****.**'],
            cc=[from_email],
            subject=subject,
            from_email=settings.FROM_EMAIL,
            headers=headers)
Esempio n. 22
0
    def test_base(self):
        recipient = UserFactory.create()
        subject = 'This is the subject'
        message = 'This is the message'
        from_email = u'Joe Doe <*****@*****.**>'
        to = u'%s %s <%s>' % (recipient.first_name, recipient.last_name,
                              recipient.email)

        with patch('remo.base.tasks.EmailMessage') as mocked_email_message:
            send_remo_mail(subject,
                           recipients_list=[recipient.id],
                           sender=from_email,
                           message=message)

        mocked_email_message.assert_called_once_with(body=message,
                                                     to=[to],
                                                     cc=[from_email],
                                                     subject=subject,
                                                     headers={},
                                                     from_email=from_email)
Esempio n. 23
0
def send_report_notification(reps, weeks):
    """Send notification to inactive reps."""
    rep_subject = '[Reminder] Please share your recent activities'
    rep_mail_body = 'emails/reps_ng_report_notification.txt'
    mentor_subject = ('[Report] Mentee without report for the last %d weeks' %
                      weeks)
    mentor_mail_body = 'emails/mentor_ng_report_notification.txt'

    for rep in reps:
        ctx_data = {
            'mentor': rep.userprofile.mentor,
            'user': rep,
            'SITE_URL': settings.SITE_URL,
            'weeks': weeks
        }

        rep_message = render_to_string(rep_mail_body, ctx_data)
        mentor_message = render_to_string(mentor_mail_body, ctx_data)
        send_remo_mail(rep_subject, [rep.email], message=rep_message)
        send_remo_mail(mentor_subject, [rep.userprofile.mentor.email],
                       message=mentor_message)
Esempio n. 24
0
def notify_event_owners_to_input_metrics():
    """Send an email to event creators after an event
    has finished that they should input the actual metrics for the event.
    """
    start = datetime.combine(get_date(), datetime.min.time())
    end = datetime.combine(get_date(), datetime.max.time())
    events = Event.objects.filter(end__range=[start, end],
                                  has_new_metrics=True,
                                  eventmetricoutcome__outcome__isnull=True)
    events = events.distinct()

    for event in events:
        subject = (
            '[Reminder] Please add the actual metrics for event {0}'.format(
                event.name))
        template = 'email/event_creator_notification_to_input_metrics.txt'
        data = {'event': event}
        send_remo_mail(subject=subject,
                       email_template=template,
                       recipients_list=[event.owner.id],
                       data=data)