Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
0c311b8f
Commit
0c311b8f
authored
Aug 07, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search for similar posts without any styling..
parent
77900bd7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
13 deletions
+64
-13
lms/djangoapps/django_comment_client/base/urls.py
+2
-2
lms/djangoapps/django_comment_client/base/views.py
+20
-9
lms/lib/comment_client.py
+11
-2
lms/static/coffee/src/discussion/discussion.coffee
+26
-0
lms/static/coffee/src/discussion/templates.coffee
+4
-0
lms/static/coffee/src/discussion/utils.coffee
+1
-0
No files found.
lms/djangoapps/django_comment_client/base/urls.py
View file @
0c311b8f
...
...
@@ -23,8 +23,8 @@ urlpatterns = patterns('django_comment_client.base.views',
url
(
r'comments/(?P<comment_id>[\w\-]+)/unvote$'
,
'undo_vote_for_comment'
,
name
=
'undo_vote_for_comment'
),
url
(
r'(?P<commentable_id>[\w\-]+)/threads/create$'
,
'create_thread'
,
name
=
'create_thread'
),
# TODO should we search within the board?
url
(
r'(?P<commentable_id>[\w\-]+)/threads/search_similar$'
,
'search_similar_threads'
,
name
=
'search_similar_threads'
),
url
(
r'(?P<commentable_id>[\w\-]+)/follow$'
,
'follow_commentable'
,
name
=
'follow_commentable'
),
url
(
r'(?P<commentable_id>[\w\-]+)/unfollow$'
,
'unfollow_commentable'
,
name
=
'unfollow_commentable'
),
url
(
r'search$'
,
'search'
,
name
=
'search'
),
)
lms/djangoapps/django_comment_client/base/views.py
View file @
0c311b8f
...
...
@@ -235,17 +235,28 @@ def unfollow_user(request, course_id, followed_user_id):
response
=
comment_client
.
unfollow
(
user_id
,
followed_user_id
)
return
JsonResponse
(
response
)
@require_POST
@login_required
def
unfollow_user
(
request
,
course_id
,
followed_user_id
):
user_id
=
request
.
user
.
id
response
=
comment_client
.
unfollow
(
user_id
,
followed_user_id
)
return
JsonResponse
(
response
)
@require_GET
def
search
(
request
,
cours
e_id
):
def
search
_similar_threads
(
request
,
course_id
,
commentabl
e_id
):
text
=
request
.
GET
.
get
(
'text'
,
None
)
commentable_id
=
request
.
GET
.
get
(
'commentable_id'
,
None
)
tags
=
request
.
GET
.
get
(
'tags'
,
None
)
response
=
comment_client
.
search_threads
({
'text'
:
text
,
'commentable_id'
:
commentable_id
,
'tags'
:
tags
,
})
return
JsonResponse
(
response
)
if
text
:
return
JsonResponse
(
comment_client
.
search_similar_threads
(
course_id
,
recursive
=
False
,
query_params
=
{
'text'
:
text
,
'commentable_id'
:
commentable_id
,
},
))
else
:
return
JsonResponse
([])
@require_GET
def
tags_autocomplete
(
request
,
course_id
):
...
...
lms/lib/comment_client.py
View file @
0c311b8f
...
...
@@ -16,19 +16,24 @@ def delete_threads(commentable_id, *args, **kwargs):
return
_perform_request
(
'delete'
,
_url_for_commentable_threads
(
commentable_id
),
*
args
,
**
kwargs
)
def
get_threads
(
commentable_id
,
recursive
=
False
,
query_params
=
{},
*
args
,
**
kwargs
):
default_params
=
{
'page'
:
1
,
'per_page'
:
20
}
default_params
=
{
'page'
:
1
,
'per_page'
:
20
,
'recursive'
:
recursive
}
attributes
=
dict
(
default_params
.
items
()
+
query_params
.
items
())
response
=
_perform_request
(
'get'
,
_url_for_threads
(
commentable_id
),
\
attributes
,
*
args
,
**
kwargs
)
return
response
.
get
(
'collection'
,
[]),
response
.
get
(
'page'
,
1
),
response
.
get
(
'num_pages'
,
1
)
def
search_threads
(
course_id
,
recursive
=
False
,
query_params
=
{},
*
args
,
**
kwargs
):
default_params
=
{
'page'
:
1
,
'per_page'
:
20
,
'course_id'
:
course_id
}
default_params
=
{
'page'
:
1
,
'per_page'
:
20
,
'course_id'
:
course_id
,
'recursive'
:
recursive
}
attributes
=
dict
(
default_params
.
items
()
+
query_params
.
items
())
response
=
_perform_request
(
'get'
,
_url_for_search_threads
(),
\
attributes
,
*
args
,
**
kwargs
)
return
response
.
get
(
'collection'
,
[]),
response
.
get
(
'page'
,
1
),
response
.
get
(
'num_pages'
,
1
)
def
search_similar_threads
(
course_id
,
recursive
=
False
,
query_params
=
{},
*
args
,
**
kwargs
):
default_params
=
{
'course_id'
:
course_id
,
'recursive'
:
recursive
}
attributes
=
dict
(
default_params
.
items
()
+
query_params
.
items
())
return
_perform_request
(
'get'
,
_url_for_search_similar_threads
(),
attributes
,
*
args
,
**
kwargs
)
def
create_user
(
attributes
,
*
args
,
**
kwargs
):
return
_perform_request
(
'post'
,
_url_for_users
(),
attributes
,
*
args
,
**
kwargs
)
...
...
@@ -159,6 +164,9 @@ def _url_for_user(user_id):
def
_url_for_search_threads
():
return
"{prefix}/search/threads"
.
format
(
prefix
=
PREFIX
)
def
_url_for_search_similar_threads
():
return
"{prefix}/search/threads/more_like_this"
.
format
(
prefix
=
PREFIX
)
def
_url_for_threads_tags
():
return
"{prefix}/threads/tags"
.
format
(
prefix
=
PREFIX
)
...
...
@@ -167,3 +175,4 @@ def _url_for_threads_tags_autocomplete():
def
_url_for_users
():
return
"{prefix}/users"
.
format
(
prefix
=
PREFIX
)
lms/static/coffee/src/discussion/discussion.coffee
View file @
0c311b8f
...
...
@@ -61,6 +61,29 @@ initializeFollowDiscussion = (discussion) ->
$local
(
".new-post-form"
).
hide
()
$local
(
".discussion-new-post"
).
show
()
handleSimilarPost
=
(
elem
)
->
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
Discussion
.
urlFor
'search_similar_threads'
,
id
type
:
"GET"
dateType
:
'json'
data
:
text
:
$local
(
".new-post-title"
).
val
()
success
:
(
response
,
textStatus
)
->
$wrapper
=
$local
(
".new-post-similar-posts-wrapper"
)
$similarPosts
=
$local
(
".new-post-similar-posts"
)
$similarPosts
.
empty
()
if
$
.
type
(
response
)
==
"array"
and
response
.
length
$wrapper
.
show
()
for
thread
in
response
#singleThreadUrl = Discussion.urlFor 'retrieve_single_thread
$similarPost
=
$
(
"<a>"
).
addClass
(
"simialr-post"
)
.
html
(
thread
[
"title"
])
.
attr
(
"href"
,
"javascript:void(0)"
)
#TODO
.
appendTo
(
$similarPosts
)
else
$wrapper
.
hide
()
handleNewPost
=
(
elem
)
->
newPostForm
=
$local
(
".new-post-form"
)
if
newPostForm
.
length
...
...
@@ -76,6 +99,9 @@ initializeFollowDiscussion = (discussion) ->
$local
(
".new-post-tags"
).
tagsInput
Discussion
.
tagsInputOptions
()
$local
(
".new-post-title"
).
blur
->
handleSimilarPost
(
this
)
$local
(
".discussion-submit-post"
).
click
->
handleSubmitNewPost
(
this
)
$local
(
".discussion-cancel-post"
).
click
->
...
...
lms/static/coffee/src/discussion/templates.coffee
View file @
0c311b8f
...
...
@@ -10,6 +10,10 @@ Discussion = @Discussion
<form class="new-post-form" _id="{{discussion_id}}">
<ul class="discussion-errors"></ul>
<input type="text" class="new-post-title title-input" placeholder="Title"/>
<div class="new-post-similar-posts-wrapper" style="display: none">
Do you mean...
<div class="new-post-similar-posts"></div>
</div>
<div class="new-post-body body-input"></div>
<input class="new-post-tags" placeholder="Tags"/>
<div class = "new-post-control">
...
...
lms/static/coffee/src/discussion/utils.coffee
View file @
0c311b8f
...
...
@@ -21,6 +21,7 @@ wmdEditors = {}
follow_discussion
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/follow"
unfollow_discussion
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/unfollow"
create_thread
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/threads/create"
search_similar_threads
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/threads/search_similar"
update_thread
:
"/courses/
#{
$$course_id
}
/discussion/threads/
#{
param
}
/update"
create_comment
:
"/courses/
#{
$$course_id
}
/discussion/threads/
#{
param
}
/reply"
delete_thread
:
"/courses/
#{
$$course_id
}
/discussion/threads/
#{
param
}
/delete"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment