Page MenuHomePhabricator

Send content of comments in emails
Closed, ResolvedPublic

Assigned To
Authored By
AVasanth_WMF
Dec 12 2019, 6:02 PM
Referenced Files
F31513390: image.png
Jan 15 2020, 2:19 PM
F31513380: image.png
Jan 15 2020, 2:19 PM
F31513385: image.png
Jan 15 2020, 2:19 PM
F31513383: image.png
Jan 15 2020, 2:19 PM
F31513376: image.png
Jan 15 2020, 2:19 PM

Description

We currently send emails with generic messages when users comment on applications, rather than actually including the content of the comments. We should do the contemporary thing and just include the corresponding contents, sender, and other metadata directly in the emails.

The code for these comments is mostly defined in https://github.com/WikipediaLibrary/TWLight/blob/master/TWLight/emails/tasks.py#L153. We use https://github.com/django/django-contrib-comments to handle our commenting system.

Event Timeline

What all data we want to show in the email and what should be the subject line?

The email itself already exists, with a subject line. We just want to modify the variables (linked above) and the templates (the ones which start comment_notification_ in https://github.com/WikipediaLibrary/TWLight/tree/master/TWLight/emails/templates/emails).

Okay! From going through docs related to django_comments, I got to know:

  • the templated needs to load comments through {% load comments %}
  • the query Comment.objects.order_by('-submit_date')[0].comment give us the content of the last comment that we can render in templates but that may require a view that will return it. Not sure if it's a right way to do it.

Please provide further direction to complete this task.

I'll try to lay this task out a bit more thoroughly:

We want the emails I noted in my previous comment to include a section that looks something like:

Date - Commenter username

Comment text

Some HTML formatting in the HTML version of the email to lay this out in a nice way would be a plus.

In terms of implementation, the most straightforward solution should be that in each of the comment email sending functions (https://github.com/WikipediaLibrary/TWLight/blob/master/TWLight/emails/tasks.py#L205, https://github.com/WikipediaLibrary/TWLight/blob/master/TWLight/emails/tasks.py#L228, https://github.com/WikipediaLibrary/TWLight/blob/master/TWLight/emails/tasks.py#L274) we want to include data from the comment. That data is being stored in the current_comment variable - see https://django-contrib-comments.readthedocs.io/en/latest/models.html for information on how to access content such as the date and comment text. We can pass that data in to the email dictionary at the functions linked above, and then access that data directly in the email templates - we shouldn't need {% load comments %}.

Does that help? :)

Okay! I'll try this and get back to you soon.

I added submit_date, commenter and comment to all the three functions related to comment as mentioned above. Now they all look like this:

{
                    "user": username,
                    "lang": user.userprofile.lang,
                    "app": app,
                    "app_url": app_url,
                    "partner": app.partner,
                    "submit_date": current_comment.submit_date,
                    "commenter": current_comment.user,
                    "comment": current_comment.comment
};

And I am able to render the data into the template directly using:

<p>{{ submit_date }} - {{ commenter }}</p>
<blockquote><p>{{ comment }}</p></blockquote>
<p>Please reply to these at <a href="{{ app_url }}">{{ app_url }}</a> so we can evaluate your application.</p>
<p>Best,</p>
<p>The Wikipedia Library</p>

Accordingly changed comment_notification_editors , comment_notification_coordinators' and comment_notification_others -body-text and -body-html templates. The subject templates for all three are unchanged.
For the following comments:

image.png (664×884 px, 55 KB)

I received these emails:
image.png (353×647 px, 45 KB)

image.png (325×645 px, 41 KB)

image.png (321×646 px, 40 KB)

image.png (334×641 px, 40 KB)

here 'ryuk1' is the superuser and Soumyaa1804 is my wp username. When I comment as Soumyaa1804, it is showing my wp user-id i.e. 60566161 in the mail. I doubt if it should be 'Soumyaa1804' instead of 60566161.
Please review if i am doing it correctly.

This is looking really great!

The issue with usernames you ran into is a common one. We have two different usernames in the application - the User object username is a string of digits (the user's Wikipedia ID), whereas the username we usually display is actually user.editor.wp_username (https://github.com/WikipediaLibrary/TWLight/blob/master/TWLight/users/models.py#L154), i.e. the Wikipedia username of the Editor object attached to that User.

Swapping out "commenter": current_comment.user for something like "commenter": current_comment.user.editor.wp_username should display "Soumyaa1804" correctly :)

Here are the templates rn:
comment_notification_coordinator-body-html.html

<p style="color: #500050">{{ submit_date }} - {{ commenter }}</p>
<blockquote><p>{{ comment }}</p></blockquote>
<p>Please reply to these at: <a href="{{ app_url }}">{{ app_url }}</a></p>
<p>Best,</p>
<p>The Wikipedia Library</p>

comment_notification_editors-body-html.html

<p style="color: #500050">{{ submit_date }} - {{ commenter }}</p>
<blockquote><p>{{ comment }}</p></blockquote>
<p>Please reply to these at <a href="{{ app_url }}">{{ app_url }}</a> so we can evaluate your application.</p>
<p>Best,</p>
<p>The Wikipedia Library</p>

comment_notification_others-body-html.html

<p style="color: #500050">{{ submit_date }} - {{ commenter }}</p>
<blockquote><p>{{ comment }}</p></blockquote>

See it at
<a href="{{ app_url }}">{{ app_url }}</a>.
Thanks for helping review Wikipedia Library applications!

Let me know if we need to change any styling or if I am good to go to make a PR.

Looks good to me! Please go ahead and make a PR :)