示例#1
0
def notify_comment_followers(comment):
    followers = {}
    kwargs = {
        'content_type': comment.content_type,
        'object_pk': comment.object_pk,
        'is_public': True,
        'followup': True
    }
    previous_comments = XtdComment.objects\
                                  .filter(**kwargs)\
                                  .exclude(user_email=comment.user_email)

    def feed_followers(gen):
        for instance in gen:
            followers[instance.user_email] = (
                instance.user_name,
                signed.dumps(instance,
                             compress=True,
                             extra_key=settings.COMMENTS_XTD_SALT))

    try:
        gen = previous_comments.distinct('user_email').order_by('user_email')
        feed_followers(gen)
    except NotSupportedError:
        feed_followers(previous_comments)

    for instance in previous_comments:
        followers[instance.user_email] = (
            instance.user_name,
            signed.dumps(instance,
                         compress=True,
                         extra_key=settings.COMMENTS_XTD_SALT))

    subject = _("new comment posted")
    text_message_template = loader.get_template(
        "django_comments_xtd/email_followup_comment.txt")
    if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
        html_message_template = loader.get_template(
            "django_comments_xtd/email_followup_comment.html")

    for email, (name, key) in six.iteritems(followers):
        mute_url = reverse('comments-xtd-mute', args=[key.decode('utf-8')])
        message_context = {
            'user_name': name,
            'comment': comment,
            # 'content_object': target,
            'mute_url': mute_url,
            'site': comment.site
        }
        text_message = text_message_template.render(message_context)
        if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
            html_message = html_message_template.render(message_context)
        else:
            html_message = None
        send_mail(subject,
                  text_message,
                  settings.COMMENTS_XTD_FROM_EMAIL, [
                      email,
                  ],
                  html=html_message)
示例#2
0
def send_email_confirmation_request(
        comment,
        target,
        key,
        text_template="django_comments_xtd/email_confirmation_request.txt",
        html_template="django_comments_xtd/email_confirmation_request.html"):
    """Send email requesting comment confirmation"""
    subject = _("comment confirmation request")
    confirmation_url = reverse("comments-xtd-confirm", args=[key])
    message_context = Context({
        'comment': comment,
        'content_object': target,
        'confirmation_url': confirmation_url,
        'contact': settings.DEFAULT_FROM_EMAIL,
        'site': Site.objects.get_current()
    })
    # prepare text message
    text_message_template = loader.get_template(text_template)
    text_message = text_message_template.render(message_context)
    if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
        # prepare html message
        html_message_template = loader.get_template(html_template)
        html_message = html_message_template.render(message_context)
    else:
        html_message = None

    send_mail(subject,
              text_message,
              settings.DEFAULT_FROM_EMAIL, [
                  comment.user_email,
              ],
              html=html_message)
示例#3
0
def notify_comment_followers(comment):
    followers = {}

    previous_comments = XtdComment.objects.filter(
        object_pk=comment.object_pk, is_public=True, 
        followup=True).exclude(id__exact=comment.id)

    for instance in previous_comments:
        followers[instance.user_email] = instance.user_name

    model = models.get_model(comment.content_type.app_label,
                             comment.content_type.model)
    target = model._default_manager.get(pk=comment.object_pk)
    subject = _("new comment posted")
    text_message_template = loader.get_template("django_comments_xtd/email_followup_comment.txt")
    html_message_template = loader.get_template("django_comments_xtd/email_followup_comment.html")

    for email, name in followers.iteritems():
        message_context = Context({ 'user_name': name,
                                    'comment': comment, 
                                    'content_object': target, 
                                    'site': Site.objects.get_current() })
        text_message = text_message_template.render(message_context)
        html_message = html_message_template.render(message_context)
        send_mail(subject, text_message, settings.DEFAULT_FROM_EMAIL, [ email, ], html=html_message)
