EDUCATOR-1590 | Message context usernames should come from django models.

This commit is contained in:
Alex Dusenbery
2017-11-15 16:50:18 -05:00
committed by Alex Dusenbery
parent 926c745a4c
commit c28427fd09
2 changed files with 10 additions and 10 deletions

View File

@@ -54,11 +54,9 @@ def send_message(comment, site):
'comment_id': comment.id,
'comment_body': comment.body,
'comment_author_id': comment.user_id,
'comment_username': comment.username,
'comment_created_at': comment.created_at, # comment_client models dates are already serialized
'thread_id': thread.id,
'thread_title': thread.title,
'thread_username': thread.username,
'thread_author_id': thread.user_id,
'thread_created_at': thread.created_at, # comment_client models dates are already serialized
'thread_commentable_id': thread.commentable_id,

View File

@@ -100,17 +100,19 @@ def _get_course_language(course_id):
def _build_message_context(context):
message_context = get_base_template_context(context['site'])
message_context.update(_deserialize_context_dates(context))
message_context['post_link'] = _get_thread_url(context)
message_context.update(context)
thread_author = User.objects.get(id=context['thread_author_id'])
comment_author = User.objects.get(id=context['comment_author_id'])
message_context.update({
'thread_username': thread_author.username,
'comment_username': comment_author.username,
'post_link': _get_thread_url(context),
'comment_created_at': date.deserialize(context['comment_created_at']),
'thread_created_at': date.deserialize(context['thread_created_at'])
})
return message_context
def _deserialize_context_dates(context):
context['comment_created_at'] = date.deserialize(context['comment_created_at'])
context['thread_created_at'] = date.deserialize(context['thread_created_at'])
return context
def _get_thread_url(context):
thread_content = {
'type': 'thread',