Commit 3fa67c14 by Your Name

allow moderators and students to select cohort on post creation

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