示例#1
0
 def send_training_email(self):
     subject = 'Capacitación virtual de Brigada'
     body = """¡Gracias por activar tu cuenta!<br><br>
     Falta solo una cosa para convertirte en un usuario experto: agendar tu capacitación virtual.<br><br>
     Manda un email a <a href="mailto:[email protected]?Subject=Brigada Agendar Capacitación" target="_blank">[email protected]</a> con tu disponibilidad.
     """.format(os.getenv('CUSTOM_SITE_URL'), self.set_password_token,
                self.email)
     send_pretty_email.delay([self.email],
                             subject,
                             body,
                             name=self.first_name)
示例#2
0
 def activate_account_email(self):
     subject = 'Activa tu cuenta Brigada'
     body = """¡Gracias por crear tu cuenta de donador con Brigada!<br><br>
     Dale clic en el link para activar tu cuenta:<br><br>
     <a href="{}/establecer?token={}&email={}&type=donor&created=true" target="_blank">Activar tu cuenta</a>
     """.format(os.getenv('CUSTOM_SITE_URL'), self.set_password_token,
                self.email)
     send_pretty_email.delay([self.email],
                             subject,
                             body,
                             name=self.first_name)
示例#3
0
def send_email_notification(notification_id) -> Dict:
    n = EmailNotification.objects.get(id=notification_id)
    r_base = {'args': n.args, 'type': n.email_type}
    if not balance_schedule():
        return {**r_base, 'result': 'balance_schedule_not_sent'}
    if not n.should_send():
        return {**r_base, 'result': 'should_send_not_sent'}
    kwargs_sets = notification_function_by_email_type[n.email_type](n)
    if kwargs_sets is None:
        return {**r_base, 'result': 'notification_function_not_sent'}
    for kwargs_set in kwargs_sets:
        if n.pretty:
            send_pretty_email.delay(**kwargs_set)
        else:
            send_email.delay(**kwargs_set)
    n.increment_sent()
    return {**r_base, 'result': kwargs_sets}
示例#4
0
    def save(self, *args, **kwargs):
        """Approves donations created by org user if no donor user exists yet.
        Unpublishes donations updated by either org or donor if there are any
        changes to donation.
        """
        from jobs.notifications import notification_function_by_email_type

        saved_by = kwargs.pop('saved_by', None)
        donor_has_users = len(self.donor.donoruser_set.all()) > 0
        email_type = None
        notification_args = None

        if self.pk is None:
            if saved_by == 'donor':
                self.approved_by_org = False
            if saved_by == 'org':
                self.approved_by_donor = not donor_has_users
            super().save(*args,
                         **kwargs)  # save instance first so pk isn't `None`

            if saved_by == 'donor':
                email_type = 'donation_unapproved'
                notification_args = {
                    'donation_id': self.pk,
                    'notify': 'org',
                    'created': True
                }
            if saved_by == 'org':
                if donor_has_users:
                    email_type = 'donation_unapproved'
                    notification_args = {
                        'donation_id': self.pk,
                        'notify': 'donor',
                        'created': True
                    }
                else:
                    email_type = 'donor_unclaimed'
                    notification_args = {'donation_id': self.pk}
        else:
            old = Donation.objects.get(pk=self.pk)
            if any(
                    getattr(old, f) != getattr(self, f)
                    for f in donation_fields):
                if saved_by == 'donor':
                    self.approved_by_org = False
                    email_type = 'donation_unapproved'
                    notification_args = {
                        'donation_id': self.pk,
                        'notify': 'org',
                        'created': False
                    }
                if saved_by == 'org':
                    self.approved_by_donor = not donor_has_users
                    if donor_has_users:
                        email_type = 'donation_unapproved'
                        notification_args = {
                            'donation_id': self.pk,
                            'notify': 'donor',
                            'created': False
                        }
                    else:
                        email_type = 'donor_unclaimed'
                        notification_args = {'donation_id': self.pk}
            super().save(
                *args, **kwargs
            )  # save instance before sending notifications so field values are updated

        if email_type and notification_args:
            pretty = email_type == 'donor_unclaimed'
            EmailNotification.objects.create(
                email_type=email_type,
                args=notification_args,
                wait_hours=24 * 3,
                period_hours=24 * 3,
                target=1,
                pretty=pretty,
            )
            for kwargs_set in notification_function_by_email_type[email_type](
                    **notification_args):
                if pretty:
                    send_pretty_email.delay(**kwargs_set)
                else:
                    send_email.delay(**kwargs_set)