Exemplo n.º 1
0
def notify_new_progress_report_email(instance):
    instance = clean_instance(instance, ProgressReport)
    is_pm_report = instance.event.type in [
        LEGACY_PROGRESS_EVENT_TYPE_PM,
        LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL
    ]
    is_client_report = instance.event.type in [
        LEGACY_PROGRESS_EVENT_TYPE_CLIENT,
        LEGACY_PROGRESS_EVENT_TYPE_CLIENT_MID_SPRINT
    ]
    is_pm_or_client_report = is_pm_report or is_client_report
    is_dev_report = not is_pm_or_client_report

    subject = "{} submitted a {}".format(
        instance.user.display_name.encode('utf-8'),
        is_client_report and "Weekly Survey" or "Progress Report")

    to = is_pm_or_client_report and TUNGA_STAFF_UPDATE_EMAIL_RECIPIENTS or []
    if is_dev_report:
        if instance.event.task.owner and check_switch_setting(
                instance.event.task.owner, NEW_TASK_PROGRESS_REPORT_EMAIL):
            to.append(instance.event.task.owner.email)
        elif instance.event.task.user and check_switch_setting(
                instance.event.task.user, NEW_TASK_PROGRESS_REPORT_EMAIL):
            to.append(instance.event.task.user.email)
        admins = instance.event.task.admins
        if admins:
            to.extend([user.email for user in admins])

    if not to:
        # Should have some recipients
        return

    ctx = {
        'owner':
        instance.event.task.owner or instance.event.task.user,
        'reporter':
        instance.user,
        'event':
        instance.event,
        'report':
        instance,
        'update_url':
        '{}/work/{}/event/{}/'.format(TUNGA_URL, instance.event.task.id,
                                      instance.event.id)
    }

    email_template = is_client_report and 'new_client_survey' or 'new_progress_report{}'.format(
        is_pm_report and '_pm' or '')
    send_mail(subject, 'tunga/email/{}'.format(email_template), to, ctx,
              **dict(deal_ids=[instance.event.task.hubspot_deal_id]))
Exemplo n.º 2
0
def notify_new_progress_report_email_client(progress_report):
    progress_report = clean_instance(progress_report, ProgressReport)

    is_dev_report = progress_report.event.type == PROGRESS_EVENT_DEVELOPER or \
                    (progress_report.event.type == PROGRESS_EVENT_MILESTONE and progress_report.user.is_developer)

    if not is_dev_report:
        # Only dev reports are sent by email to clients
        return

    subject = "{} submitted a Progress Report".format(
        progress_report.user.display_name.encode('utf-8'))

    to = []
    if is_dev_report:
        owner = progress_report.event.project.owner or progress_report.event.project.user
        if owner and check_switch_setting(owner,
                                          NEW_TASK_PROGRESS_REPORT_EMAIL):
            to.append(owner.email)
            creator = progress_report.event.project.user
            if creator and creator.id != owner.id and check_switch_setting(
                    creator, NEW_TASK_PROGRESS_REPORT_EMAIL):
                to.append(creator.email)
        # TODO: Re-enable admins
        # admins = progress_report.event.project.admins
        # if admins:
        #    to.extend([user.email for user in admins])

    if not to:
        # Should have some recipients
        return

    ctx = {
        'owner':
        progress_report.event.project.owner
        or progress_report.event.project.user,
        'reporter':
        progress_report.user,
        'event':
        progress_report.event,
        'report':
        progress_report,
        'update_url':
        '{}/projects/{}/events/{}/'.format(TUNGA_URL,
                                           progress_report.event.project.id,
                                           progress_report.event.id)
    }

    send_mail(subject, 'tunga/email/new_progress_report', to, ctx)
