Commit d5b70d7b by Your Name

inline cohorting working

parent 837f54c0
// Generated by CoffeeScript 1.3.3
// Generated by CoffeeScript 1.4.0
(function() {
var MinimaxProblemDisplay, root,
__hasProp = {}.hasOwnProperty,
......
// Generated by CoffeeScript 1.3.3
// Generated by CoffeeScript 1.4.0
(function() {
var TestProblemGenerator, root,
__hasProp = {}.hasOwnProperty,
......
// Generated by CoffeeScript 1.3.3
// Generated by CoffeeScript 1.4.0
(function() {
var TestProblemGrader, root,
__hasProp = {}.hasOwnProperty,
......
// Generated by CoffeeScript 1.3.3
// Generated by CoffeeScript 1.4.0
(function() {
var XProblemDisplay, XProblemGenerator, XProblemGrader, root;
......
......@@ -73,10 +73,14 @@ if Backbone?
# $elem.html("Hide Discussion")
@discussion = new Discussion()
@discussion.reset(response.discussion_data, {silent: false})
if response.is_cohorted
$discussion = $(Mustache.render $("script#_inline_discussion_cohorted").html(), {'threads':response.discussion_data, 'discussionId': discussionId, 'allow_anonymous_to_peers': allow_anonymous_to_peers, 'allow_anonymous': allow_anonymous})
else
$discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data, 'discussionId': discussionId, 'allow_anonymous_to_peers': allow_anonymous_to_peers, 'allow_anonymous': allow_anonymous})
#rather than have two different templates to get around (or take advantage of?)
#mustache's logic free templates, we added a 'group string' to each thread for inline
#discussions for the use case where a commentable is cohorted, but a global
#thread is posted by a TA
$discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data, 'discussionId': discussionId, 'allow_anonymous_to_peers': allow_anonymous_to_peers, 'allow_anonymous': allow_anonymous})
if @$('section.discussion').length
@$('section.discussion').replaceWith($discussion)
else
......
......@@ -25,6 +25,7 @@ if Backbone?
event.preventDefault()
title = @$(".new-post-title").val()
body = @$(".new-post-body").find(".wmd-input").val()
group = @$(".new-post-group option:selected").attr("value")
# TODO tags: commenting out til we know what to do with them
#tags = @$(".new-post-tags").val()
......@@ -45,6 +46,7 @@ if Backbone?
data:
title: title
body: body
group_id: group
# TODO tags: commenting out til we know what to do with them
#tags: tags
......
......@@ -75,9 +75,12 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
#now add the group name if the thread has a group id
for thread in threads:
if thread.get('group_id') and not thread.get('group_name'):
thread['group_name'] = get_cohort_by_id(course_id, thread.get('group_id')).name
if thread.get('group_id'):
thread['group_name'] = get_cohort_by_id(course_id, thread.get('group_id')).name
thread['group_string'] = "This post visible only to Group ${group_name}."
else:
thread['group_name'] = ""
thread['group_string'] = "This post visible to everyone."
query_params['page'] = page
query_params['num_pages'] = num_pages
......@@ -85,6 +88,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
return threads, query_params
def inline_discussion(request, course_id, discussion_id):
"""
Renders JSON for DiscussionModules
"""
......@@ -107,24 +111,26 @@ def inline_discussion(request, course_id, discussion_id):
allow_anonymous = course.metadata.get("allow_anonymous", True)
allow_anonymous_to_peers = course.metadata.get("allow_anonymous_to_peers", False)
#if we can't get the user's cohort, default to visible to all, treat as if the discussion is not cohoroted
is_cohorted = is_course_cohorted(course_id) and is_commentable_cohorted(course_id, discussion_id)
cohorts_list = list()
if is_cohorted:
cohorts_dict = dict()
#if you're a mod, send all cohorts and let you pick
if cached_has_permission(request.user, "see_all_cohorts", course_id):
if cached_has_permission(request.user, "see_all_cohorts", course_id) or True:
cohorts = get_course_cohorts(course_id)
for c in cohorts:
cohorts_dict[c.name]=c.id
cohorts_list.append({'name':c.name, 'id':c.id})
else:
#otherwise, just make a dictionary of two
user_cohort = get_cohort_id(user, course_id)
cohorts_dict["All Groups"] = None
cohorts_list.append({'name':'All Groups','id':None})
if user_cohort:
cohorts_dict[user_cohort.name] = user_cohort.id
else:
cohorts_dict = None
cohorts_list.append({'name':user_cohort.name, 'id':user_cohort.id})
else:
cohorts_list = None
return utils.JsonResponse({
......@@ -136,12 +142,13 @@ def inline_discussion(request, course_id, discussion_id):
'roles': utils.get_role_ids(course_id),
'allow_anonymous_to_peers': allow_anonymous_to_peers,
'allow_anonymous': allow_anonymous,
'cohorts': cohorts_dict,
'cohorts': cohorts_list,
'is_cohorted': is_cohorted
})
@login_required
def forum_form_discussion(request, course_id):
"""
Renders the main Discussion page, potentially filtered by a search query
"""
......@@ -181,8 +188,10 @@ def forum_form_discussion(request, course_id):
#trending_tags = cc.search_trending_tags(
# course_id,
#)
cohorts = get_course_cohorts(course_id)
cohorted_commentables = get_cohorted_commentables(course_id)
user_cohort_id = get_cohort_id(request.user, course_id)
context = {
'csrf': csrf(request)['csrf_token'],
......@@ -199,8 +208,8 @@ def forum_form_discussion(request, course_id):
'roles': saxutils.escape(json.dumps(utils.get_role_ids(course_id)), escapedict),
'is_moderator': cached_has_permission(request.user, "see_all_cohorts", course_id),
'cohorts': cohorts,
'user_cohort': get_cohort_id(user, course_id),
'cohorted_commentables': get_cohorted_commentables(course_id),
'user_cohort': user_cohort_id,
'cohorted_commentables': cohorted_commentables,
'is_course_cohorted': is_course_cohorted(course_id)
}
# print "start rendering.."
......@@ -208,7 +217,6 @@ def forum_form_discussion(request, course_id):
@login_required
def single_thread(request, course_id, discussion_id, thread_id):
course = get_course_with_access(request.user, course_id, 'load')
cc_user = cc.User.from_django_user(request.user)
user_info = cc_user.to_dict()
......@@ -222,7 +230,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
if request.is_ajax():
courseware_context = get_courseware_context(thread, course)
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
......@@ -268,6 +276,10 @@ def single_thread(request, course_id, discussion_id, thread_id):
#)
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
cohorts = get_course_cohorts(course_id)
cohorted_commentables = get_cohorted_commentables(course_id)
user_cohort = get_cohort_id(request.user, course_id)
context = {
'discussion_id': discussion_id,
......@@ -284,6 +296,11 @@ def single_thread(request, course_id, discussion_id, thread_id):
'category_map': category_map,
'roles': saxutils.escape(json.dumps(utils.get_role_ids(course_id)), escapedict),
'thread_pages': query_params['num_pages'],
'is_course_cohorted': is_course_cohorted(course_id),
'is_moderator': cached_has_permission(request.user, "see_all_cohorts", course_id) or True,
'cohorts': cohorts,
'user_cohort': get_cohort_id(request.user, course_id),
'cohorted_commentables': cohorted_commentables
}
return render_to_response('discussion/single_thread.html', context)
......
......@@ -374,7 +374,7 @@ def safe_content(content):
'updated_at', 'depth', 'type', 'commentable_id', 'comments_count',
'at_position_list', 'children', 'highlighted_title', 'highlighted_body',
'courseware_title', 'courseware_url', 'tags', 'unread_comments_count',
'read', 'group_id', 'group_name'
'read', 'group_id', 'group_name', 'group_string'
]
if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False):
......
......@@ -22,8 +22,6 @@
</%def>
<article class="new-post-article">
<div class="inner-wrapper">
<form class="new-post-form">
......@@ -58,7 +56,9 @@
<option value="${c.id}">${c.name}</option>
%endfor
%else:
<option value="${user_cohort}">My Cohort</option>
%if user_cohort:
<option value="${user_cohort}">My Cohort</option>
%endif
%endif
</select>
......
......@@ -4,6 +4,7 @@
<article class="discussion-article" data-id="${discussion_id| h}">
<a href="#" class="dogear"></a>
<div class="discussion-post">
<header>
%if thread['group_id']
<div class="group-visibility-label">This post visible only to group ${cohort_dictionary[thread['group_id']]}. </div>
......
......@@ -28,7 +28,7 @@
<header>
${"<% if (obj.group_id) { %>"}
<div class="group-visibility-label">This post visible only to Group ${"<%- obj.group_name%>"}.</div>
<div class="group-visibility-label">${"<%- obj.group_string%>"}.</div>
${"<% } %>"}
<a href="#" class="vote-btn discussion-vote discussion-vote-up" data-role="discussion-vote" data-tooltip="vote"><span class="plus-icon">+</span> <span class='votes-count-number'>${'<%- votes["up_count"] %>'}</span></a>
......
<div class="discussion-content local{{#content.roles}} role-{{name}}{{/content.roles}}">
CONTENT MUSTACHE
<div class="discussion-content-wrapper">
<div class="discussion-votes">
<a class="discussion-vote discussion-vote-up" href="javascript:void(0)" value="up">&#9650;</a>
......
<section class="discussion" data-discussion-id="{{discussionId}}">
<article class="new-post-article">
<span class="topic" data-discussion-id="{{discussionId}}" />
<div class="inner-wrapper">
......@@ -36,6 +34,7 @@
<section class="threads">
{{#threads}}
<div class="group-visibility-label">{{group_string}}</div>
<article class="discussion-thread" id="thread_{{id}}">
</article>
{{/threads}}
......
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