示例#4
0
def notify_comment_followers(comment):
    followers = {}

    previous_comments = XtdComment.objects.filter(
        object_pk=comment.object_pk, is_public=True, 
        followup=True).exclude(id__exact=comment.id)

    for instance in previous_comments:
        followers[instance.user_email] = instance.user_name

    model = models.get_model(comment.content_type.app_label,
                             comment.content_type.model)
    target = model._default_manager.get(pk=comment.object_pk)
    subject = _("new comment posted")
    text_message_template = loader.get_template("django_comments_xtd/email_followup_comment.txt")
    html_message_template = loader.get_template("django_comments_xtd/email_followup_comment.html")

    for email, name in followers.iteritems():
        message_context = Context({ 'user_name': name,
                                    'comment': comment, 
                                    'content_object': target, 
                                    'site': Site.objects.get_current() })
        text_message = text_message_template.render(message_context)
        html_message = html_message_template.render(message_context)
        send_mail(subject, text_message, settings.DEFAULT_FROM_EMAIL, [ email, ], html=html_message)
示例#5
0
def send_email_confirmation_request(
        comment,
        key,
        site,
        text_template="django_comments_xtd/email_confirmation_request.txt",
        html_template="django_comments_xtd/email_confirmation_request.html"):
    """Send email requesting comment confirmation"""
    subject = _("comment confirmation request")
    confirmation_url = reverse("comments-xtd-confirm",
                               args=[key.decode('utf-8')])
    message_context = {
        'comment': comment,
        'confirmation_url': confirmation_url,
        'contact': settings.COMMENTS_XTD_CONTACT_EMAIL,
        'site': site
    }
    # prepare text message
    text_message_template = loader.get_template(text_template)
    text_message = text_message_template.render(message_context)
    if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
        # prepare html message
        html_message_template = loader.get_template(html_template)
        html_message = html_message_template.render(message_context)
    else:
        html_message = None

    send_mail(subject,
              text_message,
              settings.COMMENTS_XTD_FROM_EMAIL, [
                  comment.user_email,
              ],
              html=html_message)
示例#6
0
def on_job_was_submitted(sender, instance, created=False, **kwargs):
    """
    Notify the jobs board when a new job has been submitted for approval

    """
    # Only send emails for newly created Jobs
    if not created:
        return

    # Only new Jobs in review status should trigger the email
    Job = models.get_model('jobs', 'Job')
    if instance.status != Job.STATUS_REVIEW:
        return

    subject_template = loader.get_template(
        'jobs/email/job_was_submitted_subject.txt')
    message_template = loader.get_template('jobs/email/job_was_submitted.txt')

    message_context = Context({
        'content_object': instance,
        'site': Site.objects.get_current()
    })
    subject = subject_template.render(message_context)
    message = message_template.render(message_context)

    send_mail(subject, message, settings.JOB_FROM_EMAIL, [EMAIL_JOBS_BOARD])
示例#7
0
def on_job_was_submitted(sender, instance, created=False, **kwargs):
    """
    Notify the jobs board when a new job has been submitted for approval

    """
    # Only send emails for newly created Jobs
    if not created:
        return

    # Skip in fixtures
    if kwargs.get('raw', False):
        return

    # Only new Jobs in review status should trigger the email
    Job = models.get_model('jobs', 'Job')
    if instance.status != Job.STATUS_REVIEW:
        return

    subject_template = loader.get_template('jobs/email/job_was_submitted_subject.txt')
    message_template = loader.get_template('jobs/email/job_was_submitted.txt')

    message_context = Context({'content_object': instance,
                               'site': Site.objects.get_current()})
    subject = subject_template.render(message_context)
    message = message_template.render(message_context)

    send_mail(subject, message, settings.JOB_FROM_EMAIL,
              [EMAIL_JOBS_BOARD])
