8000 Stop using django.contrib.comments and django_comments_xtd by berkerpeksag · Pull Request #981 · python/pythondotorg · GitHub
[go: up one dir, main page]

Skip to content

Stop using django.contrib.comments and django_comments_xtd #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't send email to job submitter for their own comment
  • Loading branch information
berkerpeksag committed Aug 6, 2017
commit 07bf6a1c6b72e735b23f5f52121a918daf27d60e
44 changes: 33 additions & 11 deletions jobs/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,44 @@ def on_comment_was_posted(sender, comment, **kwargs):
if not comment.comment:
return False
job = comment.job
email = job.email
name = job.contact or 'Job Submitter'
reviewer_name = comment.creator.get_full_name() or comment.creator.username or 'Community Reviewer'
if job.creator is None:
name = job.contact or 'Job Submitter'
else:
name = (
job.creator.get_full_name() or job.creator.get_username() or
job.contact or 'Job Submitter'
)
send_to = [EMAIL_JOBS_BOARD]
reviewer_name = (
comment.creator.get_full_name() or comment.creator.get_username() or
'Community Reviewer'
)
is_job_board_admin = job.creator.email != comment.creator.email
context = {
'comment': comment.comment.raw,
'content_object': job,
'site': Site.objects.get_current(),
}

if is_job_board_admin:
# Send email to both jobs@p.o and creator's email when
# job board admins left a comment.
send_to.append(job.email)

context['user_name'] = name
context['reviewer_name'] = reviewer_name
template_name = 'comment_was_posted'
else:
context['submitter_name'] = name
template_name = 'comment_was_posted_admin'

subject = _("Python Job Board: Review comment for: {}").format(
job.display_name)
text_message_template = loader.get_template("jobs/email/comment_was_posted.txt")
text_message_template = loader.get_template('jobs/email/{}.txt'.format(template_name))

message_context = Context({ 'user_name': name,
'reviewer_name': reviewer_name,
'comment': comment.comment.raw,
'content_object': job,
'site': Site.objects.get_current() })
message_context = Context(context)
text_message = text_message_template.render(message_context)
send_mail(subject, text_message, settings.JOB_FROM_EMAIL,
[email, EMAIL_JOBS_BOARD])
send_mail(subject, text_message, settings.JOB_FROM_EMAIL, send_to)


def send_job_review_message(job, user, subject_template_path,
Expand Down
19 changes: 18 additions & 1 deletion jobs/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,24 @@ def test_job_comment(self):
response = self.client.post(url, form_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].to, [self.creator.email, 'jobs@python.org'])
# We should only send an email to jobs@p.o.
self.assertEqual(mail.outbox[0].to, ['jobs@python.org'])
self.assertIn('Dear Python Job Board Admin,', mail.outbox[0].body)
self.client.logout()

# Send a comment as a jobs board admin.
mail.outbox = []
self.client.login(username=self.super_username, password=self.super_password)
self.assertEqual(len(mail.outbox), 0)
response = self.client.post(url, form_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(len(mail.outbox), 1)
# We should send an email to both jobs@p.o and job submitter.
self.assertEqual(mail.outbox[0].to, ['jobs@python.org', self.creator_email])
self.assertIn(
'There is a new review comment available for your job posting.',
mail.outbox[0].body
)

def test_job_comment_401(self):
mail.outbox = []
Expand Down
16 changes: 16 additions & 0 deletions templates/jobs/email/comment_was_posted_admin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Dear Python Job Board Admin,

There is a new review comment available for a job posting.

Title: {{ content_object.job_title }}
Company: {{ content_object.company_name }}
URL: https://{{ site.domain }}{{ content_object.get_absolute_url }}
Posted: {{ content_object.created|date:"d F Y" }}

--- Comment: ---

{{ comment|safe }}

--
Kind regards,
{{ submitter_name }}
0