def email_confirmation_code(self, url):
     """Send a confirmation email to the user after registering."""
     context = {'confirmation_url': url}
     subjects, bodies = localize_email(
         'users/emails/registration_confirm_subject.txt',
         'users/emails/registration_confirm.txt', context)
     tasks.SendUserEmail.apply_async(args=(self, subjects, bodies))
Exemple #2
0
 def email_confirmation_code(self, url):
     """Send a confirmation email to the user after registering."""
     context = {'confirmation_url': url}
     subjects, bodies = localize_email(
         'users/emails/registration_confirm_subject.txt',
         'users/emails/registration_confirm.txt', context)
     tasks.SendUserEmail.apply_async(args=(self, subjects, bodies))
Exemple #3
0
    def run(self,
            profiles,
            subject_template,
            body_template,
            context,
            reply_token=None,
            sender=None,
            **kwargs):
        log = self.get_logger(**kwargs)
        subjects, bodies = localize_email(subject_template, body_template,
                                          context)

        from_name = "P2PU Notifications"
        if sender:
            from_name = sender

        from_email = "{0} <{1}>".format(from_name, settings.DEFAULT_FROM_EMAIL)
        if reply_token:
            from_email = "{0} <reply+{1}@{2}>".format(
                from_name, reply_token, settings.REPLY_EMAIL_DOMAIN)

        for profile in profiles:
            if profile.deleted:
                continue
            subject = subjects[profile.preflang]
            body = bodies[profile.preflang]
            log.debug("Sending email to user %d with subject %s" % (
                profile.user.id,
                subject,
            ))
            email = EmailMessage(subject, body, from_email,
                                 [profile.user.email])
            email.send()
Exemple #4
0
def send_new_signup_answer_notification(answer):
    context = {
        'answer': answer,
        'domain': Site.objects.get_current().domain,
    }
    subjects, bodies = localize_email(
        'signups/emails/new_signup_answer_subject.txt',
        'signups/emails/new_signup_answer.txt', context)
    for organizer in answer.sign_up.project.organizers():
        SendUserEmail.apply_async((organizer.user,
            subjects, bodies))
Exemple #5
0
 def send_notification(self):
     """Send notification when a new submission is posted."""
     context = {
         'submission': self,
         'domain': Site.objects.get_current().domain,
     }
     subjects, bodies = localize_email(
         'badges/emails/new_submission_subject.txt',
         'badges/emails/new_submission.txt', context)
     for adopter in self.badge.get_adopters():
         SendUserEmail.apply_async((adopter.user, subjects, bodies))
Exemple #6
0
 def run(self, profiles, subject_template, body_template, context, **kwargs):
     log = self.get_logger(**kwargs)
     subjects, bodies = localize_email(subject_template,
         body_template, context)
     for profile in profiles:
         if profile.deleted:
             continue
         subject = subjects[profile.preflang]
         body = bodies[profile.preflang]
         log.debug("Sending email to user %d with subject %s" % (
             profile.user.id, subject,))
         profile.user.email_user(subject, body)
Exemple #7
0
 def send_comment_notification(self):
     context = {
         'comment': self,
         'domain': Site.objects.get_current().domain,
     }
     subjects, bodies = localize_email(
         'replies/emails/post_comment_subject.txt',
         'replies/emails/post_comment.txt', context)
     recipients = self.page_object.comment_notification_recipients(self)
     for recipient in recipients:
         if self.author != recipient:
             SendUserEmail.apply_async((recipient, subjects, bodies))
Exemple #8
0
 def send_creation_notification(self):
     """Send notification when a new project is created."""
     context = {"project": self, "domain": Site.objects.get_current().domain}
     subjects, bodies = localize_email(
         "projects/emails/project_created_subject.txt", "projects/emails/project_created.txt", context
     )
     for organizer in self.organizers():
         SendUserEmail.apply_async((organizer.user, subjects, bodies))
     admin_subject = render_to_string("projects/emails/admin_project_created_subject.txt", context).strip()
     admin_body = render_to_string("projects/emails/admin_project_created.txt", context).strip()
     for admin_email in settings.ADMIN_PROJECT_CREATE_EMAIL:
         send_mail(admin_subject, admin_body, admin_email, [admin_email], fail_silently=True)
 def send_comment_notification(self):
     context = {
         'comment': self,
         'domain': Site.objects.get_current().domain,
     }
     subjects, bodies = localize_email(
         'replies/emails/post_comment_subject.txt',
         'replies/emails/post_comment.txt', context)
     recipients = self.page_object.comment_notification_recipients(self)
     for recipient in recipients:
         if self.author != recipient:
             SendUserEmail.apply_async((recipient, subjects, bodies))
