Commit 310ecead by Victor Shnayder

Merge pull request #1582 from MITx/feature/kevin/cohorts_take_3

Feature/kevin/cohorts take 3
parents c236b2c8 e1ef6a83
...@@ -79,7 +79,7 @@ if Backbone? ...@@ -79,7 +79,7 @@ if Backbone?
#determined in the coffeescript based on whether or not there's a #determined in the coffeescript based on whether or not there's a
#group id #group id
if response.is_cohorted if response.is_cohorted and response.is_moderator
source = "script#_inline_discussion_cohorted" source = "script#_inline_discussion_cohorted"
else else
source = "script#_inline_discussion" source = "script#_inline_discussion"
......
...@@ -96,24 +96,25 @@ def create_thread(request, course_id, commentable_id): ...@@ -96,24 +96,25 @@ def create_thread(request, course_id, commentable_id):
#kevinchugh because the new requirement is that all groups will be determined #kevinchugh because the new requirement is that all groups will be determined
#by the group id in the request this all goes away #by the group id in the request this all goes away
#not anymore, only for admins
# 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(user, course_id) user_group_id = get_cohort_id(user, course_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):
# admins can optionally choose what group to post as # admins can optionally choose what group to post as
# 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.
# group_id = user_group_id group_id = user_group_id
group_id = post.get('group_id')
if group_id: if group_id:
thread.update_attributes(group_id=group_id) thread.update_attributes(group_id=group_id)
log.debug("Saving thread %r", thread.attributes)
thread.save() thread.save()
if post.get('auto_subscribe', 'false').lower() == 'true': if post.get('auto_subscribe', 'false').lower() == 'true':
......
...@@ -133,6 +133,7 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -133,6 +133,7 @@ def inline_discussion(request, course_id, discussion_id):
#if the commentable is cohorted, otherwise everything is not cohorted #if the commentable is cohorted, otherwise everything is not cohorted
#and no one has the option of choosing a cohort #and no one has the option of choosing a cohort
is_cohorted = is_course_cohorted(course_id) and is_commentable_cohorted(course_id, discussion_id) is_cohorted = is_course_cohorted(course_id) and is_commentable_cohorted(course_id, discussion_id)
is_moderator = cached_has_permission(request.user, "see_all_cohorts", course_id)
cohorts_list = list() cohorts_list = list()
...@@ -140,26 +141,16 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -140,26 +141,16 @@ def inline_discussion(request, course_id, discussion_id):
cohorts_list.append({'name':'All Groups','id':None}) cohorts_list.append({'name':'All Groups','id':None})
#if you're a mod, send all cohorts and let you pick #if you're a mod, send all cohorts and let you pick
if cached_has_permission(request.user, "see_all_cohorts", course_id):
if is_moderator:
cohorts = get_course_cohorts(course_id) cohorts = get_course_cohorts(course_id)
for c in cohorts: for c in cohorts:
cohorts_list.append({'name':c.name, 'id':c.id}) cohorts_list.append({'name':c.name, 'id':c.id})
else: else:
#otherwise, just make a dictionary of two #students don't get to choose
user_cohort = get_cohort(cc_user, course_id)
if user_cohort:
user_cohort_name = user_cohort.name
user_cohort_id = user_cohort.id
else:
user_cohort_name = user_cohort_id = None
if user_cohort:
cohorts_list.append({'name':user_cohort_name, 'id':user_cohort_id})
else:
cohorts_list = None cohorts_list = None
return utils.JsonResponse({ return utils.JsonResponse({
'discussion_data': map(utils.safe_content, threads), 'discussion_data': map(utils.safe_content, threads),
'user_info': user_info, 'user_info': user_info,
...@@ -170,6 +161,7 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -170,6 +161,7 @@ def inline_discussion(request, course_id, discussion_id):
'allow_anonymous_to_peers': allow_anonymous_to_peers, 'allow_anonymous_to_peers': allow_anonymous_to_peers,
'allow_anonymous': allow_anonymous, 'allow_anonymous': allow_anonymous,
'cohorts': cohorts_list, 'cohorts': cohorts_list,
'is_moderator': is_moderator,
'is_cohorted': is_cohorted 'is_cohorted': is_cohorted
}) })
......
...@@ -46,21 +46,18 @@ ...@@ -46,21 +46,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_course_cohorted: %if is_course_cohorted and is_moderator:
<div class="form-group-label choose-cohort"> <div class="form-group-label choose-cohort">
Make visible to: Make visible to:
<select class="group-filter-select new-post-group" name = "group_id"> <select class="group-filter-select new-post-group" name = "group_id">
<option value="">All Groups</option> <option value="">All Groups</option>
%if is_moderator:
%for c in cohorts: %for c in cohorts:
<option value="${c.id}">${c.name}</option> <option value="${c.id}"
%endfor %if user_cohort and str(user_cohort) == str(c.id):
%else: selected
%if user_cohort:
<option value="${user_cohort}">My Cohort</option>
%endif
%endif %endif
>${c.name}</option>
%endfor
</select> </select>
</div> </div>
%endif %endif
......
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