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
7994e1b3
Commit
7994e1b3
authored
Apr 22, 2013
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8 fixes
parent
0a627bb5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
84 additions
and
84 deletions
+84
-84
lms/djangoapps/django_comment_client/base/views.py
+18
-17
lms/djangoapps/django_comment_client/forum/views.py
+8
-11
lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py
+4
-5
lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py
+0
-1
lms/djangoapps/django_comment_client/utils.py
+16
-16
lms/lib/comment_client/comment.py
+12
-10
lms/lib/comment_client/thread.py
+26
-24
No files found.
lms/djangoapps/django_comment_client/base/views.py
View file @
7994e1b3
...
@@ -119,7 +119,7 @@ def create_thread(request, course_id, commentable_id):
...
@@ -119,7 +119,7 @@ def create_thread(request, course_id, commentable_id):
#patch for backward compatibility to comments service
#patch for backward compatibility to comments service
if
not
'pinned'
in
thread
.
attributes
:
if
not
'pinned'
in
thread
.
attributes
:
thread
[
'pinned'
]
=
False
thread
[
'pinned'
]
=
False
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
)
...
@@ -174,7 +174,7 @@ def _create_comment(request, course_id, thread_id=None, parent_id=None):
...
@@ -174,7 +174,7 @@ def _create_comment(request, course_id, thread_id=None, parent_id=None):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
.
follow
(
comment
.
thread
)
user
.
follow
(
comment
.
thread
)
if
request
.
is_ajax
():
if
request
.
is_ajax
():
return
ajax_content_response
(
request
,
course_id
,
comment
.
to_dict
(),
'discussion/ajax_create_comment.html'
)
return
ajax_content_response
(
request
,
course_id
,
comment
.
to_dict
(),
'discussion/ajax_create_comment.html'
)
else
:
else
:
return
JsonResponse
(
utils
.
safe_content
(
comment
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
comment
.
to_dict
()))
...
@@ -290,29 +290,32 @@ def vote_for_thread(request, course_id, thread_id, value):
...
@@ -290,29 +290,32 @@ def vote_for_thread(request, course_id, thread_id, value):
def
flag_abuse_for_thread
(
request
,
course_id
,
thread_id
):
def
flag_abuse_for_thread
(
request
,
course_id
,
thread_id
):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
.
flagAbuse
(
user
,
thread
)
thread
.
flagAbuse
(
user
,
thread
)
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
@require_POST
@require_POST
@login_required
@login_required
@permitted
@permitted
def
un_flag_abuse_for_thread
(
request
,
course_id
,
thread_id
):
def
un_flag_abuse_for_thread
(
request
,
course_id
,
thread_id
):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
removeAll
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course_id
)
removeAll
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course_id
)
thread
.
unFlagAbuse
(
user
,
thread
,
removeAll
)
thread
.
unFlagAbuse
(
user
,
thread
,
removeAll
)
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
@require_POST
@require_POST
@login_required
@login_required
@permitted
@permitted
def
flag_abuse_for_comment
(
request
,
course_id
,
comment_id
):
def
flag_abuse_for_comment
(
request
,
course_id
,
comment_id
):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
comment
=
cc
.
Comment
.
find
(
comment_id
)
comment
=
cc
.
Comment
.
find
(
comment_id
)
comment
.
flagAbuse
(
user
,
comment
)
comment
.
flagAbuse
(
user
,
comment
)
return
JsonResponse
(
utils
.
safe_content
(
comment
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
comment
.
to_dict
()))
@require_POST
@require_POST
@login_required
@login_required
@permitted
@permitted
...
@@ -320,9 +323,10 @@ def un_flag_abuse_for_comment(request, course_id, comment_id):
...
@@ -320,9 +323,10 @@ def un_flag_abuse_for_comment(request, course_id, comment_id):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
removeAll
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course_id
)
removeAll
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course_id
)
comment
=
cc
.
Comment
.
find
(
comment_id
)
comment
=
cc
.
Comment
.
find
(
comment_id
)
comment
.
unFlagAbuse
(
user
,
comment
,
removeAll
)
comment
.
unFlagAbuse
(
user
,
comment
,
removeAll
)
return
JsonResponse
(
utils
.
safe_content
(
comment
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
comment
.
to_dict
()))
@require_POST
@require_POST
@login_required
@login_required
@permitted
@permitted
...
@@ -332,19 +336,21 @@ def undo_vote_for_thread(request, course_id, thread_id):
...
@@ -332,19 +336,21 @@ def undo_vote_for_thread(request, course_id, thread_id):
user
.
unvote
(
thread
)
user
.
unvote
(
thread
)
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
@require_POST
@require_POST
@login_required
@login_required
@permitted
@permitted
def
pin_thread
(
request
,
course_id
,
thread_id
):
def
pin_thread
(
request
,
course_id
,
thread_id
):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
.
pin
(
user
,
thread_id
)
thread
.
pin
(
user
,
thread_id
)
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
def
un_pin_thread
(
request
,
course_id
,
thread_id
):
def
un_pin_thread
(
request
,
course_id
,
thread_id
):
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
user
=
cc
.
User
.
from_django_user
(
request
.
user
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
thread
.
un_pin
(
user
,
thread_id
)
thread
.
un_pin
(
user
,
thread_id
)
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
return
JsonResponse
(
utils
.
safe_content
(
thread
.
to_dict
()))
...
@@ -491,16 +497,11 @@ def upload(request, course_id): # ajax upload file to a question or answer
...
@@ -491,16 +497,11 @@ def upload(request, course_id): # ajax upload file to a question or answer
if
not
file_extension
in
cc_settings
.
ALLOWED_UPLOAD_FILE_TYPES
:
if
not
file_extension
in
cc_settings
.
ALLOWED_UPLOAD_FILE_TYPES
:
file_types
=
"', '"
.
join
(
cc_settings
.
ALLOWED_UPLOAD_FILE_TYPES
)
file_types
=
"', '"
.
join
(
cc_settings
.
ALLOWED_UPLOAD_FILE_TYPES
)
msg
=
_
(
"allowed file types are '
%(file_types)
s'"
)
%
\
msg
=
_
(
"allowed file types are '
%(file_types)
s'"
)
%
\
{
'file_types'
:
file_types
}
{
'file_types'
:
file_types
}
raise
exceptions
.
PermissionDenied
(
msg
)
raise
exceptions
.
PermissionDenied
(
msg
)
# generate new file name
# generate new file name
new_file_name
=
str
(
new_file_name
=
str
(
time
.
time
())
.
replace
(
'.'
,
str
(
random
.
randint
(
0
,
100000
)))
+
file_extension
time
.
time
()
)
.
replace
(
'.'
,
str
(
random
.
randint
(
0
,
100000
))
)
+
file_extension
file_storage
=
get_storage_class
()()
file_storage
=
get_storage_class
()()
# use default storage to store file
# use default storage to store file
...
@@ -511,7 +512,7 @@ def upload(request, course_id): # ajax upload file to a question or answer
...
@@ -511,7 +512,7 @@ def upload(request, course_id): # ajax upload file to a question or answer
if
size
>
cc_settings
.
MAX_UPLOAD_FILE_SIZE
:
if
size
>
cc_settings
.
MAX_UPLOAD_FILE_SIZE
:
file_storage
.
delete
(
new_file_name
)
file_storage
.
delete
(
new_file_name
)
msg
=
_
(
"maximum upload file size is
%(file_size)
sK"
)
%
\
msg
=
_
(
"maximum upload file size is
%(file_size)
sK"
)
%
\
{
'file_size'
:
cc_settings
.
MAX_UPLOAD_FILE_SIZE
}
{
'file_size'
:
cc_settings
.
MAX_UPLOAD_FILE_SIZE
}
raise
exceptions
.
PermissionDenied
(
msg
)
raise
exceptions
.
PermissionDenied
(
msg
)
except
exceptions
.
PermissionDenied
,
e
:
except
exceptions
.
PermissionDenied
,
e
:
...
...
lms/djangoapps/django_comment_client/forum/views.py
View file @
7994e1b3
...
@@ -9,7 +9,7 @@ from django.contrib.auth.models import User
...
@@ -9,7 +9,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
(
is_course_cohorted
,
get_cohort_id
,
is_commentable_cohorted
,
from
course_groups.cohorts
import
(
is_course_cohorted
,
get_cohort_id
,
is_commentable_cohorted
,
get_cohorted_commentables
,
get_course_cohorts
,
get_cohort_by_id
)
get_cohorted_commentables
,
get_course_cohorts
,
get_cohort_by_id
)
from
courseware.access
import
has_access
from
courseware.access
import
has_access
from
django_comment_client.models
import
Role
from
django_comment_client.models
import
Role
...
@@ -43,7 +43,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
...
@@ -43,7 +43,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
'course_id'
:
course_id
,
'course_id'
:
course_id
,
'user_id'
:
request
.
user
.
id
,
'user_id'
:
request
.
user
.
id
,
}
}
if
not
request
.
GET
.
get
(
'sort_key'
):
if
not
request
.
GET
.
get
(
'sort_key'
):
# If the user did not select a sort key, use their last used sort key
# If the user did not select a sort key, use their last used sort key
cc_user
=
cc
.
User
.
from_django_user
(
request
.
user
)
cc_user
=
cc
.
User
.
from_django_user
(
request
.
user
)
...
@@ -93,11 +93,11 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
...
@@ -93,11 +93,11 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
else
:
else
:
thread
[
'group_name'
]
=
""
thread
[
'group_name'
]
=
""
thread
[
'group_string'
]
=
"This post visible to everyone."
thread
[
'group_string'
]
=
"This post visible to everyone."
#patch for backward compatibility to comments service
#patch for backward compatibility to comments service
if
not
'pinned'
in
thread
:
if
not
'pinned'
in
thread
:
thread
[
'pinned'
]
=
False
thread
[
'pinned'
]
=
False
query_params
[
'page'
]
=
page
query_params
[
'page'
]
=
page
query_params
[
'num_pages'
]
=
num_pages
query_params
[
'num_pages'
]
=
num_pages
...
@@ -242,10 +242,10 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -242,10 +242,10 @@ def single_thread(request, course_id, discussion_id, thread_id):
user_info
=
cc_user
.
to_dict
()
user_info
=
cc_user
.
to_dict
()
try
:
try
:
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
,
user_id
=
request
.
user
.
id
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
,
user_id
=
request
.
user
.
id
)
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
)
as
err
:
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
)
as
err
:
log
.
error
(
"Error loading single thread."
)
log
.
error
(
"Error loading single thread."
)
raise
Http404
raise
Http404
if
request
.
is_ajax
():
if
request
.
is_ajax
():
courseware_context
=
get_courseware_context
(
thread
,
course
)
courseware_context
=
get_courseware_context
(
thread
,
course
)
...
@@ -302,9 +302,6 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -302,9 +302,6 @@ def single_thread(request, course_id, discussion_id, thread_id):
cohorts
=
get_course_cohorts
(
course_id
)
cohorts
=
get_course_cohorts
(
course_id
)
cohorted_commentables
=
get_cohorted_commentables
(
course_id
)
cohorted_commentables
=
get_cohorted_commentables
(
course_id
)
user_cohort
=
get_cohort_id
(
request
.
user
,
course_id
)
user_cohort
=
get_cohort_id
(
request
.
user
,
course_id
)
context
=
{
context
=
{
'discussion_id'
:
discussion_id
,
'discussion_id'
:
discussion_id
,
...
@@ -411,7 +408,7 @@ def followed_threads(request, course_id, user_id):
...
@@ -411,7 +408,7 @@ def followed_threads(request, course_id, user_id):
'user_info'
:
saxutils
.
escape
(
json
.
dumps
(
user_info
),
escapedict
),
'user_info'
:
saxutils
.
escape
(
json
.
dumps
(
user_info
),
escapedict
),
'annotated_content_info'
:
saxutils
.
escape
(
json
.
dumps
(
annotated_content_info
),
escapedict
),
'annotated_content_info'
:
saxutils
.
escape
(
json
.
dumps
(
annotated_content_info
),
escapedict
),
# 'content': content,
# 'content': content,
}
}
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
except
(
cc
.
utils
.
CommentClientError
,
cc
.
utils
.
CommentClientUnknownError
):
...
...
lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py
View file @
7994e1b3
...
@@ -6,10 +6,11 @@ from django.core.management.base import BaseCommand, CommandError
...
@@ -6,10 +6,11 @@ from django.core.management.base import BaseCommand, CommandError
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
import
comment_client
as
cc
import
comment_client
as
cc
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
help
=
'Reload forum (comment client) users from existing users'
help
=
'Reload forum (comment client) users from existing users'
def
adduser
(
self
,
user
):
def
adduser
(
self
,
user
):
print
user
print
user
try
:
try
:
cc_user
=
cc
.
User
.
from_django_user
(
user
)
cc_user
=
cc
.
User
.
from_django_user
(
user
)
...
@@ -22,8 +23,7 @@ class Command(BaseCommand):
...
@@ -22,8 +23,7 @@ class Command(BaseCommand):
uset
=
[
User
.
objects
.
get
(
username
=
x
)
for
x
in
args
]
uset
=
[
User
.
objects
.
get
(
username
=
x
)
for
x
in
args
]
else
:
else
:
uset
=
User
.
objects
.
all
()
uset
=
User
.
objects
.
all
()
for
user
in
uset
:
for
user
in
uset
:
self
.
adduser
(
user
)
self
.
adduser
(
user
)
\ No newline at end of file
lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py
View file @
7994e1b3
...
@@ -39,4 +39,3 @@ class CloseThreadTextTest(TestCase):
...
@@ -39,4 +39,3 @@ class CloseThreadTextTest(TestCase):
self
.
assertEqual
(
mustache_helpers
.
close_thread_text
(
self
.
contentOpen
),
'Close thread'
)
self
.
assertEqual
(
mustache_helpers
.
close_thread_text
(
self
.
contentOpen
),
'Close thread'
)
#########################################################################################
#########################################################################################
lms/djangoapps/django_comment_client/utils.py
View file @
7994e1b3
...
@@ -105,12 +105,12 @@ def filter_unstarted_categories(category_map):
...
@@ -105,12 +105,12 @@ def filter_unstarted_categories(category_map):
result_map
=
{}
result_map
=
{}
unfiltered_queue
=
[
category_map
]
unfiltered_queue
=
[
category_map
]
filtered_queue
=
[
result_map
]
filtered_queue
=
[
result_map
]
while
len
(
unfiltered_queue
)
>
0
:
while
len
(
unfiltered_queue
)
>
0
:
unfiltered_map
=
unfiltered_queue
.
pop
()
unfiltered_map
=
unfiltered_queue
.
pop
()
filtered_map
=
filtered_queue
.
pop
()
filtered_map
=
filtered_queue
.
pop
()
filtered_map
[
"children"
]
=
[]
filtered_map
[
"children"
]
=
[]
filtered_map
[
"entries"
]
=
{}
filtered_map
[
"entries"
]
=
{}
...
@@ -187,8 +187,7 @@ def initialize_discussion_info(course):
...
@@ -187,8 +187,7 @@ def initialize_discussion_info(course):
category
=
" / "
.
join
([
x
.
strip
()
for
x
in
category
.
split
(
"/"
)])
category
=
" / "
.
join
([
x
.
strip
()
for
x
in
category
.
split
(
"/"
)])
last_category
=
category
.
split
(
"/"
)[
-
1
]
last_category
=
category
.
split
(
"/"
)[
-
1
]
discussion_id_map
[
id
]
=
{
"location"
:
module
.
location
,
"title"
:
last_category
+
" / "
+
title
}
discussion_id_map
[
id
]
=
{
"location"
:
module
.
location
,
"title"
:
last_category
+
" / "
+
title
}
unexpanded_category_map
[
category
]
.
append
({
"title"
:
title
,
"id"
:
id
,
unexpanded_category_map
[
category
]
.
append
({
"title"
:
title
,
"id"
:
id
,
"sort_key"
:
sort_key
,
"start_date"
:
module
.
lms
.
start
})
"sort_key"
:
sort_key
,
"start_date"
:
module
.
lms
.
start
})
category_map
=
{
"entries"
:
defaultdict
(
dict
),
"subcategories"
:
defaultdict
(
dict
)}
category_map
=
{
"entries"
:
defaultdict
(
dict
),
"subcategories"
:
defaultdict
(
dict
)}
for
category_path
,
entries
in
unexpanded_category_map
.
items
():
for
category_path
,
entries
in
unexpanded_category_map
.
items
():
...
@@ -215,9 +214,9 @@ def initialize_discussion_info(course):
...
@@ -215,9 +214,9 @@ def initialize_discussion_info(course):
level
=
path
[
-
1
]
level
=
path
[
-
1
]
if
level
not
in
node
:
if
level
not
in
node
:
node
[
level
]
=
{
"subcategories"
:
defaultdict
(
dict
),
node
[
level
]
=
{
"subcategories"
:
defaultdict
(
dict
),
"entries"
:
defaultdict
(
dict
),
"entries"
:
defaultdict
(
dict
),
"sort_key"
:
level
,
"sort_key"
:
level
,
"start_date"
:
category_start_date
}
"start_date"
:
category_start_date
}
else
:
else
:
if
node
[
level
][
"start_date"
]
>
category_start_date
:
if
node
[
level
][
"start_date"
]
>
category_start_date
:
node
[
level
][
"start_date"
]
=
category_start_date
node
[
level
][
"start_date"
]
=
category_start_date
...
@@ -297,12 +296,12 @@ class QueryCountDebugMiddleware(object):
...
@@ -297,12 +296,12 @@ class QueryCountDebugMiddleware(object):
def
get_ability
(
course_id
,
content
,
user
):
def
get_ability
(
course_id
,
content
,
user
):
return
{
return
{
'editable'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"update_thread"
if
content
[
'type'
]
==
'thread'
else
"update_comment"
),
'editable'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"update_thread"
if
content
[
'type'
]
==
'thread'
else
"update_comment"
),
'can_reply'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"create_comment"
if
content
[
'type'
]
==
'thread'
else
"create_sub_comment"
),
'can_reply'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"create_comment"
if
content
[
'type'
]
==
'thread'
else
"create_sub_comment"
),
'can_endorse'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"endorse_comment"
)
if
content
[
'type'
]
==
'comment'
else
False
,
'can_endorse'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"endorse_comment"
)
if
content
[
'type'
]
==
'comment'
else
False
,
'can_delete'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"delete_thread"
if
content
[
'type'
]
==
'thread'
else
"delete_comment"
),
'can_delete'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"delete_thread"
if
content
[
'type'
]
==
'thread'
else
"delete_comment"
),
'can_openclose'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"openclose_thread"
)
if
content
[
'type'
]
==
'thread'
else
False
,
'can_openclose'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"openclose_thread"
)
if
content
[
'type'
]
==
'thread'
else
False
,
'can_vote'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"vote_for_thread"
if
content
[
'type'
]
==
'thread'
else
"vote_for_comment"
),
'can_vote'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"vote_for_thread"
if
content
[
'type'
]
==
'thread'
else
"vote_for_comment"
),
}
}
#TODO: RENAME
#TODO: RENAME
...
@@ -331,6 +330,7 @@ def get_annotated_content_infos(course_id, thread, user, user_info):
...
@@ -331,6 +330,7 @@ def get_annotated_content_infos(course_id, thread, user, user_info):
Get metadata for a thread and its children
Get metadata for a thread and its children
"""
"""
infos
=
{}
infos
=
{}
def
annotate
(
content
):
def
annotate
(
content
):
infos
[
str
(
content
[
'id'
])]
=
get_annotated_content_info
(
course_id
,
content
,
user
,
user_info
)
infos
[
str
(
content
[
'id'
])]
=
get_annotated_content_info
(
course_id
,
content
,
user
,
user_info
)
for
child
in
content
.
get
(
'children'
,
[]):
for
child
in
content
.
get
(
'children'
,
[]):
...
@@ -395,8 +395,8 @@ def get_courseware_context(content, course):
...
@@ -395,8 +395,8 @@ def get_courseware_context(content, course):
location
=
id_map
[
id
][
"location"
]
.
url
()
location
=
id_map
[
id
][
"location"
]
.
url
()
title
=
id_map
[
id
][
"title"
]
title
=
id_map
[
id
][
"title"
]
url
=
reverse
(
'jump_to'
,
kwargs
=
{
"course_id"
:
course
.
location
.
course_id
,
url
=
reverse
(
'jump_to'
,
kwargs
=
{
"course_id"
:
course
.
location
.
course_id
,
"location"
:
location
})
"location"
:
location
})
content_info
=
{
"courseware_url"
:
url
,
"courseware_title"
:
title
}
content_info
=
{
"courseware_url"
:
url
,
"courseware_title"
:
title
}
return
content_info
return
content_info
...
@@ -410,7 +410,7 @@ def safe_content(content):
...
@@ -410,7 +410,7 @@ def safe_content(content):
'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'
,
'group_id'
,
'group_name'
,
'group_string'
,
'pinned'
,
'abuse_flaggers'
'read'
,
'group_id'
,
'group_name'
,
'group_string'
,
'pinned'
,
'abuse_flaggers'
]
]
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
):
...
...
lms/lib/comment_client/comment.py
View file @
7994e1b3
...
@@ -41,7 +41,7 @@ class Comment(models.Model):
...
@@ -41,7 +41,7 @@ class Comment(models.Model):
return
cls
.
url_for_comments
(
params
)
return
cls
.
url_for_comments
(
params
)
else
:
else
:
return
super
(
Comment
,
cls
)
.
url
(
action
,
params
)
return
super
(
Comment
,
cls
)
.
url
(
action
,
params
)
def
flagAbuse
(
self
,
user
,
voteable
):
def
flagAbuse
(
self
,
user
,
voteable
):
if
voteable
.
type
==
'thread'
:
if
voteable
.
type
==
'thread'
:
url
=
_url_for_flag_abuse_thread
(
voteable
.
id
)
url
=
_url_for_flag_abuse_thread
(
voteable
.
id
)
...
@@ -51,8 +51,8 @@ class Comment(models.Model):
...
@@ -51,8 +51,8 @@ class Comment(models.Model):
raise
CommentClientError
(
"Can only flag/unflag threads or comments"
)
raise
CommentClientError
(
"Can only flag/unflag threads or comments"
)
params
=
{
'user_id'
:
user
.
id
}
params
=
{
'user_id'
:
user
.
id
}
request
=
perform_request
(
'put'
,
url
,
params
)
request
=
perform_request
(
'put'
,
url
,
params
)
voteable
.
update_attributes
(
request
)
voteable
.
update_attributes
(
request
)
def
unFlagAbuse
(
self
,
user
,
voteable
,
removeAll
):
def
unFlagAbuse
(
self
,
user
,
voteable
,
removeAll
):
if
voteable
.
type
==
'thread'
:
if
voteable
.
type
==
'thread'
:
url
=
_url_for_unflag_abuse_thread
(
voteable
.
id
)
url
=
_url_for_unflag_abuse_thread
(
voteable
.
id
)
...
@@ -61,12 +61,12 @@ class Comment(models.Model):
...
@@ -61,12 +61,12 @@ class Comment(models.Model):
else
:
else
:
raise
CommentClientError
(
"Can flag/unflag for threads or comments"
)
raise
CommentClientError
(
"Can flag/unflag for threads or comments"
)
params
=
{
'user_id'
:
user
.
id
}
params
=
{
'user_id'
:
user
.
id
}
if
removeAll
:
if
removeAll
:
params
[
'all'
]
=
True
params
[
'all'
]
=
True
request
=
perform_request
(
'put'
,
url
,
params
)
request
=
perform_request
(
'put'
,
url
,
params
)
voteable
.
update_attributes
(
request
)
voteable
.
update_attributes
(
request
)
def
_url_for_thread_comments
(
thread_id
):
def
_url_for_thread_comments
(
thread_id
):
...
@@ -75,9 +75,11 @@ def _url_for_thread_comments(thread_id):
...
@@ -75,9 +75,11 @@ def _url_for_thread_comments(thread_id):
def
_url_for_comment
(
comment_id
):
def
_url_for_comment
(
comment_id
):
return
"{prefix}/comments/{comment_id}"
.
format
(
prefix
=
settings
.
PREFIX
,
comment_id
=
comment_id
)
return
"{prefix}/comments/{comment_id}"
.
format
(
prefix
=
settings
.
PREFIX
,
comment_id
=
comment_id
)
def
_url_for_flag_abuse_comment
(
comment_id
):
def
_url_for_flag_abuse_comment
(
comment_id
):
return
"{prefix}/comments/{comment_id}/abuse_flags"
.
format
(
prefix
=
settings
.
PREFIX
,
comment_id
=
comment_id
)
return
"{prefix}/comments/{comment_id}/abuse_flags"
.
format
(
prefix
=
settings
.
PREFIX
,
comment_id
=
comment_id
)
def
_url_for_unflag_abuse_comment
(
comment_id
):
def
_url_for_unflag_abuse_comment
(
comment_id
):
return
"{prefix}/comments/{comment_id}/abuse_unflags"
.
format
(
prefix
=
settings
.
PREFIX
,
comment_id
=
comment_id
)
return
"{prefix}/comments/{comment_id}/abuse_unflags"
.
format
(
prefix
=
settings
.
PREFIX
,
comment_id
=
comment_id
)
lms/lib/comment_client/thread.py
View file @
7994e1b3
...
@@ -11,7 +11,6 @@ class Thread(models.Model):
...
@@ -11,7 +11,6 @@ class Thread(models.Model):
'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'
,
'group_name'
,
'pinned'
,
'abuse_flaggers'
'highlighted_body'
,
'endorsed'
,
'read'
,
'group_id'
,
'group_name'
,
'pinned'
,
'abuse_flaggers'
]
]
updatable_fields
=
[
updatable_fields
=
[
...
@@ -33,7 +32,7 @@ class Thread(models.Model):
...
@@ -33,7 +32,7 @@ class Thread(models.Model):
'course_id'
:
query_params
[
'course_id'
],
'course_id'
:
query_params
[
'course_id'
],
'recursive'
:
False
}
'recursive'
:
False
}
params
=
merge_dict
(
default_params
,
strip_blank
(
strip_none
(
query_params
)))
params
=
merge_dict
(
default_params
,
strip_blank
(
strip_none
(
query_params
)))
if
query_params
.
get
(
'text'
)
or
query_params
.
get
(
'tags'
)
or
query_params
.
get
(
'commentable_ids'
):
if
query_params
.
get
(
'text'
)
or
query_params
.
get
(
'tags'
)
or
query_params
.
get
(
'commentable_ids'
):
url
=
cls
.
url
(
action
=
'search'
)
url
=
cls
.
url
(
action
=
'search'
)
else
:
else
:
...
@@ -56,7 +55,7 @@ class Thread(models.Model):
...
@@ -56,7 +55,7 @@ class Thread(models.Model):
@classmethod
@classmethod
def
url
(
cls
,
action
,
params
=
{}):
def
url
(
cls
,
action
,
params
=
{}):
if
action
in
[
'get_all'
,
'post'
]:
if
action
in
[
'get_all'
,
'post'
]:
return
cls
.
url_for_threads
(
params
)
return
cls
.
url_for_threads
(
params
)
elif
action
==
'search'
:
elif
action
==
'search'
:
...
@@ -70,11 +69,11 @@ class Thread(models.Model):
...
@@ -70,11 +69,11 @@ class Thread(models.Model):
def
_retrieve
(
self
,
*
args
,
**
kwargs
):
def
_retrieve
(
self
,
*
args
,
**
kwargs
):
url
=
self
.
url
(
action
=
'get'
,
params
=
self
.
attributes
)
url
=
self
.
url
(
action
=
'get'
,
params
=
self
.
attributes
)
request_params
=
{
request_params
=
{
'recursive'
:
kwargs
.
get
(
'recursive'
),
'recursive'
:
kwargs
.
get
(
'recursive'
),
'user_id'
:
kwargs
.
get
(
'user_id'
),
'user_id'
:
kwargs
.
get
(
'user_id'
),
'mark_as_read'
:
kwargs
.
get
(
'mark_as_read'
,
True
),
'mark_as_read'
:
kwargs
.
get
(
'mark_as_read'
,
True
),
}
}
# user_id may be none, in which case it shouldn't be part of the
# user_id may be none, in which case it shouldn't be part of the
# request.
# request.
request_params
=
strip_none
(
request_params
)
request_params
=
strip_none
(
request_params
)
...
@@ -91,8 +90,8 @@ class Thread(models.Model):
...
@@ -91,8 +90,8 @@ class Thread(models.Model):
raise
CommentClientError
(
"Can only flag/unflag threads or comments"
)
raise
CommentClientError
(
"Can only flag/unflag threads or comments"
)
params
=
{
'user_id'
:
user
.
id
}
params
=
{
'user_id'
:
user
.
id
}
request
=
perform_request
(
'put'
,
url
,
params
)
request
=
perform_request
(
'put'
,
url
,
params
)
voteable
.
update_attributes
(
request
)
voteable
.
update_attributes
(
request
)
def
unFlagAbuse
(
self
,
user
,
voteable
,
removeAll
):
def
unFlagAbuse
(
self
,
user
,
voteable
,
removeAll
):
if
voteable
.
type
==
'thread'
:
if
voteable
.
type
==
'thread'
:
url
=
_url_for_unflag_abuse_thread
(
voteable
.
id
)
url
=
_url_for_unflag_abuse_thread
(
voteable
.
id
)
...
@@ -104,31 +103,34 @@ class Thread(models.Model):
...
@@ -104,31 +103,34 @@ class Thread(models.Model):
#if you're an admin, when you unflag, remove ALL flags
#if you're an admin, when you unflag, remove ALL flags
if
removeAll
:
if
removeAll
:
params
[
'all'
]
=
True
params
[
'all'
]
=
True
request
=
perform_request
(
'put'
,
url
,
params
)
request
=
perform_request
(
'put'
,
url
,
params
)
voteable
.
update_attributes
(
request
)
voteable
.
update_attributes
(
request
)
def
pin
(
self
,
user
,
thread_id
):
def
pin
(
self
,
user
,
thread_id
):
url
=
_url_for_pin_thread
(
thread_id
)
url
=
_url_for_pin_thread
(
thread_id
)
params
=
{
'user_id'
:
user
.
id
}
params
=
{
'user_id'
:
user
.
id
}
request
=
perform_request
(
'put'
,
url
,
params
)
request
=
perform_request
(
'put'
,
url
,
params
)
self
.
update_attributes
(
request
)
self
.
update_attributes
(
request
)
def
un_pin
(
self
,
user
,
thread_id
):
def
un_pin
(
self
,
user
,
thread_id
):
url
=
_url_for_un_pin_thread
(
thread_id
)
url
=
_url_for_un_pin_thread
(
thread_id
)
params
=
{
'user_id'
:
user
.
id
}
params
=
{
'user_id'
:
user
.
id
}
request
=
perform_request
(
'put'
,
url
,
params
)
request
=
perform_request
(
'put'
,
url
,
params
)
self
.
update_attributes
(
request
)
self
.
update_attributes
(
request
)
def
_url_for_flag_abuse_thread
(
thread_id
):
def
_url_for_flag_abuse_thread
(
thread_id
):
return
"{prefix}/threads/{thread_id}/abuse_flags"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
return
"{prefix}/threads/{thread_id}/abuse_flags"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
def
_url_for_unflag_abuse_thread
(
thread_id
):
def
_url_for_unflag_abuse_thread
(
thread_id
):
return
"{prefix}/threads/{thread_id}/abuse_unflags"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
return
"{prefix}/threads/{thread_id}/abuse_unflags"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
def
_url_for_pin_thread
(
thread_id
):
def
_url_for_pin_thread
(
thread_id
):
return
"{prefix}/threads/{thread_id}/pin"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
return
"{prefix}/threads/{thread_id}/pin"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
def
_url_for_un_pin_thread
(
thread_id
):
def
_url_for_un_pin_thread
(
thread_id
):
return
"{prefix}/threads/{thread_id}/unpin"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
return
"{prefix}/threads/{thread_id}/unpin"
.
format
(
prefix
=
settings
.
PREFIX
,
thread_id
=
thread_id
)
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