Exemple #10
0
    def run(self, profiles, subject_template, body_template, context, sender, **kwargs):
        log = self.get_logger(**kwargs)
        subjects, bodies = localize_email(subject_template,
            body_template, context)

        for profile in profiles:
            if profile.deleted:
                continue
            subject = subjects[profile.preflang]
            body = bodies[profile.preflang]
            log.debug(u"Sending email to %s with subject %s" % (
                profile.user.username, subject,))
            email = EmailMessage(subject, body, sender, [profile.user.email])
            email.send()
Exemple #11
0
def send_email_notification(instance):
    project = instance.project
    if not instance.listed:
        return
    context = {"instance": instance, "project": project, "domain": Site.objects.get_current().domain}
    subjects, bodies = localize_email(
        "content/emails/content_update_subject.txt", "content/emails/content_update.txt", context
    )
    from_organizer = project.organizers().filter(user=instance.author).exists()
    for participation in project.participants():
        is_author = instance.author == participation.user
        if from_organizer:
            unsubscribed = participation.no_organizers_content_updates
        else:
            unsubscribed = participation.no_participants_content_updates
        if not is_author and not unsubscribed:
            SendUserEmail.apply_async((participation.user, subjects, bodies))
Exemple #12
0
def send_email_notification(instance):
    project = instance.project
    if not instance.listed:
        return
    context = {
        'instance': instance,
        'project': project,
        'domain': Site.objects.get_current().domain,
    }
    subjects, bodies = localize_email(
        'content/emails/content_update_subject.txt',
        'content/emails/content_update.txt', context)
    for participation in project.participants():
        is_author = (instance.author == participation.user)
        if not is_author and not participation.no_updates:
            SendUserEmail.apply_async(
                    (participation.user, subjects, bodies))
Exemple #13
0
    def run(self, profiles, subject_template, body_template, context, sender,
            **kwargs):
        log = self.get_logger(**kwargs)
        subjects, bodies = localize_email(subject_template, body_template,
                                          context)

        for profile in profiles:
            if profile.deleted:
                continue
            subject = subjects[profile.preflang]
            body = bodies[profile.preflang]
            log.debug(u"Sending email to %s with subject %s" % (
                profile.user.username,
                subject,
            ))
            email = EmailMessage(subject, body, sender, [profile.user.email])
            email.send()
Exemple #14
0
 def run(self, profiles, subject_template, body_template, context, reply_token=None, **kwargs):
     log = self.get_logger(**kwargs)
     subjects, bodies = localize_email(subject_template,
         body_template, context)
         
     from_email = "P2PU Notifications <{0}>".format(settings.DEFAULT_FROM_EMAIL)
     if reply_token:
         from_email = "P2PU Notifications <reply+{0}@{1}>".format(reply_token,
             settings.REPLY_EMAIL_DOMAIN)
         
     for profile in profiles:
         if profile.deleted:
             continue
         subject = subjects[profile.preflang]
         body = bodies[profile.preflang]
         log.debug("Sending email to user %d with subject %s" % (
             profile.user.id, subject,))
         profile.user.email_user(subject, body, from_email)
Exemple #15
0
 def send_creation_notification(self):
     """Send notification when a new project is created."""
     context = {
         'project': self,
         'domain': Site.objects.get_current().domain,
     }
     subjects, bodies = localize_email(
         'projects/emails/project_created_subject.txt',
         'projects/emails/project_created.txt', context)
     for organizer in self.organizers():
         SendUserEmail.apply_async((organizer.user, subjects, bodies))
     admin_subject = render_to_string(
         "projects/emails/admin_project_created_subject.txt",
         context).strip()
     admin_body = render_to_string(
         "projects/emails/admin_project_created.txt", context).strip()
     for admin_email in settings.ADMIN_PROJECT_CREATE_EMAIL:
         send_mail(admin_subject, admin_body, admin_email,
             [admin_email], fail_silently=True)
