Commit 4fea82f5 by Arjun Singh Committed by Matthew Mongeau

courseware context links in discussion

parent 3587e460
......@@ -234,6 +234,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
thread = cc.Thread.find(thread_id).retrieve(recursive=True)
annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info)
context = {'thread': thread.to_dict(), 'course_id': course_id}
# TODO: Remove completely or switch back to server side rendering
html = render_to_string('discussion/_ajax_single_thread.html', context)
return utils.JsonResponse({
......@@ -247,15 +248,23 @@ def single_thread(request, course_id, discussion_id, thread_id):
category_map = utils.get_discussion_category_map(course)
threads, query_params = get_threads(request, course_id)
recent_active_threads = cc.search_recent_active_threads(
course_id,
recursive=False,
query_params={'follower_id': request.user.id},
)
course = get_course_with_access(request.user, course_id, 'load')
for thread in threads:
courseware_context = get_courseware_context(thread, course)
if courseware_context:
thread['courseware_location'] = courseware_context['courseware_location']
thread['courseware_title'] = courseware_context['courseware_title']
#recent_active_threads = cc.search_recent_active_threads(
# course_id,
# recursive=False,
# query_params={'follower_id': request.user.id},
#)
trending_tags = cc.search_trending_tags(
course_id,
)
#trending_tags = cc.search_trending_tags(
# course_id,
#)
user_info = cc.User.from_django_user(request.user).to_dict()
escapedict = {'"': '"'}
......@@ -272,8 +281,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
'user_info': saxutils.escape(json.dumps(user_info),escapedict),
'annotated_content_info': saxutils.escape(json.dumps(annotated_content_info), escapedict),
'course': course,
'recent_active_threads': recent_active_threads,
'trending_tags': trending_tags,
#'recent_active_threads': recent_active_threads,
#'trending_tags': trending_tags,
'course_id': course.id,
'thread_id': thread_id,
'threads': saxutils.escape(json.dumps(threads), escapedict),
......
......@@ -135,6 +135,16 @@ def initialize_discussion_info(course):
_DISCUSSIONINFO['category_map'] = category_map
def get_courseware_context(content, course):
id_map = get_discussion_id_map(course)
id = content['commentable_id']
content_info = None
if id in id_map:
location = id_map[id]["location"].url()
title = id_map[id]["title"]
content_info = { "courseware_location": location, "courseware_title": title}
return content_info
class JsonResponse(HttpResponse):
def __init__(self, data=None):
content = simplejson.dumps(data)
......
......@@ -1056,6 +1056,12 @@ body.discussion {
color: #888;
}
.post-context{
margin-top: 20px;
font-size: 12px;
color: #888;
}
p + p {
margin-top: 20px;
}
......
......@@ -13,8 +13,15 @@
<div class="post-body">
${'<%- body %>'}
</div>
<div class="post-status-closed" style="display: none">
${'<% if (obj.courseware_location) { %>'}
<div class="post-context">
(this post is about <a href="../../jump_to/${'<%- courseware_location %>'}">${'<%- courseware_title %>'}</a>)
</div>
${'<% } %>'}
<div class="post-status">
${'<% if (closed) { %>'}
This thread is closed.
${'<% } %>'}
</div>
<ul class="moderator-actions">
<li style="display: none"><a class="action-edit" href="javascript:void(0)"><span class="edit-icon"></span> Edit</a></li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment