Merge branch 'feature/arjun/new-discussions' of github.com:MITx/mitx into feature/arjun/new-discussions
This commit is contained in:
@@ -62,19 +62,31 @@ def ajax_content_response(request, course_id, content, template_name):
|
||||
@login_required
|
||||
@permitted
|
||||
def create_thread(request, course_id, commentable_id):
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
post = request.POST
|
||||
|
||||
if course.metadata.get("allow_anonymous", True):
|
||||
anonymous = post.get('anonymous', 'false').lower() == 'true'
|
||||
else:
|
||||
anonymous = False
|
||||
|
||||
if course.metadata.get("allow_anonymous_to_peers", False):
|
||||
anonymous_to_peers = post.get('anonymous_to_peers', 'false').lower() == 'true'
|
||||
else:
|
||||
anonymous_to_peers = False
|
||||
|
||||
thread = cc.Thread(**extract(post, ['body', 'title', 'tags']))
|
||||
thread.update_attributes(**{
|
||||
'anonymous' : post.get('anonymous', 'false').lower() == 'true',
|
||||
'commentable_id' : commentable_id,
|
||||
'course_id' : course_id,
|
||||
'user_id' : request.user.id,
|
||||
'anonymous' : anonymous,
|
||||
'anonymous_to_peers' : anonymous_to_peers,
|
||||
'commentable_id' : commentable_id,
|
||||
'course_id' : course_id,
|
||||
'user_id' : request.user.id,
|
||||
})
|
||||
thread.save()
|
||||
if post.get('auto_subscribe', 'false').lower() == 'true':
|
||||
user = cc.User.from_django_user(request.user)
|
||||
user.follow(thread)
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
data = thread.to_dict()
|
||||
if courseware_context:
|
||||
@@ -99,8 +111,20 @@ def update_thread(request, course_id, thread_id):
|
||||
def _create_comment(request, course_id, thread_id=None, parent_id=None):
|
||||
post = request.POST
|
||||
comment = cc.Comment(**extract(post, ['body']))
|
||||
|
||||
if course.metadata.get("allow_anonymous", True):
|
||||
anonymous = post.get('anonymous', 'false').lower() == 'true'
|
||||
else:
|
||||
anonymous = False
|
||||
|
||||
if course.metadata.get("allow_anonymous_to_peers", False):
|
||||
anonymous_to_peers = post.get('anonymous_to_peers', 'false').lower() == 'true'
|
||||
else:
|
||||
anonymous_to_peers = False
|
||||
|
||||
comment.update_attributes(**{
|
||||
'anonymous' : post.get('anonymous', 'false').lower() == 'true',
|
||||
'anonymous' : anonymous,
|
||||
'anonymous_to_peers' : anonymous_to_peers,
|
||||
'user_id' : request.user.id,
|
||||
'course_id' : course_id,
|
||||
'thread_id' : thread_id,
|
||||
|
||||
@@ -92,6 +92,8 @@ def inline_discussion(request, course_id, discussion_id):
|
||||
Renders JSON for DiscussionModules
|
||||
"""
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
|
||||
try:
|
||||
threads, query_params = get_threads(request, course_id, discussion_id, per_page=INLINE_THREADS_PER_PAGE)
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
@@ -106,6 +108,9 @@ def inline_discussion(request, course_id, discussion_id):
|
||||
|
||||
annotated_content_info = reduce(merge_dict, map(infogetter, threads), {})
|
||||
|
||||
allow_anonymous = course.metadata.get("allow_anonymous", True)
|
||||
allow_anonymous_to_peers = course.metadata.get("allow_anonymous_to_peers", False)
|
||||
|
||||
return utils.JsonResponse({
|
||||
'discussion_data': map(utils.safe_content, threads),
|
||||
'user_info': user_info,
|
||||
@@ -113,6 +118,8 @@ def inline_discussion(request, course_id, discussion_id):
|
||||
'page': query_params['page'],
|
||||
'num_pages': query_params['num_pages'],
|
||||
'roles': utils.get_role_ids(course_id),
|
||||
'allow_anonymous_to_peers': allow_anonymous_to_peers,
|
||||
'allow_anonymous': allow_anonymous,
|
||||
})
|
||||
|
||||
@login_required
|
||||
|
||||
@@ -188,7 +188,9 @@ def initialize_discussion_info(course):
|
||||
"sort_key": entry["sort_key"],
|
||||
"start_date": entry["start_date"]}
|
||||
|
||||
for topic, entry in course.metadata.get('discussion_topics', {}).items():
|
||||
default_topics = {'General': course.location.html_id()}
|
||||
discussion_topics = course.metadata.get('discussion_topics', default_topics)
|
||||
for topic, entry in discussion_topics.items():
|
||||
category_map['entries'][topic] = {"id": entry["id"],
|
||||
"sort_key": entry.get("sort_key", topic),
|
||||
"start_date": time.gmtime()}
|
||||
@@ -327,15 +329,14 @@ def get_courseware_context(content, course):
|
||||
|
||||
def safe_content(content):
|
||||
fields = [
|
||||
'id', 'title', 'body', 'course_id', 'anonymous', 'endorsed',
|
||||
'parent_id', 'thread_id', 'votes', 'closed',
|
||||
'created_at', 'updated_at', 'depth', 'type',
|
||||
'commentable_id', 'comments_count', 'at_position_list',
|
||||
'children', 'highlighted_title', 'highlighted_body',
|
||||
'id', 'title', 'body', 'course_id', 'anonymous', 'anonymous_to_peers',
|
||||
'endorsed', 'parent_id', 'thread_id', 'votes', 'closed', 'created_at',
|
||||
'updated_at', 'depth', 'type', 'commentable_id', 'comments_count',
|
||||
'at_position_list', 'children', 'highlighted_title', 'highlighted_body',
|
||||
'courseware_title', 'courseware_location', 'tags'
|
||||
]
|
||||
|
||||
if content.get('anonymous') is False:
|
||||
if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False):
|
||||
fields += ['username', 'user_id']
|
||||
|
||||
return strip_none(extract(content, fields))
|
||||
|
||||
@@ -7,15 +7,14 @@ import settings
|
||||
class Comment(models.Model):
|
||||
|
||||
accessible_fields = [
|
||||
'id', 'body', 'anonymous', 'course_id',
|
||||
'endorsed', 'parent_id', 'thread_id',
|
||||
'username', 'votes', 'user_id', 'closed',
|
||||
'created_at', 'updated_at', 'depth',
|
||||
'at_position_list', 'type', 'commentable_id',
|
||||
'id', 'body', 'anonymous', 'anonymous_to_peers', 'course_id',
|
||||
'endorsed', 'parent_id', 'thread_id', 'username', 'votes', 'user_id',
|
||||
'closed', 'created_at', 'updated_at', 'depth', 'at_position_list',
|
||||
'type', 'commentable_id',
|
||||
]
|
||||
|
||||
updatable_fields = [
|
||||
'body', 'anonymous', 'course_id', 'closed',
|
||||
'body', 'anonymous', 'anonymous_to_peers', 'course_id', 'closed',
|
||||
'user_id', 'endorsed',
|
||||
]
|
||||
|
||||
|
||||
@@ -6,17 +6,14 @@ import settings
|
||||
class Thread(models.Model):
|
||||
|
||||
accessible_fields = [
|
||||
'id', 'title', 'body', 'anonymous',
|
||||
'course_id', 'closed', 'tags', 'votes',
|
||||
'commentable_id', 'username', 'user_id',
|
||||
'created_at', 'updated_at', 'comments_count',
|
||||
'at_position_list', 'children', 'type',
|
||||
'highlighted_title', 'highlighted_body',
|
||||
'endorsed'
|
||||
'id', 'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id',
|
||||
'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id',
|
||||
'created_at', 'updated_at', 'comments_count', 'at_position_list',
|
||||
'children', 'type', 'highlighted_title', 'highlighted_body', 'endorsed'
|
||||
]
|
||||
|
||||
updatable_fields = [
|
||||
'title', 'body', 'anonymous', 'course_id',
|
||||
'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id',
|
||||
'closed', 'tags', 'user_id', 'commentable_id',
|
||||
]
|
||||
|
||||
|
||||
@@ -68,10 +68,12 @@ if Backbone?
|
||||
window.user = new DiscussionUser(response.user_info)
|
||||
Content.loadContentInfos(response.annotated_content_info)
|
||||
DiscussionUtil.loadRoles(response.roles)
|
||||
allow_anonymous = response.allow_anonymous
|
||||
allow_anonymous_to_peers = response.allow_anonymous_to_peers
|
||||
# $elem.html("Hide Discussion")
|
||||
@discussion = new Discussion()
|
||||
@discussion.reset(response.discussion_data, {silent: false})
|
||||
$discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data, 'discussionId': discussionId})
|
||||
$discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data, 'discussionId': discussionId, 'allow_anonymous_to_peers': allow_anonymous_to_peers, 'allow_anonymous': allow_anonymous})
|
||||
if @$('section.discussion').length
|
||||
@$('section.discussion').replaceWith($discussion)
|
||||
else
|
||||
|
||||
@@ -134,6 +134,6 @@ if Backbone?
|
||||
renderTemplate: ->
|
||||
@template = DiscussionUtil.getTemplate('_inline_thread_show')
|
||||
params = @model.toJSON()
|
||||
if not @model.get('anonymous')
|
||||
if @model.get('username')?
|
||||
params = $.extend(params, user:{username: @model.username, user_url: @model.user_url})
|
||||
Mustache.render(@template, params)
|
||||
|
||||
@@ -8,7 +8,9 @@ if Backbone?
|
||||
@maxNameWidth = 100
|
||||
|
||||
DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "new-post-body"
|
||||
@$(".new-post-tags").tagsInput DiscussionUtil.tagsInputOptions()
|
||||
|
||||
# TODO tags: commenting out til we know what to do with them
|
||||
#@$(".new-post-tags").tagsInput DiscussionUtil.tagsInputOptions()
|
||||
|
||||
events:
|
||||
"submit .new-post-form": "createPost"
|
||||
@@ -23,9 +25,12 @@ if Backbone?
|
||||
event.preventDefault()
|
||||
title = @$(".new-post-title").val()
|
||||
body = @$(".new-post-body").find(".wmd-input").val()
|
||||
tags = @$(".new-post-tags").val()
|
||||
|
||||
anonymous = false || @$("input.discussion-anonymous").is(":checked")
|
||||
# TODO tags: commenting out til we know what to do with them
|
||||
#tags = @$(".new-post-tags").val()
|
||||
|
||||
anonymous = false || @$("input.discussion-anonymous").is(":checked")
|
||||
anonymous_to_peers = false || @$("input.discussion-anonymous-to-peers").is(":checked")
|
||||
follow = false || @$("input.discussion-follow").is(":checked")
|
||||
|
||||
url = DiscussionUtil.urlFor('create_thread', @topicId)
|
||||
@@ -40,8 +45,12 @@ if Backbone?
|
||||
data:
|
||||
title: title
|
||||
body: body
|
||||
tags: tags
|
||||
|
||||
# TODO tags: commenting out til we know what to do with them
|
||||
#tags: tags
|
||||
|
||||
anonymous: anonymous
|
||||
anonymous_to_peers: anonymous_to_peers
|
||||
auto_subscribe: follow
|
||||
error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors"))
|
||||
success: (response, textStatus) =>
|
||||
@@ -51,6 +60,9 @@ if Backbone?
|
||||
@$el.hide()
|
||||
@$(".new-post-title").val("").attr("prev-text", "")
|
||||
@$(".new-post-body textarea").val("").attr("prev-text", "")
|
||||
@$(".new-post-tags").val("")
|
||||
@$(".new-post-tags").importTags("")
|
||||
|
||||
# TODO tags, commenting out til we know what to do with them
|
||||
#@$(".new-post-tags").val("")
|
||||
#@$(".new-post-tags").importTags("")
|
||||
|
||||
@collection.add thread
|
||||
|
||||
@@ -116,8 +116,9 @@ if Backbone?
|
||||
body = @$(".new-post-body").find(".wmd-input").val()
|
||||
tags = @$(".new-post-tags").val()
|
||||
|
||||
anonymous = false || @$("input.discussion-anonymous").is(":checked")
|
||||
follow = false || @$("input.discussion-follow").is(":checked")
|
||||
anonymous = false || @$("input.discussion-anonymous").is(":checked")
|
||||
anonymous_to_peers = false || @$("input.discussion-anonymous-to-peers").is(":checked")
|
||||
follow = false || @$("input.discussion-follow").is(":checked")
|
||||
|
||||
$formTopicDropBtn.bind('click', showFormTopicDrop)
|
||||
$formTopicDropMenu.bind('click', setFormTopic)
|
||||
@@ -136,6 +137,7 @@ if Backbone?
|
||||
body: body
|
||||
tags: tags
|
||||
anonymous: anonymous
|
||||
anonymous_to_peers: anonymous_to_peers
|
||||
auto_subscribe: follow
|
||||
error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors"))
|
||||
success: (response, textStatus) =>
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
<div class="options">
|
||||
<input type="checkbox" name="follow" class="discussion-follow" class="discussion-follow" id="new-post-follow" checked><label for="new-post-follow">follow this post</label>
|
||||
<br>
|
||||
<input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
|
||||
% if course.metadata.get("allow_anonymous", True):
|
||||
<input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
|
||||
%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
|
||||
</div>
|
||||
</div>
|
||||
<div class="right-column">
|
||||
@@ -18,9 +22,10 @@
|
||||
<div class="new-post-body" name="body" placeholder="Enter your question or comment…"></div>
|
||||
<!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>-->
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="text" class="new-post-tags" name="tags" placeholder="Tags">
|
||||
</div>
|
||||
## TODO commenting out tags til we figure out what to do with them
|
||||
##<div class="form-row">
|
||||
## <input type="text" class="new-post-tags" name="tags" placeholder="Tags">
|
||||
##</div>
|
||||
<input type="submit" class="submit" value="Add post">
|
||||
<a href="#" class="new-post-cancel">Cancel</a>
|
||||
</div>
|
||||
|
||||
@@ -40,7 +40,11 @@
|
||||
<div class="options">
|
||||
<input type="checkbox" name="follow" class="discussion-follow" class="discussion-follow" id="new-post-follow" checked><label for="new-post-follow">follow this post</label>
|
||||
<br>
|
||||
<input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
|
||||
% if course.metadata.get("allow_anonymous", True):
|
||||
<input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
|
||||
%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
|
||||
</div>
|
||||
</div>
|
||||
<div class="right-column">
|
||||
@@ -52,9 +56,10 @@
|
||||
<div class="new-post-body" name="body" placeholder="Enter your question or comment…"></div>
|
||||
<!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>-->
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="text" class="new-post-tags" name="tags" placeholder="Tags">
|
||||
</div>
|
||||
## TODO tags commenting out til we figure out what to do w/ tags
|
||||
##<div class="form-row">
|
||||
## <input type="text" class="new-post-tags" name="tags" placeholder="Tags">
|
||||
##</div>
|
||||
<input type="submit" class="submit" value="Add post">
|
||||
<a href="#" class="new-post-cancel">Cancel</a>
|
||||
</div>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<a href="#" class="vote-btn discussion-vote discussion-vote-up" data-role="discussion-vote"><span class="plus-icon">+</span> <span class='votes-count-number'>${'<%- votes["up_count"] %>'}</span></a>
|
||||
<h1>${'<%- title %>'}</h1>
|
||||
<p class="posted-details">
|
||||
${"<% if (!obj.anonymous) { %>"}
|
||||
${"<% if (obj.username) { %>"}
|
||||
<a href="${'<%- user_url %>'}" class="username">${'<%- username %>'}</a>
|
||||
${"<% } else {print('anonymous');} %>"}
|
||||
<span class="timeago" title="${'<%- created_at %>'}">${'<%- created_at %>'}</span>
|
||||
|
||||
@@ -14,15 +14,21 @@
|
||||
<div class="new-post-body" name="body" placeholder="Enter your question or comment…"></div>
|
||||
<!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>-->
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input type="text" class="new-post-tags" name="tags" placeholder="Tags">
|
||||
</div>
|
||||
{{! TODO tags: Getting rid of tags for now. }}
|
||||
{{!<div class="form-row">}}
|
||||
{{! <input type="text" class="new-post-tags" name="tags" placeholder="Tags">}}
|
||||
{{!</div>}}
|
||||
<input type="submit" class="submit" value="Add post">
|
||||
<a href="#" class="new-post-cancel">Cancel</a>
|
||||
<div class="options">
|
||||
<input type="checkbox" name="follow" class="discussion-follow" class="discussion-follow" id="new-post-follow" checked><label for="new-post-follow">follow this post</label>
|
||||
<br>
|
||||
<input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
|
||||
{{#allow_anonymous}}
|
||||
<input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
|
||||
{{/allow_anonymous}}
|
||||
{{#allow_anonymous_to_peers}}
|
||||
<input type="checkbox" name="anonymous" class="discussion-anonymous-to-peers" id="new-post-anonymous-to-peers"><label for="new-post-anonymous-to-peers">post anonymously to classmates</label>
|
||||
{{/allow_anonymous_to_peers}}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
<input type="text" class="new-post-title title-input" placeholder="Title" />
|
||||
<div class="new-post-similar-posts-wrapper" style="display: none"></div>
|
||||
<div class="new-post-body reply-body"></div>
|
||||
<input class="new-post-tags" placeholder="Tags" />
|
||||
{{! TODO tags: Getting rid of tags for now. }}
|
||||
{{! <input class="new-post-tags" placeholder="Tags" /> }}
|
||||
<div class="post-options">
|
||||
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-${discussion_id}">
|
||||
<label for="discussion-post-anonymously-${discussion_id}">post anonymously</label>
|
||||
|
||||
Reference in New Issue
Block a user