示例#8
0
def notify_comment_followers(comment):
    followers = {}

    kwargs = {
        'content_type': comment.content_type,
        'object_pk': comment.object_pk,
        'is_public': True,
        'followup': True
    }
    previous_comments = XtdComment.objects\
                                  .filter(**kwargs)\
                                  .exclude(user_email=comment.user_email)

    for instance in previous_comments:
        followers[instance.user_email] = (
            instance.user_name,
            signed.dumps(instance,
                         compress=True,
                         extra_key=settings.COMMENTS_XTD_SALT))

    model = get_model(comment.content_type.app_label,
                      comment.content_type.model)
    target = model._default_manager.get(pk=comment.object_pk)
    subject = _("new comment posted")
    text_message_template = loader.get_template(
        "django_comments_xtd/email_followup_comment.txt")
    if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
        html_message_template = loader.get_template(
            "django_comments_xtd/email_followup_comment.html")

    for email, (name, key) in six.iteritems(followers):
        mute_url = reverse('comments-xtd-mute', args=[key])
        message_context = Context({
            'user_name': name,
            'comment': comment,
            'content_object': target,
            'mute_url': mute_url,
            'site': comment.site
        })
        text_message = text_message_template.render(message_context)
        if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
            html_message = html_message_template.render(message_context)
        else:
            html_message = None
        send_mail(subject,
                  text_message,
                  settings.COMMENTS_XTD_FROM_EMAIL, [
                      email,
                  ],
                  html=html_message)
示例#9
0
def on_job_was_submitted(sender, job, **kwargs):
    """
    Notify the jobs board when a new job has been submitted for approval

    """
    subject_template = loader.get_template('jobs/email/job_was_submitted_subject.txt')
    message_template = loader.get_template('jobs/email/job_was_submitted.txt')

    message_context = Context({'content_object': job,
                               'site': Site.objects.get_current()})
    subject = subject_template.render(message_context)
    message = message_template.render(message_context)

    send_mail(subject, message, settings.JOB_FROM_EMAIL,
              [EMAIL_JOBS_BOARD])
示例#10
0
 def notify_removal_suggestion(self, comment, content_object, request):
     if not self.removal_suggestion_notification:
         return
     recipient_list = [manager_tuple[1]
                       for manager_tuple in settings.MANAGERS]
     t = loader.get_template('django_comments_xtd/'
                             'removal_notification_email.txt')
     c = {'comment': comment,
          'content_object': content_object,
          'current_site': get_current_site(request),
          'request': request}
     subject = ('[%s] Comment removal suggestion on "%s"' %
                (c['current_site'].name, content_object))
     message = t.render(Context(c) if VERSION < (1, 8) else c)
     send_mail(subject, message, settings.COMMENTS_XTD_FROM_EMAIL,
               recipient_list, fail_silently=True)
示例#11
0
 def notify_removal_suggestion(self, comment, content_object, request):
     if not self.removal_suggestion_notification:
         return
     recipient_list = [manager_tuple[1]
                       for manager_tuple in settings.MANAGERS]
     t = loader.get_template('django_comments_xtd/'
                             'removal_notification_email.txt')
     c = {'comment': comment,
          'content_object': content_object,
          'current_site': get_current_site(request),
          'request': request}
     subject = ('[%s] Comment removal suggestion on "%s"' %
                (c['current_site'].name, content_object))
     message = t.render(Context(c) if VERSION < (1, 8) else c)
     send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
               recipient_list, fail_silently=True)
示例#12
0
def send_job_review_message(job, user, subject_template_path,
                            message_template_path):
    """Helper function wrapping logic of sending the review message concerning
    a job.

    `user` param holds user that performed the review action.
    """
    subject_template = loader.get_template(subject_template_path)
    message_template = loader.get_template(message_template_path)
    reviewer_name = '{} {}'.format(user.first_name, user.last_name)
    message_context = Context({'addressee': job.contact,
                               'reviewer_name': reviewer_name,
                              })
    # subject can't contain newlines, thus strip() call
    subject = subject_template.render(message_context).strip()
    message = message_template.render(message_context)
    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [job.email])
