Commit a8a99759 by Your Name

Merge branch 'feature/kevin/groups_ui_changes' of github.com:MITx/mitx into…

Merge branch 'feature/kevin/groups_ui_changes' of github.com:MITx/mitx into feature/kevin/groups_ui_changes
parents 6e8e74aa f7ba14ae
...@@ -86,27 +86,32 @@ def create_thread(request, course_id, commentable_id): ...@@ -86,27 +86,32 @@ def create_thread(request, course_id, commentable_id):
'anonymous_to_peers' : anonymous_to_peers, 'anonymous_to_peers' : anonymous_to_peers,
'commentable_id' : commentable_id, 'commentable_id' : commentable_id,
'course_id' : course_id, 'course_id' : course_id,
'user_id' : request.user.id, 'user_id' : request.user.id
}) })
user = cc.User.from_django_user(request.user) user = cc.User.from_django_user(request.user)
#kevinchugh because the new requirement is that all groups will be determined
#by the group id in the request this all goes away
# 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
thread.update_attributes(group_id=group_id) if 'group_id' in post.keys():
thread.update_attributes(group_id=post['group_id'])
thread.save() thread.save()
print thread
if post.get('auto_subscribe', 'false').lower() == 'true': if post.get('auto_subscribe', 'false').lower() == 'true':
user = cc.User.from_django_user(request.user) user = cc.User.from_django_user(request.user)
user.follow(thread) user.follow(thread)
......
...@@ -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, get_cohorted_commentables, is_course_cohorted from course_groups.cohorts import get_cohort_id, get_course_cohorts, get_cohorted_commentables, is_course_cohorted, get_cohort_by_id
from courseware.access import has_access from courseware.access import has_access
from urllib import urlencode from urllib import urlencode
...@@ -73,6 +73,12 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG ...@@ -73,6 +73,12 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
threads, page, num_pages = cc.Thread.search(query_params) threads, page, num_pages = cc.Thread.search(query_params)
#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
query_params['page'] = page query_params['page'] = page
query_params['num_pages'] = num_pages query_params['num_pages'] = num_pages
...@@ -133,6 +139,8 @@ def forum_form_discussion(request, course_id): ...@@ -133,6 +139,8 @@ def forum_form_discussion(request, course_id):
for thread in threads: for thread in threads:
courseware_context = get_courseware_context(thread, course) courseware_context = get_courseware_context(thread, course)
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 courseware_context: if courseware_context:
thread.update(courseware_context) thread.update(courseware_context)
if request.is_ajax(): if request.is_ajax():
...@@ -152,10 +160,8 @@ def forum_form_discussion(request, course_id): ...@@ -152,10 +160,8 @@ def forum_form_discussion(request, course_id):
#trending_tags = cc.search_trending_tags( #trending_tags = cc.search_trending_tags(
# course_id, # course_id,
#) #)
cohorts = get_course_cohorts(course_id) cohorts = get_course_cohorts(course_id)
cohort_dictionary = dict()
for c in cohorts:
cohort_dictionary[c.id] = c.name
context = { context = {
'csrf': csrf(request)['csrf_token'], 'csrf': csrf(request)['csrf_token'],
...@@ -172,14 +178,11 @@ def forum_form_discussion(request, course_id): ...@@ -172,14 +178,11 @@ def forum_form_discussion(request, course_id):
'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),
'cohorts': cohorts, 'cohorts': cohorts,
'cohort_map': cohort_dictionary,
'user_cohort': get_cohort_id(user, course_id), 'user_cohort': get_cohort_id(user, course_id),
'cohorted_commentables': get_cohorted_commentables(course_id), 'cohorted_commentables': get_cohorted_commentables(course_id),
'is_course_cohorted': is_course_cohorted(course_id) 'is_course_cohorted': is_course_cohorted(course_id)
} }
# print "start rendering.." # print "start rendering.."
print "\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
...@@ -228,6 +231,8 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -228,6 +231,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
courseware_context = get_courseware_context(thread, course) courseware_context = get_courseware_context(thread, course)
if courseware_context: if courseware_context:
thread.update(courseware_context) thread.update(courseware_context)
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
threads = [utils.safe_content(thread) for thread in threads] threads = [utils.safe_content(thread) for thread in threads]
...@@ -241,7 +246,6 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -241,7 +246,6 @@ def single_thread(request, course_id, discussion_id, thread_id):
# course_id, # course_id,
#) #)
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)
context = { context = {
......
...@@ -374,7 +374,7 @@ def safe_content(content): ...@@ -374,7 +374,7 @@ def safe_content(content):
'updated_at', 'depth', 'type', 'commentable_id', 'comments_count', 'updated_at', 'depth', 'type', 'commentable_id', 'comments_count',
'at_position_list', 'children', 'highlighted_title', 'highlighted_body', 'at_position_list', 'children', 'highlighted_title', 'highlighted_body',
'courseware_title', 'courseware_url', 'tags', 'unread_comments_count', 'courseware_title', 'courseware_url', 'tags', 'unread_comments_count',
'read', 'read', 'group_id', 'group_name'
] ]
if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False): if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False):
......
...@@ -10,12 +10,12 @@ class Thread(models.Model): ...@@ -10,12 +10,12 @@ class Thread(models.Model):
'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id', 'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id',
'created_at', 'updated_at', 'comments_count', 'unread_comments_count', 'created_at', 'updated_at', 'comments_count', 'unread_comments_count',
'at_position_list', 'children', 'type', 'highlighted_title', 'at_position_list', 'children', 'type', 'highlighted_title',
'highlighted_body', 'endorsed', 'read', 'group_id' 'highlighted_body', 'endorsed', 'read', 'group_id', 'group_name'
] ]
updatable_fields = [ updatable_fields = [
'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id', 'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id',
'closed', 'tags', 'user_id', 'commentable_id', 'group_id' 'closed', 'tags', 'user_id', 'commentable_id', 'group_id', 'group_name'
] ]
initializable_fields = updatable_fields initializable_fields = updatable_fields
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<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 >All Groups</option> <option value="">All Groups</option>
%if is_moderator: %if is_moderator:
%for c in cohorts: %for c in cohorts:
<option value="${c.id}">${c.name}</option> <option value="${c.id}">${c.name}</option>
......
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
<div class="discussion-post"> <div class="discussion-post">
<div><a href="javascript:void(0)" class="dogear action-follow" data-tooltip="follow"></a></div> <div><a href="javascript:void(0)" class="dogear action-follow" data-tooltip="follow"></a></div>
<header> <header>
%if thread['group_id']
<div class="group-visibility-label">This post visible only to Group ${cohort_dictionary[thread['group_id']]}.</div> ${"<% if (obj.group_id) { %>"}
%endif <div class="group-visibility-label">This post visible only to Group ${"<%- obj.group_name%>"}.</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> <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>
<h1>${'<%- title %>'}</h1> <h1>${'<%- title %>'}</h1>
<p class="posted-details"> <p class="posted-details">
......
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