Commit b8c2a5cb by Ibrahim Awwal

Fixed context links after searching for real, and removed some more dead code.

parent f25b2666
...@@ -49,7 +49,6 @@ def render_accordion(request, course, discussion_id): ...@@ -49,7 +49,6 @@ def render_accordion(request, course, discussion_id):
return render_to_string('discussion/_accordion.html', context) return render_to_string('discussion/_accordion.html', context)
def render_discussion(request, course_id, threads, *args, **kwargs): def render_discussion(request, course_id, threads, *args, **kwargs):
discussion_id = kwargs.get('discussion_id') discussion_id = kwargs.get('discussion_id')
user_id = kwargs.get('user_id') user_id = kwargs.get('user_id')
discussion_type = kwargs.get('discussion_type', 'inline') discussion_type = kwargs.get('discussion_type', 'inline')
...@@ -182,13 +181,13 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -182,13 +181,13 @@ def inline_discussion(request, course_id, discussion_id):
def forum_form_discussion(request, course_id): def forum_form_discussion(request, course_id):
""" """
Renders the main Discussion page Renders the main Discussion page, potentially filtered by a search query
""" """
course = get_course_with_access(request.user, course_id, 'load') course = get_course_with_access(request.user, course_id, 'load')
category_map = utils.get_discussion_category_map(course) category_map = utils.get_discussion_category_map(course)
try: try:
unsafethreads, query_params = get_threads(request, course_id) unsafethreads, query_params = get_threads(request, course_id) # This might process a search query
threads = [utils.safe_content(thread) for thread in unsafethreads] threads = [utils.safe_content(thread) for thread in unsafethreads]
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err: except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
raise Http404 raise Http404
...@@ -201,11 +200,16 @@ def forum_form_discussion(request, course_id): ...@@ -201,11 +200,16 @@ def forum_form_discussion(request, course_id):
return utils.get_annotated_content_infos(course_id, thread, request.user, user_info) return utils.get_annotated_content_infos(course_id, thread, request.user, user_info)
annotated_content_info = reduce(merge_dict, map(infogetter, threads), {}) annotated_content_info = reduce(merge_dict, map(infogetter, threads), {})
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']
if request.is_ajax(): if request.is_ajax():
return utils.JsonResponse({ return utils.JsonResponse({
#'html': content, #'html': content,
'discussion_data': threads, 'discussion_data': threads,
'annotated_content_info': annotated_content_info,
}) })
else: else:
#recent_active_threads = cc.search_recent_active_threads( #recent_active_threads = cc.search_recent_active_threads(
...@@ -217,6 +221,7 @@ def forum_form_discussion(request, course_id): ...@@ -217,6 +221,7 @@ def forum_form_discussion(request, course_id):
#trending_tags = cc.search_trending_tags( #trending_tags = cc.search_trending_tags(
# course_id, # course_id,
#) #)
escapedict = {'"': '"'} escapedict = {'"': '"'}
context = { context = {
'csrf': csrf(request)['csrf_token'], 'csrf': csrf(request)['csrf_token'],
......
...@@ -273,6 +273,7 @@ def safe_content(content): ...@@ -273,6 +273,7 @@ def safe_content(content):
'created_at', 'updated_at', 'depth', 'type', 'created_at', 'updated_at', 'depth', 'type',
'commentable_id', 'comments_count', 'at_position_list', 'commentable_id', 'comments_count', 'at_position_list',
'children', 'highlighted_title', 'highlighted_body', 'children', 'highlighted_title', 'highlighted_body',
'courseware_title', 'courseware_location'
] ]
if content.get('anonymous') is False: if content.get('anonymous') is False:
......
...@@ -15,13 +15,9 @@ class @DiscussionUtil ...@@ -15,13 +15,9 @@ class @DiscussionUtil
@getTemplate: (id) -> @getTemplate: (id) ->
$("script##{id}").html() $("script##{id}").html()
@addContent: (id, content) -> window.$$contents[id] = content
@getContent: (id) -> window.$$contents[id]
@bulkUpdateContentInfo: (infos) -> @bulkUpdateContentInfo: (infos) ->
for id, info of infos for id, info of infos
@getContent(id).updateInfo(info) Content.getContent(id).updateInfo(info)
@generateDiscussionLink: (cls, txt, handler) -> @generateDiscussionLink: (cls, txt, handler) ->
$("<a>").addClass("discussion-link") $("<a>").addClass("discussion-link")
......
...@@ -229,6 +229,10 @@ if Backbone? ...@@ -229,6 +229,10 @@ if Backbone?
success: (response, textStatus) => success: (response, textStatus) =>
if textStatus == 'success' if textStatus == 'success'
@collection.reset(response.discussion_data) @collection.reset(response.discussion_data)
Content.loadContentInfos(response.content_info)
# TODO: Perhaps reload user info so that votes can be updated.
# In the future we might not load all of a user's votes at once
# so this would probably be necessary anyway
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models)
setActiveItem: (event) -> setActiveItem: (event) ->
......
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