示例#13
0
def send_job_review_message(job, user, subject_template_path,
                            message_template_path):
    """Helper function wrapping logic of sending the review message concerning
    a job.

    `user` param holds user that performed the review action.
    """
    subject_template = loader.get_template(subject_template_path)
    message_template = loader.get_template(message_template_path)
    reviewer_name = '{} {}'.format(user.first_name, user.last_name)
    message_context = Context({
        'addressee': job.contact,
        'reviewer_name': reviewer_name,
    })
    # subject can't contain newlines, thus strip() call
    subject = subject_template.render(message_context).strip()
    message = message_template.render(message_context)
    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [job.email])
示例#14
0
def send_email_confirmation_request(comment, target, key, text_template="django_comments_xtd/email_confirmation_request.txt", html_template="django_comments_xtd/email_confirmation_request.html"):
    """Send email requesting comment confirmation"""
    subject = _("comment confirmation request")
    confirmation_url = reverse("comments-xtd-confirm", args=[key])
    message_context = Context({ 'comment': comment, 
                                'content_object': target, 
                                'confirmation_url': confirmation_url,
                                'contact': settings.DEFAULT_FROM_EMAIL,
                                'site': Site.objects.get_current() })
    # prepare text message
    text_message_template = loader.get_template(text_template)
    text_message = text_message_template.render(message_context)
    # prepare html message
    html_message_template = loader.get_template(html_template)
    html_message = html_message_template.render(message_context)

    send_mail(subject, text_message, settings.DEFAULT_FROM_EMAIL,
              [ comment.user_email, ], html=html_message)
示例#15
0
def on_comment_was_posted(sender, comment, request, **kwargs):
    """
    Notify the author of the post when the first comment has been posted.

    Further comments subscribe automatically because our custom forms at
    `.forms.JobCommentForm` forces `follow_up` to `True` and Django-comments-xtd
    will already notify followers.
    """
    Job = models.get_model('jobs', 'Job')

    # Skip if this is not a 'first comment'
    if comment.level > 0 or comment.order > 1:
        return False

    # RSkip if we're not commenting on a Job
    model = comment.content_type.model_class()
    if model != Job:
        return False

    job = model._default_manager.get(pk=comment.object_pk)

    email = job.email
    name = job.contact

    subject = _("new comment posted")
    text_message_template = loader.get_template(
        "django_comments_xtd/email_job_added_comment.txt")
    html_message_template = loader.get_template(
        "django_comments_xtd/email_job_added_comment.html")

    message_context = Context({
        'user_name': name,
        'comment': comment,
        'content_object': job,
        'site': Site.objects.get_current()
    })
    text_message = text_message_template.render(message_context)
    html_message = html_message_template.render(message_context)
    send_mail(subject,
              text_message,
              settings.DEFAULT_FROM_EMAIL, [
                  email,
              ],
              html=html_message)
示例#16
0
def notify_comment_followers(comment):
    followers = {}

    kwargs = {'content_type': comment.content_type,
              'object_pk': comment.object_pk,
              'is_public': True,
              'followup': True}
    previous_comments = XtdComment.objects\
                                  .filter(**kwargs)\
                                  .exclude(user_email=comment.user_email)

    for instance in previous_comments:
        followers[instance.user_email] = (
            instance.user_name,
            signed.dumps(instance, compress=True,
                         extra_key=settings.COMMENTS_XTD_SALT))

    model = get_model(comment.content_type.app_label,
                      comment.content_type.model)
    target = model._default_manager.get(pk=comment.object_pk)
    subject = _("new comment posted")
    text_message_template = loader.get_template(
        "django_comments_xtd/email_followup_comment.txt")
    if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
        html_message_template = loader.get_template(
            "django_comments_xtd/email_followup_comment.html")

    for email, (name, key) in six.iteritems(followers):
        mute_url = reverse('comments-xtd-mute', args=[key])
        message_context = Context({'user_name': name,
                                   'comment': comment,
                                   'content_object': target,
                                   'mute_url': mute_url,
                                   'site': Site.objects.get_current()})
        text_message = text_message_template.render(message_context)
        if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
            html_message = html_message_template.render(message_context)
        else:
            html_message = None
        send_mail(subject, text_message, settings.COMMENTS_XTD_FROM_EMAIL,
                  [email, ], html=html_message)
