allow moderators and students to select cohort on post creation
This commit is contained in:
@@ -30,6 +30,9 @@ def get_cohort_id(user, course_id):
|
||||
Given a course id and a user, return the id of the cohort that user is
|
||||
assigned to in that course. If they don't have a cohort, return None.
|
||||
"""
|
||||
print "\n\n\n\n\n*********************************"
|
||||
print user
|
||||
print course_id
|
||||
cohort = get_cohort(user, course_id)
|
||||
return None if cohort is None else cohort.id
|
||||
|
||||
@@ -64,7 +67,23 @@ def is_commentable_cohorted(course_id, commentable_id):
|
||||
ans))
|
||||
return ans
|
||||
|
||||
|
||||
def get_cohorted_commentables(course_id):
|
||||
"""
|
||||
Given a course_id return a list of strings representing cohorted commentables
|
||||
"""
|
||||
|
||||
course = courses.get_course_by_id(course_id)
|
||||
|
||||
if not course.is_cohorted:
|
||||
# this is the easy case :)
|
||||
ans = []
|
||||
else:
|
||||
ans = course.top_level_discussion_topic_ids
|
||||
|
||||
return ans
|
||||
|
||||
|
||||
def get_cohort(user, course_id):
|
||||
"""
|
||||
Given a django User and a course_id, return the user's cohort in that
|
||||
|
||||
@@ -14,8 +14,9 @@ if Backbone?
|
||||
@setSelectedTopic()
|
||||
|
||||
DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "new-post-body"
|
||||
|
||||
@$(".new-post-tags").tagsInput DiscussionUtil.tagsInputOptions()
|
||||
|
||||
|
||||
events:
|
||||
"submit .new-post-form": "createPost"
|
||||
"click .topic_dropdown_button": "toggleTopicDropdown"
|
||||
@@ -65,6 +66,11 @@ if Backbone?
|
||||
@topicText = @getFullTopicName($target)
|
||||
@topicId = $target.data('discussion_id')
|
||||
@setSelectedTopic()
|
||||
if $target.attr('cohorted') == "True"
|
||||
$('.choose-cohort').show();
|
||||
else
|
||||
$('.choose-cohort').hide();
|
||||
|
||||
|
||||
setSelectedTopic: ->
|
||||
@dropdownButton.html(@fitName(@topicText) + ' <span class="drop-arrow">▾</span>')
|
||||
@@ -116,6 +122,7 @@ if Backbone?
|
||||
title = @$(".new-post-title").val()
|
||||
body = @$(".new-post-body").find(".wmd-input").val()
|
||||
tags = @$(".new-post-tags").val()
|
||||
group = @$(".new-post-group option:selected").attr("value")
|
||||
|
||||
anonymous = false || @$("input.discussion-anonymous").is(":checked")
|
||||
anonymous_to_peers = false || @$("input.discussion-anonymous-to-peers").is(":checked")
|
||||
@@ -137,6 +144,7 @@ if Backbone?
|
||||
anonymous: anonymous
|
||||
anonymous_to_peers: anonymous_to_peers
|
||||
auto_subscribe: follow
|
||||
group_id: group
|
||||
error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors"))
|
||||
success: (response, textStatus) =>
|
||||
# TODO: Move this out of the callback, this makes it feel sluggish
|
||||
|
||||
@@ -89,20 +89,31 @@ def create_thread(request, course_id, commentable_id):
|
||||
'user_id' : request.user.id,
|
||||
})
|
||||
|
||||
|
||||
user = cc.User.from_django_user(request.user)
|
||||
|
||||
# Cohort the thread if the commentable is cohorted.
|
||||
if is_commentable_cohorted(course_id, commentable_id):
|
||||
user_group_id = get_cohort_id(request.user, course_id)
|
||||
print "********************** IS COHORTED"
|
||||
user_group_id = get_cohort_id(user, course_id)
|
||||
print "********************** USER GOUP ID IS"
|
||||
print user_group_id
|
||||
# TODO (vshnayder): once we have more than just cohorts, we'll want to
|
||||
# change this to a single get_group_for_user_and_commentable function
|
||||
# that can do different things depending on the commentable_id
|
||||
if cached_has_permission(request.user, "see_all_cohorts", course_id):
|
||||
if cached_has_permission(request.user, "see_all_cohorts", course_id) or True:
|
||||
# admins can optionally choose what group to post as
|
||||
|
||||
print "********************** CACHED HAS PERMISSIONS TRUE"
|
||||
group_id = post.get('group_id', user_group_id)
|
||||
else:
|
||||
# regular users always post with their own id.
|
||||
print "********************** CACHED HAS PERMISSIONS FALSE"
|
||||
group_id = user_group_id
|
||||
|
||||
print "\n\n\n\n\n********************************* group is "
|
||||
print group_id
|
||||
print "\n\n\n\n\n********************************* and post is"
|
||||
print post
|
||||
thread.update_attributes(group_id=group_id)
|
||||
|
||||
thread.save()
|
||||
|
||||
@@ -11,7 +11,7 @@ from django.contrib.auth.models import User
|
||||
|
||||
from mitxmako.shortcuts import render_to_response, render_to_string
|
||||
from courseware.courses import get_course_with_access
|
||||
from course_groups.cohorts import get_cohort_id, get_course_cohorts
|
||||
from course_groups.cohorts import get_cohort_id, get_course_cohorts, get_cohorted_commentables, is_course_cohorted
|
||||
from courseware.access import has_access
|
||||
|
||||
from urllib import urlencode
|
||||
@@ -128,7 +128,8 @@ def forum_form_discussion(request, course_id):
|
||||
log.error("Error loading forum discussion threads: %s" % str(err))
|
||||
raise Http404
|
||||
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
user = cc.User.from_django_user(request.user)
|
||||
user_info = user.to_dict()
|
||||
|
||||
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
|
||||
|
||||
@@ -167,13 +168,13 @@ def forum_form_discussion(request, course_id):
|
||||
'course_id': course.id,
|
||||
'category_map': category_map,
|
||||
'roles': saxutils.escape(json.dumps(utils.get_role_ids(course_id)), escapedict),
|
||||
#'is_moderator': cached_has_permission(request.user, "see_all_cohorts", course_id),
|
||||
'is_moderator': True,
|
||||
'cohorts': get_course_cohorts(course_id)
|
||||
'is_moderator': cached_has_permission(request.user, "see_all_cohorts", course_id),
|
||||
'cohorts': get_course_cohorts(course_id),
|
||||
'cohort': get_cohort_id(user, course_id),
|
||||
'cohorted_commentables': get_cohorted_commentables(course_id),
|
||||
'is_course_cohorted': is_course_cohorted(course_id)
|
||||
}
|
||||
# print "start rendering.."
|
||||
print "\n\n\n\n\n\n*************************************"
|
||||
print context
|
||||
return render_to_response('discussion/index.html', context)
|
||||
|
||||
@login_required
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</%def>
|
||||
|
||||
<%def name="render_entry(entries, entry)">
|
||||
<li><a href="#" class="topic" data-discussion_id="${entries[entry]['id']}">${entry}</a></li>
|
||||
<li><a href="#" class="topic" data-discussion_id="${entries[entry]['id']}" cohorted = "${entries[entry]['id'] in cohorted_commentables}">${entry}</a></li>
|
||||
</%def>
|
||||
|
||||
<%def name="render_category(categories, category)">
|
||||
@@ -21,6 +21,9 @@
|
||||
</li>
|
||||
</%def>
|
||||
|
||||
|
||||
|
||||
|
||||
<article class="new-post-article">
|
||||
<div class="inner-wrapper">
|
||||
<form class="new-post-form">
|
||||
@@ -45,14 +48,18 @@
|
||||
%elif course.metadata.get("allow_anonymous_to_peers", False):
|
||||
<input type="checkbox" name="anonymous_to_peers" class="discussion-anonymous-to-peers" id="new-post-anonymous-to-peers"><label for="new-post-anonymous-to-peers">post anonymously to classmates</label>
|
||||
%endif
|
||||
%if is_moderator:
|
||||
<div class="form-group-label">
|
||||
%if is_course_cohorted:
|
||||
<div class="form-group-label choose-cohort">
|
||||
Make visible to:
|
||||
<select class="group-filter-select">
|
||||
<select class="group-filter-select new-post-group" name = "group_id">
|
||||
<option >All Groups</option>
|
||||
%for c in cohorts:
|
||||
<option value="g1">Group 1</option>
|
||||
%endfor
|
||||
%if is_moderator:
|
||||
%for c in cohorts:
|
||||
<option value="${c.id}">${c.name}</option>
|
||||
%endfor
|
||||
%else:
|
||||
<option value="${cohort}">My Cohort</option>
|
||||
%endif
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user