email: Rename template_payload to context.

This commit is contained in:
Rishi Gupta
2017-05-04 14:37:01 -07:00
committed by Tim Abbott
parent 6a8ed81439
commit face3077df
2 changed files with 17 additions and 19 deletions

View File

@@ -157,10 +157,10 @@ def handle_digest_email(user_profile_id, cutoff):
user_profile=user_profile, user_profile=user_profile,
message__pub_date__gt=cutoff_date).order_by("message__pub_date") message__pub_date__gt=cutoff_date).order_by("message__pub_date")
template_payload = common_context(user_profile) context = common_context(user_profile)
# Start building email template data. # Start building email template data.
template_payload.update({ context.update({
'name': user_profile.full_name, 'name': user_profile.full_name,
'unsubscribe_link': one_click_unsubscribe_link(user_profile, "digest") 'unsubscribe_link': one_click_unsubscribe_link(user_profile, "digest")
}) })
@@ -175,9 +175,9 @@ def handle_digest_email(user_profile_id, cutoff):
# Show up to 4 missed PMs. # Show up to 4 missed PMs.
pms_limit = 4 pms_limit = 4
template_payload['unread_pms'] = build_message_list( context['unread_pms'] = build_message_list(
user_profile, [pm.message for pm in pms[:pms_limit]]) user_profile, [pm.message for pm in pms[:pms_limit]])
template_payload['remaining_unread_pms_count'] = min(0, len(pms) - pms_limit) context['remaining_unread_pms_count'] = min(0, len(pms) - pms_limit)
home_view_recipients = [sub.recipient for sub in home_view_recipients = [sub.recipient for sub in
Subscription.objects.filter( Subscription.objects.filter(
@@ -190,25 +190,23 @@ def handle_digest_email(user_profile_id, cutoff):
message__recipient__in=home_view_recipients) message__recipient__in=home_view_recipients)
# Gather hot conversations. # Gather hot conversations.
template_payload["hot_conversations"] = gather_hot_conversations( context["hot_conversations"] = gather_hot_conversations(
user_profile, stream_messages) user_profile, stream_messages)
# Gather new streams. # Gather new streams.
new_streams_count, new_streams = gather_new_streams( new_streams_count, new_streams = gather_new_streams(
user_profile, cutoff_date) user_profile, cutoff_date)
template_payload["new_streams"] = new_streams context["new_streams"] = new_streams
template_payload["new_streams_count"] = new_streams_count context["new_streams_count"] = new_streams_count
# Gather users who signed up recently. # Gather users who signed up recently.
new_users_count, new_users = gather_new_users( new_users_count, new_users = gather_new_users(
user_profile, cutoff_date) user_profile, cutoff_date)
template_payload["new_users"] = new_users context["new_users"] = new_users
# We don't want to send emails containing almost no information. # We don't want to send emails containing almost no information.
if enough_traffic(template_payload["unread_pms"], if enough_traffic(context["unread_pms"], context["hot_conversations"],
template_payload["hot_conversations"],
new_streams_count, new_users_count): new_streams_count, new_users_count):
logger.info("Sending digest email for %s" % (user_profile.email,)) logger.info("Sending digest email for %s" % (user_profile.email,))
# Send now, as a ScheduledJob # Send now, as a ScheduledJob
send_future_email('zerver/emails/digest', display_email(user_profile), send_future_email('zerver/emails/digest', display_email(user_profile), context=context)
context=template_payload)

View File

@@ -248,8 +248,8 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
) )
unsubscribe_link = one_click_unsubscribe_link(user_profile, "missed_messages") unsubscribe_link = one_click_unsubscribe_link(user_profile, "missed_messages")
template_payload = common_context(user_profile) context = common_context(user_profile)
template_payload.update({ context.update({
'name': user_profile.full_name, 'name': user_profile.full_name,
'messages': build_message_list(user_profile, missed_messages), 'messages': build_message_list(user_profile, missed_messages),
'message_count': message_count, 'message_count': message_count,
@@ -261,12 +261,12 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
# can users reply to email to send message to Zulip. Thus, one must # can users reply to email to send message to Zulip. Thus, one must
# ensure to display warning in the template. # ensure to display warning in the template.
if settings.EMAIL_GATEWAY_PATTERN: if settings.EMAIL_GATEWAY_PATTERN:
template_payload.update({ context.update({
'reply_warning': False, 'reply_warning': False,
'reply_to_zulip': True, 'reply_to_zulip': True,
}) })
else: else:
template_payload.update({ context.update({
'reply_warning': True, 'reply_warning': True,
'reply_to_zulip': False, 'reply_to_zulip': False,
}) })
@@ -291,13 +291,13 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
headers['Sender'] = from_email headers['Sender'] = from_email
sender = missed_messages[0].sender sender = missed_messages[0].sender
from_email = '"%s" <%s>' % (sender_str, sender.email) from_email = '"%s" <%s>' % (sender_str, sender.email)
template_payload.update({ context.update({
'reply_warning': False, 'reply_warning': False,
'reply_to_zulip': False, 'reply_to_zulip': False,
}) })
text_content = loader.render_to_string('zerver/emails/missed_message.txt', template_payload) text_content = loader.render_to_string('zerver/emails/missed_message.txt', context)
html_content = loader.render_to_string('zerver/emails/missed_message.html', template_payload) html_content = loader.render_to_string('zerver/emails/missed_message.html', context)
email_content = { email_content = {
'subject': subject, 'subject': subject,
'text_content': text_content, 'text_content': text_content,