Refactor some things more and make the forum index sort of work, although the sticky sidebar is broken, probably because there's no content in the thread view pane.
This commit is contained in:
@@ -18,7 +18,7 @@ from django_comment_client.utils import merge_dict, extract, strip_none, strip_b
|
||||
import json
|
||||
import django_comment_client.utils as utils
|
||||
import comment_client as cc
|
||||
|
||||
import xml.sax.saxutils as saxutils
|
||||
|
||||
THREADS_PER_PAGE = 50000
|
||||
PAGES_NEARBY_DELTA = 2
|
||||
@@ -143,9 +143,10 @@ def render_search_bar(request, course_id, discussion_id=None, text=''):
|
||||
|
||||
def forum_form_discussion(request, course_id):
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
category_map = utils.get_discussion_category_map(course)
|
||||
threads, query_params = get_threads(request, course_id)
|
||||
content = render_forum_discussion(request, course_id, threads, discussion_id=_general_discussion_id(course_id), query_params=query_params)
|
||||
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
if request.is_ajax():
|
||||
return utils.JsonResponse({
|
||||
'html': content,
|
||||
@@ -161,6 +162,7 @@ def forum_form_discussion(request, course_id):
|
||||
trending_tags = cc.search_trending_tags(
|
||||
course_id,
|
||||
)
|
||||
escapedict = {'"': '"'}
|
||||
context = {
|
||||
'csrf': csrf(request)['csrf_token'],
|
||||
'course': course,
|
||||
@@ -168,7 +170,10 @@ def forum_form_discussion(request, course_id):
|
||||
'recent_active_threads': recent_active_threads,
|
||||
'trending_tags': trending_tags,
|
||||
'staff_access' : has_access(request.user, course, 'staff'),
|
||||
'threads': threads,
|
||||
'threads': saxutils.escape(json.dumps(threads),escapedict),
|
||||
'user_info': saxutils.escape(json.dumps(user_info),escapedict),
|
||||
'course_id': course.id,
|
||||
'category_map': category_map,
|
||||
}
|
||||
# print "start rendering.."
|
||||
return render_to_response('discussion/index.html', context)
|
||||
@@ -197,7 +202,7 @@ def render_single_thread(request, discussion_id, course_id, thread_id):
|
||||
def single_thread(request, course_id, discussion_id, thread_id):
|
||||
|
||||
if request.is_ajax():
|
||||
|
||||
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
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)
|
||||
@@ -226,19 +231,19 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
)
|
||||
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
|
||||
escapedict = {'"': '"'}
|
||||
context = {
|
||||
'discussion_id': discussion_id,
|
||||
'csrf': csrf(request)['csrf_token'],
|
||||
'init': '',
|
||||
'user_info': json.dumps(user_info),
|
||||
'user_info': saxutils.escape(json.dumps(user_info),escapedict),
|
||||
'content': render_single_thread(request, discussion_id, course_id, thread_id),
|
||||
'course': course,
|
||||
'recent_active_threads': recent_active_threads,
|
||||
'trending_tags': trending_tags,
|
||||
'course_id': course.id,
|
||||
'thread_id': thread_id,
|
||||
'threads': json.dumps(threads),
|
||||
'threads': saxutils.escape(json.dumps(threads), escapedict),
|
||||
'category_map': category_map,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ if Backbone?
|
||||
model: Thread
|
||||
|
||||
initialize: ->
|
||||
DiscussionUtil.addDiscussion @id, @
|
||||
@bind "add", (item) =>
|
||||
item.discussion = @
|
||||
@comparator = @sortByDate
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
DiscussionApp =
|
||||
start: (elem)->
|
||||
# TODO: Perhaps eliminate usage of global variables when possible
|
||||
element = $(elem)
|
||||
window.$$contents = {}
|
||||
window.$$course_id = element.data("course-id")
|
||||
user_info = element.data("user-info")
|
||||
threads = element.data("threads")
|
||||
window.user = new DiscussionUser(user_info)
|
||||
discussion = new Discussion(threads)
|
||||
new DiscussionRouter({discussion: discussion})
|
||||
Backbone.history.start({pushState: true, root: "/courses/#{$$course_id}/discussion/forum/"})
|
||||
|
||||
$ ->
|
||||
$("section.discussion").each (index, elem) ->
|
||||
DiscussionApp.start(elem)
|
||||
|
||||
@@ -13,16 +13,9 @@ class @DiscussionUtil
|
||||
@getTemplate: (id) ->
|
||||
$("script##{id}").html()
|
||||
|
||||
@getDiscussionData: (id) ->
|
||||
return $$discussion_data[id]
|
||||
|
||||
@addContent: (id, content) -> window.$$contents[id] = content
|
||||
|
||||
@getContent: (id) -> window.$$contents[id]
|
||||
|
||||
@addDiscussion: (id, discussion) -> window.$$discussions[id] = discussion
|
||||
|
||||
@getDiscussion: (id) -> window.$$discussions[id]
|
||||
|
||||
@bulkUpdateContentInfo: (infos) ->
|
||||
for id, info of infos
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<%! import django_comment_client.helpers as helpers %>
|
||||
<%! from django.template.defaultfilters import escapejs %>
|
||||
<%! from django.core.urlresolvers import reverse %>
|
||||
|
||||
<%inherit file="../main.html" />
|
||||
<%namespace name='static' file='../static_content.html'/>
|
||||
<%block name="bodyclass">discussion</%block>
|
||||
@@ -16,51 +19,15 @@
|
||||
|
||||
<%include file="../courseware/course_navigation.html" args="active_page='discussion'" />
|
||||
|
||||
<%include file="_new_post.html" />
|
||||
|
||||
<section class="container">
|
||||
<div class="discussion-wrapper">
|
||||
<article class="discussion-sidebar">
|
||||
<div class="board-selector">
|
||||
<a href="#" class="board-drop-btn">Homework / Week 1 <span class="drop-arrow">▾</span></a>
|
||||
<div class="board-drop-menu">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sort-bar">
|
||||
<a href="#"><span class="sort-label">Sort by:</span> most recent <span class="drop-arrow">▾</span></a>
|
||||
</div>
|
||||
<div class="post-list-wrapper">
|
||||
<ul class="post-list">
|
||||
% for thread in threads:
|
||||
<li><a href="${helpers.permalink(thread) | h}"><span class="title">${thread['title'] | h}</span> <span class="comments">${thread['comments_count'] | h}</span><span class="votes">+${thread['votes']['up_count'] | h}</span></a></li>
|
||||
% endfor
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
<section class="discussion-content">
|
||||
This page intentionally left blank
|
||||
</section>
|
||||
</div>
|
||||
<script type="text/javascript" src="${static.url('js/discussions-temp.js')}"></script>
|
||||
|
||||
<section class="discussion container" id="discussion-container" data-course-id="${course_id}" data-user-info="${user_info}" data-threads="${threads}">
|
||||
<div class="discussion-body">
|
||||
<div class="sidebar"></div>
|
||||
<div class="discussion-column"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="container">
|
||||
<div class="course-wrapper">
|
||||
<section aria-label="Course Navigation" class="course-index">
|
||||
<nav>
|
||||
|
||||
<article class="sidebar-module discussion-sidebar">
|
||||
<a href="#" class="sidebar-new-post-button">New Post</a>
|
||||
</article>
|
||||
|
||||
<%include file="_recent_active_posts.html" />
|
||||
|
||||
<%include file="_trending_tags.html" />
|
||||
|
||||
</nav>
|
||||
</section>
|
||||
|
||||
<section class="course-content">
|
||||
${content.decode('utf-8')}
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
<%include file="_underscore_templates.html" />
|
||||
@@ -18,21 +18,7 @@
|
||||
<%static:js group='discussion'/>
|
||||
<script type="text/javascript" src="${static.url('js/discussions-temp.js')}"></script>
|
||||
<script>
|
||||
$$contents = {};
|
||||
$$discussions = {};
|
||||
$$course_id = "${course_id}";
|
||||
DiscussionApp = {
|
||||
start: function() {
|
||||
window.user = new DiscussionUser(JSON.parse("${user_info | escapejs}"));
|
||||
var discussion = new Discussion(JSON.parse("${threads | escapejs}"));
|
||||
|
||||
new DiscussionRouter({discussion: discussion});
|
||||
Backbone.history.start({pushState: true, root: "/courses/${course_id}/discussion/forum/"});
|
||||
}
|
||||
}
|
||||
$(document).ready(function() {
|
||||
DiscussionApp.start();
|
||||
});
|
||||
</script>
|
||||
</%block>
|
||||
|
||||
@@ -71,11 +57,11 @@
|
||||
|
||||
<%include file="_new_post.html" />
|
||||
|
||||
<div class="discussion container">
|
||||
<section class="discussion container" id="discussion-container" data-course-id="${course_id}" data-user-info="${user_info}" data-threads="${threads}">
|
||||
<div class="discussion-body">
|
||||
<div class="sidebar"></div>
|
||||
<div class="discussion-column"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<%include file="_underscore_templates.html" />
|
||||
|
||||
Reference in New Issue
Block a user