Example #1
0
    def _send_email(self,
                    recipients,
                    template_name,
                    context=None,
                    user=None,
                    include_token=False,
                    **kwargs):
        context = context or {}

        base_context = {
            'visit': self.get_mail_context(user=user,
                                           include_token=include_token),
            'environment': get_environment(),
        }
        base_context.update(context)
        context = base_context

        if isinstance(recipients, str):
            recipients = [
                recipients,
            ]
        else:
            recipients = list(recipients)

        # assert recipients
        if recipients:
            send_notification_with_template(
                recipients=recipients,
                template_name=template_name,
                context=context,
            )
Example #2
0
def notify_partner_hidden(partner_pk, tenant_name):

    with schema_context(tenant_name):
        partner = PartnerOrganization.objects.get(pk=partner_pk)
        pds = Intervention.objects.filter(
            agreement__partner__name=partner.name,
            status__in=[
                Intervention.SIGNED, Intervention.ACTIVE, Intervention.ENDED
            ])
        if pds:
            email_context = {
                'partner_name': partner.name,
                'pds': ', '.join(pd.number for pd in pds),
                'environment': get_environment(),
            }
            emails_to_pd = [
                pd.unicef_focal_points.values_list('email', flat=True)
                for pd in pds
            ]
            recipients = set(itertools.chain.from_iterable(emails_to_pd))

            send_notification_with_template(
                recipients=list(recipients),
                template_name='partners/blocked_partner',
                context=email_context)
Example #3
0
def send_invite_email(staff):
    context = {
        'environment': get_environment(),
        'login_link': get_token_auth_link(staff.user)
    }

    send_notification_using_email_template(
        recipients=[staff.user.email],
        email_template_name='organisations/staff_member/invite',
        context=context)
Example #4
0
    def send_email(self, recipient, template_name, additional_context=None):
        context = {
            'environment': get_environment(),
            'action_point': self.get_mail_context(user=recipient),
            'recipient': recipient.get_full_name(),
        }
        context.update(additional_context or {})

        notification = Notification.objects.create(
            sender=self,
            recipients=[recipient.email], template_name=template_name,
            template_data=context
        )
        notification.send_notification()
Example #5
0
    def _notify_focal_points(self, template_name, context=None):
        for focal_point in get_user_model().objects.filter(
                groups=UNICEFAuditFocalPoint.as_group()):
            # Build the context in the same order the previous version of the code did,
            # just in case something relies on it (intentionally or not).
            ctx = {
                'focal_point': focal_point.get_full_name(),
            }
            if context:
                ctx.update(context)
            base_context = {
                'engagement': self.get_mail_context(user=focal_point),
                'environment': get_environment(),
            }
            base_context.update(ctx)
            context = base_context

            send_notification_using_email_template(
                recipients=[focal_point.email],
                email_template_name=template_name,
                context=context,
            )