Exemple #16
0
def send_email_notification(instance):
    project = instance.project
    if not instance.listed:
        return
    context = {
        'instance': instance,
        'project': project,
        'domain': Site.objects.get_current().domain,
    }
    subjects, bodies = localize_email(
        'content/emails/content_update_subject.txt',
        'content/emails/content_update.txt', context)
    from_organizer = project.organizers().filter(user=instance.author).exists()
    for participation in project.participants():
        is_author = (instance.author == participation.user)
        if from_organizer:
            unsubscribed = participation.no_organizers_content_updates
        else:
            unsubscribed = participation.no_participants_content_updates
        if not is_author and not unsubscribed:
            SendUserEmail.apply_async((participation.user, subjects, bodies))
Exemple #17
0
def follow_handler(sender, **kwargs):
    rel = kwargs.get('instance', None)
    created = kwargs.get('created', False)
    if not created or not isinstance(rel, Relationship) or rel.deleted:
        return
    activity = Activity(actor=rel.source,
                        verb=verbs['follow'],
                        target_object=rel)
    receipts = []
    if rel.target_user:
        preferences = AccountPreferences.objects.filter(
            user=rel.target_user, key='no_email_new_follower')
        for pref in preferences:
            if pref.value:
                break
        else:
            receipts.append(rel.target_user)
    else:
        activity.scope_object = rel.target_project
        for organizer in rel.target_project.organizers():
            if organizer.user != rel.source:
                preferences = AccountPreferences.objects.filter(
                    user=organizer.user, key='no_email_new_project_follower')
                for pref in preferences:
                    if pref.value:
                        break
                else:
                    receipts.append(organizer.user)
    activity.save()
    context = {
        'user': rel.source,
        'project': rel.target_project,
        'domain': Site.objects.get_current().domain
    }
    subjects, bodies = localize_email(
        'relationships/emails/new_follower_subject.txt',
        'relationships/emails/new_follower.txt', context)
    for user in receipts:
        SendUserEmail.apply_async((user, subjects, bodies))
Exemple #18
0
def report_abuse(request, model, app_label, pk):
    """Report abusive or irrelavent content."""
    if request.method == 'POST':
        # we only use the form for the csrf middleware. skip validation.
        form = AbuseForm(request.POST)
        content_type_cls = get_object_or_404(
            ContentType, model=model, app_label=app_label).model_class()
        instance = get_object_or_404(content_type_cls, pk=pk)
        try:
            url = request.build_absolute_uri(instance.get_absolute_url())
        except NoReverseMatch:
            url = request.build_absolute_uri(reverse('dashboard'))
        context = {
            'user': request.user.get_profile(),
            'url': url,
            'model': model,
            'app_label': app_label,
            'pk': pk,
        }
        subjects, bodies = localize_email(
            'drumbeat/emails/abuse_report_subject.txt',
            'drumbeat/emails/abuse_report.txt', context)
        try:
            profile = UserProfile.objects.get(email=settings.ADMINS[0][1])
            SendUserEmail.apply_async(args=(profile, subjects, bodies))
        except:
            log.debug("Error sending abuse report: %s" % sys.exc_info()[0])
            pass
        return render_to_response('drumbeat/report_received.html', {},
                                  context_instance=RequestContext(request))
    else:
        form = AbuseForm()
    return render_to_response('drumbeat/report_abuse.html', {
        'form': form,
        'model': model,
        'app_label': app_label,
        'pk': pk,
    },
                              context_instance=RequestContext(request))
Exemple #19
0
def message_sent_handler(sender, **kwargs):
    message = kwargs.get("instance", None)
    created = kwargs.get("created", False)
    if not created or not isinstance(message, Message):
        return
    recipient = message.recipient.get_profile()
    preferences = AccountPreferences.objects.filter(user=recipient, key="no_email_message_received")
    for preference in preferences:
        if preference.value:
            return
    sender = message.sender.get_profile()
    reply_url = reverse("drumbeatmail_reply", kwargs={"message": message.pk})
    msg_body = clean_html("rich", message.body)
    context = {
        "sender": sender,
        "message": msg_body,
        "domain": Site.objects.get_current().domain,
        "reply_url": reply_url,
    }
    subjects, bodies = localize_email(
        "drumbeatmail/emails/direct_message_subject.txt", "drumbeatmail/emails/direct_message.txt", context
    )
    SendUserEmail.apply_async((recipient, subjects, bodies))
