Commit 65b8bcd6 by Ibrahim Awwal

Make voting render properly in inline discussions. Also might have fixed

following if it wasn't working before.
parent f33b98fa
...@@ -38,11 +38,10 @@ def permitted(fn): ...@@ -38,11 +38,10 @@ def permitted(fn):
else: else:
content = None content = None
return content return content
if check_permissions_by_view(request.user, kwargs['course_id'], fetch_content(), request.view_name): if check_permissions_by_view(request.user, kwargs['course_id'], fetch_content(), request.view_name):
return fn(request, *args, **kwargs) return fn(request, *args, **kwargs)
else: else:
return JsonError("unauthorized") return JsonError("unauthorized", status=401)
return wrapper return wrapper
def ajax_content_response(request, course_id, content, template_name): def ajax_content_response(request, course_id, content, template_name):
......
...@@ -136,10 +136,16 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -136,10 +136,16 @@ def inline_discussion(request, course_id, discussion_id):
# html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id, \ # html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id, \
# query_params=query_params) # query_params=query_params)
user_info = cc.User.from_django_user(request.user).to_dict() user_info = cc.User.from_django_user(request.user).to_dict()
def infogetter(thread):
return utils.get_annotated_content_infos(course_id, thread, request.user, user_info)
annotated_content_info = reduce(merge_dict, map(infogetter, threads), {})
return utils.JsonResponse({ return utils.JsonResponse({
# 'html': html, # 'html': html,
'discussion_data': map(utils.safe_content, threads), 'discussion_data': map(utils.safe_content, threads),
'user_info': user_info, 'user_info': user_info,
'annotated_content_info': annotated_content_info
}) })
def render_search_bar(request, course_id, discussion_id=None, text=''): def render_search_bar(request, course_id, discussion_id=None, text=''):
......
...@@ -149,14 +149,14 @@ class JsonResponse(HttpResponse): ...@@ -149,14 +149,14 @@ class JsonResponse(HttpResponse):
mimetype='application/json; charset=utf8') mimetype='application/json; charset=utf8')
class JsonError(HttpResponse): class JsonError(HttpResponse):
def __init__(self, error_messages=[]): def __init__(self, error_messages=[], status=400):
if isinstance(error_messages, str): if isinstance(error_messages, str):
error_messages = [error_messages] error_messages = [error_messages]
content = simplejson.dumps({'errors': error_messages}, content = simplejson.dumps({'errors': error_messages},
indent=2, indent=2,
ensure_ascii=False) ensure_ascii=False)
super(JsonError, self).__init__(content, super(JsonError, self).__init__(content,
mimetype='application/json; charset=utf8', status=400) mimetype='application/json; charset=utf8', status=status)
class HtmlResponse(HttpResponse): class HtmlResponse(HttpResponse):
def __init__(self, html=''): def __init__(self, html=''):
......
...@@ -23,8 +23,8 @@ if Backbone? ...@@ -23,8 +23,8 @@ if Backbone?
type: "GET" type: "GET"
dataType: 'json' dataType: 'json'
success: (response, textStatus) => success: (response, textStatus) =>
#@$el.append(response.html)
window.user = new DiscussionUser(response.user_info) window.user = new DiscussionUser(response.user_info)
Content.loadContentInfos(response.annotated_content_info)
$(event.target).html("Hide Discussion") $(event.target).html("Hide Discussion")
discussion = new Discussion() discussion = new Discussion()
discussion.reset(response.discussion_data, {silent: false}) discussion.reset(response.discussion_data, {silent: false})
......
...@@ -21,10 +21,6 @@ class @DiscussionThreadInlineView extends DiscussionContentView ...@@ -21,10 +21,6 @@ class @DiscussionThreadInlineView extends DiscussionContentView
@model.on "change", @updateModelDetails @model.on "change", @updateModelDetails
render: -> render: ->
#TODO: Debugging, remove when done
if not window.$disc
window.$disc = []
window.$disc.push(@)
if not @model.has('abbreviatedBody') if not @model.has('abbreviatedBody')
@abbreviateBody() @abbreviateBody()
@$el.html(Mustache.render(@template(), $.extend(@model.toJSON(),{expanded: @expanded}) )) @$el.html(Mustache.render(@template(), $.extend(@model.toJSON(),{expanded: @expanded}) ))
......
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
<div class="local"><a href="#" class="dogear action-follow"></a></div> <div class="local"><a href="#" class="dogear action-follow"></a></div>
<div class="discussion-post local"> <div class="discussion-post local">
<header> <header>
<a href="#" class="vote-btn discussion-vote discussion-vote-up"><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"><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">
<span class="timeago" title="{{created_at}}">sometime</span> by <span class="timeago" title="{{created_at}}">{{created_at}}</span> by
<a href="{{user_url}}">{{username}}</a> <a href="{{user_url}}">{{username}}</a>
<span class="post-status-closed top-post-status" style="display: none">
&bull; This thread is closed.
</span>
</p> </p>
<div class="local post-tools"> <div class="local post-tools">
<a href="javascript:void(0)" class="expand-post">Expand...</a> <a href="javascript:void(0)" class="expand-post">Expand...</a>
...@@ -16,6 +19,11 @@ ...@@ -16,6 +19,11 @@
<div class="post-body"> <div class="post-body">
{{abbreviatedBody}} {{abbreviatedBody}}
</div> </div>
<ul class="moderator-actions">
<li style="display: none"><a class="action-edit" href="javascript:void(0)"><span class="edit-icon"></span> Edit</a></li>
<li style="display: none"><a class="action-delete" href="javascript:void(0)"><span class="delete-icon"></span> Delete</a></li>
<li style="display: none"><a class="action-openclose" href="javascript:void(0)"><span class="edit-icon"></span> Close</a></li>
</ul>
</div> </div>
<ol class="responses post-extended-content"> <ol class="responses post-extended-content">
<li class="loading"><div class="loading-animation"></div></li> <li class="loading"><div class="loading-animation"></div></li>
......
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