Exemplo n.º 1
0
 def reset_password_email(self):
     subject = 'Reset your password'
     body = """
     <a href="{}/establish?token={}&email={}" target="_blank">Click here to reset your password</a>.<br><br>
     If you don't want to reset your password you can delete this email.<br><br>
     """.format(os.getenv('CUSTOM_SITE_URL'), self.set_password_token,
                self.email)
     send_email.delay([self.email], subject, body)
Exemplo n.º 2
0
 def activate_account_email(self):
     subject = 'Activate your account'
     body = """Thank you for creating your account!<br><br>
     Click on this link to active your account:<br><br>
     <a href="{}/establish?token={}&email={}&created=true" target="_blank">Activate your account</a>
     """.format(os.getenv('CUSTOM_SITE_URL'), self.set_password_token,
                self.email)
     send_email.delay([self.email], subject, body)
Exemplo n.º 3
0
 def reset_password_email(self):
     subject = 'Restablecer tu contraseña de donador Brigada'
     body = """
     <a href="{}/establecer?token={}&email={}&type=donor" target="_blank">Haz clic aquí para restablecer tu contraseña de donador</a>.<br><br>
     Si no pediste restablecer tu contraseña puedes borrar este mail.<br><br>
     """.format(os.getenv('CUSTOM_SITE_URL'), self.set_password_token,
                self.email)
     send_email.delay([self.email], subject, body)
Exemplo n.º 4
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}
Exemplo n.º 5
0
    def post(self, request, *args, **kwargs):
        serializer = SupportTicketSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        email = serializer.validated_data['email']
        phone = serializer.validated_data['phone']
        name = serializer.validated_data['name']
        reason = serializer.validated_data['reason']
        meta = serializer.validated_data['meta']

        body = """Support request from{}:<br><br>
        name: {}<br>
        email: {}<br>
        phone: {}<br><br>
        {}
        """.format(f' {meta}' if meta else '', name, email, phone, reason)

        send_email.delay(
            ['*****@*****.**'],
            f'Support Request - {name}, {email}',
            body,
            'Brigada Support <*****@*****.**>',
        )
        return Response({}, status=200)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def send_notify_admin_created_email(self):
     subject = 'Nuevo usuario de donador'
     body = 'Nuevo usuario {} {} con email {}, para donador {} con id {}, esperando aprobación.'.format(
         self.first_name, self.surnames, self.email, self.donor.name,
         self.donor.id)
     send_email.delay(['*****@*****.**'], subject, body)