Exemplo n.º 3
0
def notify_new_progress_report_email_client(progress_report):
    progress_report = clean_instance(progress_report, ProgressReport)

    is_dev_report = progress_report.event.type == PROGRESS_EVENT_DEVELOPER or \
                    (progress_report.event.type == PROGRESS_EVENT_MILESTONE and progress_report.user.is_developer)

    if not is_dev_report:
        # Only dev reports are sent by email to clients
        return

    subject = "{} submitted a Progress Report".format(
        progress_report.user.display_name.encode('utf-8')
    )

    to = []
    if is_dev_report:
        owner = progress_report.event.project.owner or progress_report.event.project.user
        if owner and check_switch_setting(owner, NEW_TASK_PROGRESS_REPORT_EMAIL):
            to.append(owner.email)
            creator = progress_report.event.project.user
            if creator and creator.id != owner.id and check_switch_setting(creator, NEW_TASK_PROGRESS_REPORT_EMAIL):
                to.append(creator.email)
        # TODO: Re-enable admins
        # admins = progress_report.event.project.admins
        # if admins:
        #    to.extend([user.email for user in admins])

    if not to:
        # Should have some recipients
        return

    ctx = {
        'owner': progress_report.event.project.owner or progress_report.event.project.user,
        'reporter': progress_report.user,
        'event': progress_report.event,
        'report': progress_report,
        'update_url': '{}/projects/{}/events/{}/'.format(TUNGA_URL, progress_report.event.project.id, progress_report.event.id)
    }

    send_mail(
        subject, 'tunga/email/new_progress_report', to, ctx
    )
Exemplo n.º 4
0
def notify_new_progress_report_email(instance):
    instance = clean_instance(instance, ProgressReport)
    is_pm_report = instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_PM, LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL]
    is_client_report = instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_CLIENT, LEGACY_PROGRESS_EVENT_TYPE_CLIENT_MID_SPRINT]
    is_pm_or_client_report = is_pm_report or is_client_report
    is_dev_report = not is_pm_or_client_report

    subject = "{} submitted a {}".format(
        instance.user.display_name.encode('utf-8'), is_client_report and "Weekly Survey" or "Progress Report"
    )

    to = is_pm_or_client_report and TUNGA_STAFF_UPDATE_EMAIL_RECIPIENTS or []
    if is_dev_report:
        if instance.event.task.owner and check_switch_setting(instance.event.task.owner, NEW_TASK_PROGRESS_REPORT_EMAIL):
            to.append(instance.event.task.owner.email)
        elif instance.event.task.user and check_switch_setting(instance.event.task.user, NEW_TASK_PROGRESS_REPORT_EMAIL):
            to.append(instance.event.task.user.email)
        admins = instance.event.task.admins
        if admins:
            to.extend([user.email for user in admins])

    if not to:
        # Should have some recipients
        return

    ctx = {
        'owner': instance.event.task.owner or instance.event.task.user,
        'reporter': instance.user,
        'event': instance.event,
        'report': instance,
        'update_url': '{}/work/{}/event/{}/'.format(TUNGA_URL, instance.event.task.id, instance.event.id)
    }

    email_template = is_client_report and 'new_client_survey' or 'new_progress_report{}'.format(
        is_pm_report and '_pm' or ''
    )
    send_mail(
        subject, 'tunga/email/{}'.format(email_template), to, ctx,
        **dict(deal_ids=[instance.event.task.hubspot_deal_id])
    )
