diff --git a/common/djangoapps/course_groups/cohorts.py b/common/djangoapps/course_groups/cohorts.py index 5c8a1ca067..4fda68bf36 100644 --- a/common/djangoapps/course_groups/cohorts.py +++ b/common/djangoapps/course_groups/cohorts.py @@ -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 diff --git a/common/static/coffee/src/discussion/views/new_post_view.coffee b/common/static/coffee/src/discussion/views/new_post_view.coffee index 1c49fdbc8e..be146587df 100644 --- a/common/static/coffee/src/discussion/views/new_post_view.coffee +++ b/common/static/coffee/src/discussion/views/new_post_view.coffee @@ -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) + ' ▾') @@ -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 diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 777c7bafce..6e86e629a1 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -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() diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 715cb575d4..b5c65202d9 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -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 diff --git a/lms/templates/discussion/_new_post.html b/lms/templates/discussion/_new_post.html index 3af63f9ea1..1bc6148dbe 100644 --- a/lms/templates/discussion/_new_post.html +++ b/lms/templates/discussion/_new_post.html @@ -9,7 +9,7 @@ %def> <%def name="render_entry(entries, entry)"> -