Exemple #20
0
 def send_wall_notification(self):
     if not self.project:
         return
     context = {
         'status': self,
         'project': self.project,
         'domain': Site.objects.get_current().domain,
     }
     subjects, bodies = localize_email(
         'statuses/emails/wall_updated_subject.txt',
         'statuses/emails/wall_updated.txt', context)
     from_organizer = self.project.organizers().filter(
         user=self.author).exists()
     for participation in self.project.participants():
         if self.important:
             unsubscribed = False
         elif from_organizer:
             unsubscribed = participation.no_organizers_wall_updates
         else:
             unsubscribed = participation.no_participants_wall_updates
         if self.author != participation.user and not unsubscribed:
             SendUserEmail.apply_async(
                 (participation.user, subjects, bodies))
Exemple #21
0
    def run(self, profiles, subject_template, body_template, context, reply_token=None, sender=None, **kwargs):
        log = self.get_logger(**kwargs)
        subjects, bodies = localize_email(subject_template,
            body_template, context)

        from_name = "P2PU Notifications"
        if sender:
            from_name = sender
            
        from_email = "{0} <{1}>".format(from_name, settings.DEFAULT_FROM_EMAIL)
        if reply_token:
            from_email = "{0} <reply+{1}@{2}>".format(from_name, reply_token,
                settings.REPLY_EMAIL_DOMAIN)
            
        for profile in profiles:
            if profile.deleted:
                continue
            subject = subjects[profile.preflang]
            body = bodies[profile.preflang]
            log.debug("Sending email to user %d with subject %s" % (
                profile.user.id, subject,))
            email = EmailMessage(subject, body, from_email, [profile.user.email])
            email.send()
Exemple #22
0
def report_abuse(request, model, app_label, pk):
    """Report abusive or irrelavent content."""
    if request.method == 'POST':
        # we only use the form for the csrf middleware. skip validation.
        form = AbuseForm(request.POST)
        content_type_cls = get_object_or_404(ContentType, model=model,
            app_label=app_label).model_class()
        instance = get_object_or_404(content_type_cls, pk=pk)
        try:
            url = request.build_absolute_uri(instance.get_absolute_url())
        except NoReverseMatch:
            url = request.build_absolute_uri(reverse('dashboard'))
        context = {
            'user': request.user.get_profile(),
            'url': url, 'model': model,
            'app_label': app_label, 'pk': pk,
        }
        subjects, bodies = localize_email(
            'drumbeat/emails/abuse_report_subject.txt',
            'drumbeat/emails/abuse_report.txt', context)
        try:
            profile = UserProfile.objects.get(email=settings.ADMINS[0][1])
            SendUserEmail.apply_async(args=(profile, subjects, bodies))
        except:
            log.debug("Error sending abuse report: %s" % sys.exc_info()[0])
            pass
        return render_to_response('drumbeat/report_received.html', {},
                                  context_instance=RequestContext(request))
    else:
        form = AbuseForm()
    return render_to_response('drumbeat/report_abuse.html', {
        'form': form,
        'model': model,
        'app_label': app_label,
        'pk': pk,
    }, context_instance=RequestContext(request))
Exemple #23
0
def message_sent_handler(sender, **kwargs):
    message = kwargs.get('instance', None)
    created = kwargs.get('created', False)
    if not created or not isinstance(message, Message):
        return
    recipient = message.recipient.get_profile()
    preferences = AccountPreferences.objects.filter(
        user=recipient, key='no_email_message_received')
    for preference in preferences:
        if preference.value:
            return
    sender = message.sender.get_profile()
    reply_url = reverse('drumbeatmail_reply', kwargs={'message': message.pk})
    msg_body = clean_html('rich', message.body)
    context = {
        'sender': sender,
        'message': msg_body,
        'domain': Site.objects.get_current().domain,
        'reply_url': reply_url,
    }
    subjects, bodies = localize_email(
        'drumbeatmail/emails/direct_message_subject.txt',
        'drumbeatmail/emails/direct_message.txt', context)
    SendUserEmail.apply_async((recipient, subjects, bodies))