Exemplo n.º 5
0
def remind_progress_event_email(progress_event):
    progress_event = clean_instance(progress_event, ProgressEvent)

    if progress_event.last_reminder_at:
        # No double notifications
        return

    is_client_event = progress_event.type in [PROGRESS_EVENT_CLIENT, PROGRESS_EVENT_MILESTONE]
    is_pm_event = progress_event.type in [PROGRESS_EVENT_PM, PROGRESS_EVENT_INTERNAL, PROGRESS_EVENT_MILESTONE]
    is_dev_event = progress_event.type in [PROGRESS_EVENT_DEVELOPER, PROGRESS_EVENT_MILESTONE]

    successful_sends = []

    owner = progress_event.project.owner or progress_event.project.user
    pm = progress_event.project.pm

    ctx = {
        'owner': owner,
        'event': progress_event,
        'update_url': '%s/projects/%s/events/%s/' % (TUNGA_URL, progress_event.project.id, progress_event.id)
    }

    if is_client_event and owner and owner.is_active and check_switch_setting(owner, TASK_SURVEY_REMINDER_EMAIL):
        subject = "Progress Survey"
        to = [owner.email]
        if owner.email != progress_event.project.user.email:
            to.append(progress_event.project.user.email)

        if send_mail(subject, 'tunga/email/client_survey_reminder_v3', to, ctx):
            successful_sends.append('client')

    if is_pm_event and pm and pm.is_active:
        subject = "Upcoming progress update"
        to = [pm.email]

        if send_mail(subject, 'tunga/email/progress_event_reminder_v3', to, ctx, bcc=None):
            successful_sends.append('pm')

    if is_dev_event:
        subject = "Upcoming progress update"

        participants = progress_event.project.participation_set.filter(status=STATUS_ACCEPTED, updates_enabled=True)
        if participants:
            to = [participants[0].user.email]
            bcc = [participant.user.email for participant in participants[1:]] if participants.count() > 1 else None

            if send_mail(subject, 'tunga/email/progress_event_reminder_v3', to, ctx, bcc=bcc):
                successful_sends.append('devs')

    if successful_sends:
        progress_event.last_reminder_at = datetime.datetime.utcnow()
        progress_event.save()
Exemplo n.º 6
0
def remind_progress_event_email(progress_event):
    progress_event = clean_instance(progress_event, ProgressEvent)

    if progress_event.last_reminder_at:
        # No double notifications
        return

    is_client_event = progress_event.type in [
        PROGRESS_EVENT_CLIENT, PROGRESS_EVENT_MILESTONE
    ]
    is_pm_event = progress_event.type in [
        PROGRESS_EVENT_PM, PROGRESS_EVENT_INTERNAL, PROGRESS_EVENT_MILESTONE
    ]
    is_dev_event = progress_event.type in [
        PROGRESS_EVENT_DEVELOPER, PROGRESS_EVENT_MILESTONE
    ]

    successful_sends = []

    owner = progress_event.project.owner or progress_event.project.user
    pm = progress_event.project.pm

    ctx = {
        'owner':
        owner,
        'event':
        progress_event,
        'update_url':
        '%s/projects/%s/events/%s/' %
        (TUNGA_URL, progress_event.project.id, progress_event.id)
    }

    if is_client_event and owner and owner.is_active and check_switch_setting(
            owner, TASK_SURVEY_REMINDER_EMAIL):
        subject = "Progress Survey"
        to = [owner.email]
        if owner.email != progress_event.project.user.email:
            to.append(progress_event.project.user.email)

        if send_mail(subject, 'tunga/email/client_survey_reminder_v3', to,
                     ctx):
            successful_sends.append('client')

    if is_pm_event and pm and pm.is_active:
        subject = "Upcoming progress update"
        to = [pm.email]

        if send_mail(subject,
                     'tunga/email/progress_event_reminder_v3',
                     to,
                     ctx,
                     bcc=None):
            successful_sends.append('pm')

    if is_dev_event:
        subject = "Upcoming progress update"
        day = datetime.datetime.now().strftime("%a")
        participants = progress_event.project.participation_set.filter(
            status=STATUS_ACCEPTED,
            updates_enabled=True,
            update_days__icontains=day)
        if participants:
            to = [participants[0].user.email]
            bcc = [participant.user.email for participant in participants[1:]
                   ] if participants.count() > 1 else None

            if send_mail(subject,
                         'tunga/email/progress_event_reminder_v3',
                         to,
                         ctx,
                         bcc=bcc):
                successful_sends.append('devs')

    if successful_sends:
        progress_event.last_reminder_at = datetime.datetime.utcnow()
        progress_event.save()
