Beispiel #1
0
    def test_translated_mail_subject(self):
        self.user_a.primary_language = 'en'
        self.user_a.save()

        send_mail(
            template_name='project_wallpost_reaction_new.mail',
            subject=_('Username'),
            obj=self.project,
            to=self.user_a,
            author=self.user_b
        )

        self.assertEqual(len(mail.outbox), 1)
        mail_message = mail.outbox[0]

        self.assertEquals(mail_message.subject, 'Username')

        self.user_a.primary_language = 'nl'
        self.user_a.save()

        send_mail(
            template_name='project_wallpost_reaction_new.mail',
            subject=_('Username'),
            obj=self.project,
            to=self.user_a,
            author=self.user_b
        )

        self.assertEqual(len(mail.outbox), 2)
        mail_message = mail.outbox[1]

        self.assertEquals(mail_message.subject, 'Gebruikersnaam')
Beispiel #2
0
def mail_new_oneoff_donation(donation):
    if donation.user:
        name = donation.user.first_name
    else:
        name = _('Anonymous')

    if donation.fundraiser:
        send_mail(
            template_name='new_oneoff_donation_fundraiser.mail',
            subject=_('You received a new donation'),
            to=donation.fundraiser.owner,

            amount=(donation.amount / 100.0),
            donor_name=name,
            link='/go/fundraisers/{0}'.format(donation.fundraiser.id),
        )
    # Always email the project owner.
    send_mail(
        template_name='new_oneoff_donation.mail',
        subject=_('You received a new donation'),
        to=donation.project.owner,

        amount=(donation.amount / 100.0),
        donor_name=name,
        link='/go/projects/{0}'.format(donation.project.slug),
    )
def new_oneoff_donation(sender, instance, **kwargs):
    """
    Send project owner a mail if a new "one off" donation is done. We consider a donation done if the status is pending.
    """
    donation = instance

    # Only process the donation if it is of type "one off".
    if donation.donation_type != Donation.DonationTypes.one_off:
        return

    # If the instance has no PK the previous status is unknown.
    if donation.pk:
        # NOTE: We cannot check the previous and future state of the ready attribute since it is set in the
        # Donation.save function.

        existing_donation = Donation.objects.get(pk=donation.pk)
        # If the existing donation is already pending, don't mail.
        if existing_donation.status in [DonationStatuses.pending, DonationStatuses.paid]:
            return

    # If the donation status will be pending, send a mail.
    if donation.status in [DonationStatuses.pending, DonationStatuses.paid]:

        name = _('Anonymous')

        if donation.user:
            if donation.user.first_name != '':
                name = donation.user.first_name

        if donation.fundraiser:
            send_mail(
                template_name='new_oneoff_donation_fundraiser.mail',
                subject=_('You received a new donation'),
                to=donation.fundraiser.owner,

                amount=(donation.amount / 100.0),
                donor_name=name,
                link='/go/fundraisers/{0}'.format(donation.fundraiser.id),
            )
        # Always email the project owner.
        send_mail(
            template_name='new_oneoff_donation.mail',
            subject=_('You received a new donation'),
            to=donation.project.owner,

            amount=(donation.amount / 100.0),
            donor_name=name,
            link='/go/projects/{0}'.format(donation.project.slug),
        )
Beispiel #4
0
def new_wallpost_notification(sender, instance, created, **kwargs):
    post = instance

    site = 'https://' + Site.objects.get_current().domain

    # Project Wall Post
    if isinstance(post.content_object, Project):
        project = post.content_object
        project_owner = project.owner
    
        post_author = post.author

        # Implement 1a: send email to Object owner, if Wallpost author is not the Object owner.
        if post_author != project_owner:
            send_mail(
                template_name='project_wallpost_new.mail',
                subject=_('%(author)s has left a message on your project page.') % {'author': post_author.first_name},
                to=project_owner,

                project=project,
                link='/go/projects/{0}'.format(project.slug),
                author=post_author
            )

    # Task Wall Post
    if isinstance(post.content_object, Task):
        task = post.content_object
        receiver = task.author
        author = post.author

        link = '/go/projects/{0}/tasks/{1}'.format(task.project.slug, task.id)

        # Compose the mail
        translation.activate(receiver.primary_language)
        subject = _('%(author)s has left a message on your task page.') % {'author': author.first_name}
        context = Context({'task': task, 'receiver': receiver, 'author': author, 'link': link, 'site': site})
        text_content = get_template('task_wallpost_new.mail.txt').render(context)
        html_content = get_template('task_wallpost_new.mail.html').render(context)
        translation.deactivate()

        msg = EmailMultiAlternatives(subject=subject, body=text_content, to=[receiver.email])
        msg.attach_alternative(html_content, "text/html")
        msg.send()
Beispiel #5
0
def new_reaction_notification(sender, instance, created, **kwargs):
    reaction = instance
    post = instance.wallpost

    # Project Wall Post
    if isinstance(post.content_object, Project):
        project = post.content_object
        project_owner = project.owner

        post_author = post.author
        reaction_author = reaction.author

        # Make sure users only get mailed once!
        mailed_users = set()
    
        # Implement 2c: send email to other Reaction authors that are not the Object owner or the post author.
        reactions = post.reactions.exclude(Q(author=post_author) | Q(author=project_owner) | Q(author=reaction_author))
        for r in reactions:
            if r.author not in mailed_users:
                send_mail(
                    template_name='project_wallpost_reaction_same_wallpost.mail',
                    subject=_('%(author)s commented on a post you reacted on.') % {'author': reaction_author.first_name},
                    to=r.author,

                    project=project,
                    link='/go/projects/{0}'.format(project.slug),
                    author=reaction_author
                )
                mailed_users.add(r.author)

        # Implement 2b: send email to post author, if Reaction author is not the post author.
        if reaction_author != post_author:
            if reaction_author not in mailed_users and post_author:
                send_mail(
                    template_name='project_wallpost_reaction_new.mail',
                    subject=_('%(author)s commented on your post.') % {'author': reaction_author.first_name},
                    to=post_author,

                    project=project,
                    link='/go/projects/{0}'.format(project.slug),
                    author=reaction_author
                )
                mailed_users.add(post_author)

        # Implement 2a: send email to Object owner, if Reaction author is not the Object owner.
        if reaction_author != project_owner:
            if project_owner not in mailed_users:
                send_mail(
                    template_name='project_wallpost_reaction_project.mail',
                    subject=_('%(author)s commented on your project page.') % {'author': reaction_author.first_name},
                    to=project_owner,
                    author=reaction_author
                )