示例#17
0
def send_job_review_message(job, user, subject_template_path,
                            message_template_path):
    """Helper function wrapping logic of sending the review message concerning
    a job.

    `user` param holds user that performed the review action.
    """
    subject_template = loader.get_template(subject_template_path)
    message_template = loader.get_template(message_template_path)
    if user.first_name or user.last_name:
        reviewer_name = '{} {}'.format(user.first_name, user.last_name)
    else:
        reviewer_name = 'Community Reviewer'
    message_context = Context({'reviewer_name': reviewer_name,
                               'content_object': job,
                               'site': Site.objects.get_current(),
                              })
    # subject can't contain newlines, thus strip() call
    subject = subject_template.render(message_context).strip()
    message = message_template.render(message_context)
    send_mail(subject, message, settings.JOB_FROM_EMAIL,
              [job.email, EMAIL_JOBS_BOARD])
示例#18
0
def on_comment_was_posted(sender, comment, request, **kwargs):
    """
    Notify the author of the post when the first comment has been posted.

    Further comments subscribe automatically because our custom forms at
    `.forms.JobCommentForm` forces `follow_up` to `True` and Django-comments-xtd
    will already notify followers.
    """
    # Skip if this is not a 'first comment'
    if comment.level > 0 or comment.order > 1:
        return False

    # Skip if we're not commenting on a Job
    Job = models.get_model('jobs', 'Job')
    model = comment.content_type.model_class()
    if model != Job:
        return False

    job = model._default_manager.get(pk=comment.object_pk)
    email = job.email
    name = job.contact or 'Job Submitter'
    reviewer_name = comment.name or 'Community Reviewer'

    subject = _("Python Job Board: Review comment for: {}").format(
        job.display_name)
    text_message_template = loader.get_template("django_comments_xtd/email_job_added_comment.txt")
    html_message_template = loader.get_template("django_comments_xtd/email_job_added_comment.html")

    message_context = Context({ 'user_name': name,
                                'reviewer_name': reviewer_name,
                                'comment': comment,
                                'content_object': job,
                                'site': Site.objects.get_current() })
    text_message = text_message_template.render(message_context)
    html_message = html_message_template.render(message_context)
    send_mail(subject, text_message, settings.JOB_FROM_EMAIL,
              [email, EMAIL_JOBS_BOARD], html=html_message)
示例#19
0
def send_email_confirmation_request(
        comment, key, site,
        text_template="django_comments_xtd/email_confirmation_request.txt",
        html_template="django_comments_xtd/email_confirmation_request.html"):
    """Send email requesting comment confirmation"""
    subject = _("comment confirmation request")
    confirmation_url = reverse("comments-xtd-confirm",
                               args=[key.decode('utf-8')])
    message_context = {'comment': comment,
                       'confirmation_url': confirmation_url,
                       'contact': settings.COMMENTS_XTD_CONTACT_EMAIL,
                       'site': site}
    # prepare text message
    text_message_template = loader.get_template(text_template)
    text_message = text_message_template.render(message_context)
    if settings.COMMENTS_XTD_SEND_HTML_EMAIL:
        # prepare html message
        html_message_template = loader.get_template(html_template)
        html_message = html_message_template.render(message_context)
    else:
        html_message = None

    send_mail(subject, text_message, settings.COMMENTS_XTD_FROM_EMAIL,
              [comment.user_email, ], html=html_message)