Exemplo n.º 7
0
def remind_progress_event_email(instance):
    instance = clean_instance(instance, ProgressEvent)

    is_pm_report = instance.type in [
        LEGACY_PROGRESS_EVENT_TYPE_PM,
        LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL
    ]
    is_client_report = instance.type in [
        LEGACY_PROGRESS_EVENT_TYPE_CLIENT,
        LEGACY_PROGRESS_EVENT_TYPE_CLIENT_MID_SPRINT
    ]
    is_pm_or_client_report = is_pm_report or is_client_report

    if is_pm_report and not instance.task.is_project:
        return

    pm = instance.task.pm
    if not pm and instance.task.user.is_project_manager:
        pm = instance.task.user

    if is_pm_report and not pm:
        return

    owner = instance.task.owner
    if not owner:
        owner = instance.task.user

    if is_client_report and not owner:
        return

    if is_client_report and not check_switch_setting(
            owner, TASK_SURVEY_REMINDER_EMAIL):
        return

    subject = is_client_report and "Weekly Survey" or "Upcoming {} Update".format(
        instance.task.is_task and 'Task' or 'Project')

    to = []
    bcc = None
    if is_pm_report:
        to = [pm.email]
        bcc = None
    elif is_client_report:
        to = [owner.email]
        if owner.email != instance.task.user.email:
            to.append(instance.task.user.email)
        admins = instance.task.admins
        if admins:
            to.extend([user.email for user in admins])
        bcc = None
    else:
        participants = instance.task.participation_set.filter(
            status=STATUS_ACCEPTED, updates_enabled=True)
        if participants:
            to = [participants[0].user.email]
            bcc = [participant.user.email for participant in participants[1:]
                   ] if participants.count() > 1 else None
    ctx = {
        'owner':
        instance.task.owner or instance.task.user,
        'event':
        instance,
        'update_url':
        '%s/work/%s/event/%s/' % (TUNGA_URL, instance.task.id, instance.id)
    }

    if to:
        email_template = is_client_report and 'client_survey_reminder' or 'progress_event_reminder'
        if send_mail(subject,
                     'tunga/email/{}'.format(email_template),
                     to,
                     ctx,
                     bcc=bcc,
                     **dict(deal_ids=[instance.task.hubspot_deal_id])):
            instance.last_reminder_at = datetime.datetime.utcnow()
            instance.save()
Exemplo n.º 8
0
def remind_progress_event_email(instance):
    instance = clean_instance(instance, ProgressEvent)

    is_pm_report = instance.type in [LEGACY_PROGRESS_EVENT_TYPE_PM, LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL]
    is_client_report = instance.type in [LEGACY_PROGRESS_EVENT_TYPE_CLIENT, LEGACY_PROGRESS_EVENT_TYPE_CLIENT_MID_SPRINT]
    is_pm_or_client_report = is_pm_report or is_client_report

    if is_pm_report and not instance.task.is_project:
        return

    pm = instance.task.pm
    if not pm and instance.task.user.is_project_manager:
        pm = instance.task.user

    if is_pm_report and not pm:
        return

    owner = instance.task.owner
    if not owner:
        owner = instance.task.user

    if is_client_report and not owner:
        return

    if is_client_report and not check_switch_setting(owner, TASK_SURVEY_REMINDER_EMAIL):
        return

    subject = is_client_report and "Weekly Survey" or "Upcoming {} Update".format(
        instance.task.is_task and 'Task' or 'Project')

    to = []
    bcc = None
    if is_pm_report:
        to = [pm.email]
        bcc = None
    elif is_client_report:
        to = [owner.email]
        if owner.email != instance.task.user.email:
            to.append(instance.task.user.email)
        admins = instance.task.admins
        if admins:
            to.extend([user.email for user in admins])
        bcc = None
    else:
        participants = instance.task.participation_set.filter(status=STATUS_ACCEPTED, updates_enabled=True)
        if participants:
            to = [participants[0].user.email]
            bcc = [participant.user.email for participant in participants[1:]] if participants.count() > 1 else None
    ctx = {
        'owner': instance.task.owner or instance.task.user,
        'event': instance,
        'update_url': '%s/work/%s/event/%s/' % (TUNGA_URL, instance.task.id, instance.id)
    }

    if to:
        email_template = is_client_report and 'client_survey_reminder' or 'progress_event_reminder'
        if send_mail(
                subject, 'tunga/email/{}'.format(email_template), to, ctx, bcc=bcc,
                **dict(deal_ids=[instance.task.hubspot_deal_id])
        ):
            instance.last_reminder_at = datetime.datetime.utcnow()
            instance.save()