make similar posts url working
This commit is contained in:
@@ -298,10 +298,13 @@ def search_similar_threads(request, course_id, commentable_id):
|
||||
'text': text,
|
||||
'commentable_id': commentable_id,
|
||||
}
|
||||
result = cc.search_similar_threads(course_id, recursive=False, query_params=query_params)
|
||||
return JsonResponse(result)
|
||||
threads = cc.search_similar_threads(course_id, recursive=False, query_params=query_params)
|
||||
else:
|
||||
return JsonResponse([])
|
||||
theads = []
|
||||
context = { 'threads': map(utils.extend_content, threads) }
|
||||
return JsonResponse({
|
||||
'html': render_to_string('discussion/_similar_posts.html', context)
|
||||
})
|
||||
|
||||
@require_GET
|
||||
def tags_autocomplete(request, course_id):
|
||||
|
||||
@@ -33,24 +33,10 @@ def include_mustache_templates():
|
||||
file_contents = map(read_file, filter(valid_file_name, os.listdir(mustache_dir)))
|
||||
return '\n'.join(map(wrap_in_tag, map(strip_file_name, file_contents)))
|
||||
|
||||
def permalink(content):
|
||||
if content['type'] == 'thread':
|
||||
return reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['id']])
|
||||
else:
|
||||
return reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['thread_id']]) + '#' + content['id']
|
||||
|
||||
def render_content(content, additional_context={}):
|
||||
content_info = {
|
||||
'displayed_title': content.get('highlighted_title') or content.get('title', ''),
|
||||
'displayed_body': content.get('highlighted_body') or content.get('body', ''),
|
||||
'raw_tags': ','.join(content.get('tags', [])),
|
||||
'permalink': permalink(content),
|
||||
}
|
||||
|
||||
context = {
|
||||
'content': merge_dict(content, content_info),
|
||||
'content': extend_content(content),
|
||||
content['type']: True,
|
||||
}
|
||||
context = merge_dict(context, additional_context)
|
||||
|
||||
@@ -197,3 +197,20 @@ def url_for_tags(course_id, tags):
|
||||
def render_mustache(template_name, dictionary, *args, **kwargs):
|
||||
template = middleware.lookup['main'].get_template(template_name).source
|
||||
return pystache.render(template, dictionary)
|
||||
|
||||
def permalink(content):
|
||||
if content['type'] == 'thread':
|
||||
return reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['id']])
|
||||
else:
|
||||
return reverse('django_comment_client.forum.views.single_thread',
|
||||
args=[content['course_id'], content['commentable_id'], content['thread_id']]) + '#' + content['id']
|
||||
|
||||
def extend_content(content):
|
||||
content_info = {
|
||||
'displayed_title': content.get('highlighted_title') or content.get('title', ''),
|
||||
'displayed_body': content.get('highlighted_body') or content.get('body', ''),
|
||||
'raw_tags': ','.join(content.get('tags', [])),
|
||||
'permalink': permalink(content),
|
||||
}
|
||||
return merge_dict(content, content_info)
|
||||
|
||||
@@ -61,17 +61,16 @@ if Backbone?
|
||||
$elem = $(event.target)
|
||||
url = DiscussionUtil.urlFor 'search_similar_threads', @model.id
|
||||
data = { text: @$(".new-post-title").val() }
|
||||
DiscussionUtil.get $elem, url, data, (response, textStatus) =>
|
||||
$similarPosts.empty()
|
||||
if $.type(response) == "array" and response.length
|
||||
DiscussionUtil.safeAjax
|
||||
$elem: $elem
|
||||
url: url
|
||||
data: data
|
||||
dataType: 'json'
|
||||
success: (response, textStatus) =>
|
||||
$wrapper.html(response.html)
|
||||
$wrapper.show()
|
||||
for thread in response
|
||||
$similarPost = $("<a>").addClass("similar-post")
|
||||
.html(thread["title"])
|
||||
.attr("href", "javascript:void(0)") #TODO
|
||||
.appendTo($similarPosts)
|
||||
else
|
||||
$wrapper.hide()
|
||||
$wrapper.find(".hide-similar-posts").click =>
|
||||
$wrapper.hide()
|
||||
else
|
||||
$wrapper.hide()
|
||||
$title.attr("prev-text", text)
|
||||
@@ -131,7 +130,7 @@ if Backbone?
|
||||
|
||||
@$(".new-post-similar-posts").empty()
|
||||
@$(".new-post-similar-posts-wrapper").hide()
|
||||
@$(".new-post-title").val("")
|
||||
@$(".new-post-title").val("").attr("prev-text", "")
|
||||
DiscussionUtil.setWmdContent @$el, $.proxy(@$, @), "new-post-body", ""
|
||||
@$(".new-post-tags").val("")
|
||||
@$(".new-post-tags").importTags("")
|
||||
|
||||
9
lms/templates/discussion/_similar_posts.html
Normal file
9
lms/templates/discussion/_similar_posts.html
Normal file
@@ -0,0 +1,9 @@
|
||||
% if len(threads) > 0:
|
||||
Similar Posts:
|
||||
<a class="hide-similar-posts" href="javascript:void(0)">Hide</a>
|
||||
<div class="new-post-similar-posts">
|
||||
% for thread in threads:
|
||||
<a class="similar-post" href="${thread['permalink']}">${thread['title']}</a>
|
||||
% endfor
|
||||
</div>
|
||||
% endif
|
||||
@@ -1,11 +1,7 @@
|
||||
<form class="new-post-form collapsed" id="new-post-form" style="display: block; ">
|
||||
<ul class="new-post-form-errors discussion-errors"></ul>
|
||||
<input type="text" class="new-post-title title-input" placeholder="Title" />
|
||||
<div class="new-post-similar-posts-wrapper" style="display: none">
|
||||
Similar Posts:
|
||||
<a class="hide-similar-posts" href="javascript:void(0)">Hide</a>
|
||||
<div class="new-post-similar-posts"></div>
|
||||
</div>
|
||||
<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" />
|
||||
<div class="post-options">
|
||||
|
||||
Reference in New Issue
Block a user