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
50e95de9
Commit
50e95de9
authored
Aug 14, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a place to start for the user profiel & fixed some bugs
parent
04387289
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
94 additions
and
59 deletions
+94
-59
common/djangoapps/student/management/commands/sync_user_info.py
+3
-6
common/djangoapps/student/models.py
+3
-10
lms/djangoapps/django_comment_client/forum/urls.py
+1
-1
lms/djangoapps/django_comment_client/forum/views.py
+8
-23
lms/djangoapps/django_comment_client/utils.py
+6
-0
lms/lib/comment_client/user.py
+14
-2
lms/static/coffee/src/discussion/discussion.coffee
+4
-5
lms/static/coffee/src/discussion/utils.coffee
+1
-1
lms/static/sass/_discussion.scss
+6
-1
lms/templates/discussion/_thread.html
+8
-8
lms/templates/discussion/index.html
+2
-2
lms/templates/discussion/user_profile.html
+38
-0
No files found.
common/djangoapps/student/management/commands/sync_user_info.py
View file @
50e95de9
...
...
@@ -4,7 +4,7 @@
from
django.core.management.base
import
BaseCommand
from
django.contrib.auth.models
import
User
import
comment_client
import
comment_client
as
cc
class
Command
(
BaseCommand
):
...
...
@@ -15,8 +15,5 @@ service'''
def
handle
(
self
,
*
args
,
**
options
):
for
user
in
User
.
objects
.
all
()
.
iterator
():
comment_client
.
update_user
(
user
.
id
,
{
'id'
:
user
.
id
,
'username'
:
user
.
username
,
'email'
:
user
.
email
})
cc_user
=
cc
.
User
.
from_django_user
(
user
)
cc_user
.
save
()
common/djangoapps/student/models.py
View file @
50e95de9
...
...
@@ -50,7 +50,7 @@ from django.dispatch import receiver
from
functools
import
partial
import
comment_client
import
comment_client
as
cc
import
logging
...
...
@@ -265,16 +265,9 @@ def add_user_to_default_group(user, group):
@receiver
(
post_save
,
sender
=
User
)
def
update_user_information
(
sender
,
instance
,
created
,
**
kwargs
):
if
created
:
func
=
comment_client
.
create_user
else
:
func
=
partial
(
comment_client
.
update_user
,
user_id
=
instance
.
id
)
try
:
func
(
attributes
=
{
'id'
:
instance
.
id
,
'username'
:
instance
.
username
,
'email'
:
instance
.
email
,
})
cc_user
=
cc
.
User
.
from_django_user
(
instance
)
cc_user
.
save
()
except
Exception
as
e
:
log
=
logging
.
getLogger
(
"mitx.discussion"
)
log
.
error
(
unicode
(
e
))
...
...
lms/djangoapps/django_comment_client/forum/urls.py
View file @
50e95de9
...
...
@@ -2,7 +2,7 @@ from django.conf.urls.defaults import url, patterns
import
django_comment_client.forum.views
urlpatterns
=
patterns
(
'django_comment_client.forum.views'
,
url
(
r'
search$'
,
'search'
,
name
=
'search
'
),
url
(
r'
users/(?P<user_id>\w+)$'
,
'user_profile'
,
name
=
'user_profile
'
),
url
(
r'(?P<discussion_id>\w+)/threads/(?P<thread_id>\w+)$'
,
'single_thread'
,
name
=
'single_thread'
),
url
(
r'(?P<discussion_id>\w+)/inline$'
,
'inline_discussion'
,
name
=
'inline_discussion'
),
url
(
r'(?P<discussion_id>\w+)$'
,
'forum_form_discussion'
,
name
=
'forum_form_discussion'
),
...
...
lms/djangoapps/django_comment_client/forum/views.py
View file @
50e95de9
...
...
@@ -91,12 +91,6 @@ def get_threads(request, course_id, discussion_id):
threads
,
page
,
num_pages
=
cc
.
Thread
.
search
(
query_params
)
#if _should_perform_search(request):
# query_params['commentable_id'] = discussion_id
# threads, page, num_pages = cc.Thread.searchcomment_client.search_threads(course_id, recursive=False, query_params=utils.strip_none(query_params))
#else:
# threads, page, num_pages = comment_client.get_threads(discussion_id, recursive=False, query_params=utils.strip_none(query_params))
query_params
[
'page'
]
=
page
query_params
[
'num_pages'
]
=
num_pages
...
...
@@ -153,7 +147,6 @@ def forum_form_discussion(request, course_id, discussion_id):
def
render_single_thread
(
request
,
discussion_id
,
course_id
,
thread_id
):
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
#comment_client.get_thread(thread_id, recursive=True)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
=
thread
.
to_dict
(),
\
user
=
request
.
user
,
type
=
'thread'
)
...
...
@@ -196,26 +189,18 @@ def single_thread(request, course_id, discussion_id, thread_id):
return
render_to_response
(
'discussion/index.html'
,
context
)
def
search
(
request
,
course
_id
):
def
user_profile
(
request
,
course_id
,
user
_id
):
course
=
check_course
(
request
.
user
,
course_id
)
text
=
request
.
GET
.
get
(
'text'
,
None
)
commentable_id
=
request
.
GET
.
get
(
'commentable_id'
,
None
)
tags
=
request
.
GET
.
get
(
'tags'
,
None
)
threads
=
cc
.
Threads
.
search
({
'text'
:
text
,
'commentable_id'
:
commentable_id
,
'tags'
:
tags
,
})
discussion_user
=
cc
.
User
(
id
=
user_id
,
course_id
=
course_id
)
context
=
{
'csrf'
:
csrf
(
request
)[
'csrf_token'
],
'init'
:
''
,
'content'
:
render_forum_discussion
(
request
,
course_id
,
threads
,
search_text
=
text
),
'accordion'
:
''
,
'course'
:
course
,
'course'
:
course
,
'user'
:
request
.
user
,
'discussion_user'
:
discussion_user
.
to_dict
(),
}
return
render_to_response
(
'discussion/index.html'
,
context
)
print
context
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
lms/djangoapps/django_comment_client/utils.py
View file @
50e95de9
...
...
@@ -141,3 +141,9 @@ def get_annotated_content_infos(course_id, thread, user, type='thread'):
_annotate
(
child
,
'comment'
)
_annotate
(
thread
,
type
)
return
infos
def
pluralize
(
singular_term
,
count
):
if
int
(
count
)
>=
2
:
return
singular_term
+
's'
return
singular_term
lms/lib/comment_client/user.py
View file @
50e95de9
...
...
@@ -6,8 +6,9 @@ import settings
class
User
(
models
.
Model
):
accessible_fields
=
[
'username'
,
'email'
,
'follower_ids'
,
'upvoted_ids'
,
'downvoted_ids'
,
'id'
,
'external_id'
,
'subscribed_user_ids'
,
'children'
,
'id'
,
'external_id'
,
'subscribed_user_ids'
,
'children'
,
'course_id'
,
'subscribed_thread_ids'
,
'subscribed_commentable_ids'
,
'threads_count'
,
'comments_count'
,
]
updatable_fields
=
[
'username'
,
'external_id'
,
'email'
]
...
...
@@ -19,7 +20,10 @@ class User(models.Model):
@classmethod
def
from_django_user
(
cls
,
user
):
return
cls
(
id
=
str
(
user
.
id
))
return
cls
(
id
=
str
(
user
.
id
),
external_id
=
str
(
user
.
id
),
username
=
user
.
username
,
email
=
user
.
email
)
def
follow
(
self
,
source
):
params
=
{
'source_type'
:
source
.
type
,
'source_id'
:
source
.
id
}
...
...
@@ -51,6 +55,14 @@ class User(models.Model):
request
=
perform_request
(
'delete'
,
url
,
params
)
voteable
.
update_attributes
(
request
)
def
_retrieve
(
self
,
*
args
,
**
kwargs
):
url
=
self
.
url
(
action
=
'get'
,
params
=
self
.
attributes
)
retrieve_params
=
self
.
default_retrieve_params
if
self
.
course_id
:
retrieve_params
[
'course_id'
]
=
self
.
course_id
response
=
perform_request
(
'get'
,
url
,
retrieve_params
)
self
.
update_attributes
(
**
response
)
def
_url_for_vote_comment
(
comment_id
):
return
"{prefix}/comments/{comment_id}/votes"
.
format
(
prefix
=
settings
.
PREFIX
,
comment_id
=
comment_id
)
...
...
lms/static/coffee/src/discussion/discussion.coffee
View file @
50e95de9
...
...
@@ -92,8 +92,6 @@ initializeFollowDiscussion = (discussion) ->
$title
.
attr
(
"prev-text"
,
text
)
initializeNewPost
=
->
#newPostForm = $local(".new-post-form")
#$newPostButton = $local(".discussion-new-post")
view
=
{
discussion_id
:
id
}
$discussionNonContent
=
$discussion
.
children
(
".discussion-non-content"
)
...
...
@@ -137,8 +135,9 @@ initializeFollowDiscussion = (discussion) ->
success
:
(
data
,
textStatus
)
->
$data
=
$
(
data
)
$discussion
.
replaceWith
(
$data
)
Discussion
.
initializeDiscussion
(
$data
)
Discussion
.
bindDiscussionEvents
(
$data
)
$discussion
=
$
(
".discussion[_id='
#{
id
}
']"
)
Discussion
.
initializeDiscussion
(
$discussion
)
Discussion
.
bindDiscussionEvents
(
$discussion
)
handleAjaxSearch
=
(
elem
)
->
$elem
=
$
(
elem
)
...
...
@@ -177,5 +176,5 @@ initializeFollowDiscussion = (discussion) ->
"click .discussion-sort-link"
:
->
handleAjaxSort
(
this
)
$discussion
.
children
(
".discussion-paginator"
).
find
(
".discussion-page-link"
).
click
->
$discussion
.
children
(
".discussion-paginator"
).
find
(
".discussion-page-link"
).
unbind
(
'click'
).
click
->
handleAjaxPage
(
this
)
lms/static/coffee/src/discussion/utils.coffee
View file @
50e95de9
...
...
@@ -60,7 +60,7 @@ wmdEditors = {}
bindLocalEvents
:
(
$local
,
eventsHandler
)
->
for
eventSelector
,
handler
of
eventsHandler
[
event
,
selector
]
=
eventSelector
.
split
(
' '
)
$local
(
selector
)[
event
]
handler
$local
(
selector
)
.
unbind
(
event
)
[
event
]
handler
tagsInputOptions
:
->
autocomplete_url
:
Discussion
.
urlFor
(
'tags_autocomplete'
)
...
...
lms/static/sass/_discussion.scss
View file @
50e95de9
...
...
@@ -71,8 +71,13 @@ $tag-text-color: #5b614f;
font-weight
:
bold
;
}
.sidebar-new-post-button
{
.sidebar-new-post-button
,
.sidebar-promote-moderator-button
{
@include
button
;
}
.sidebar-revoke-moderator-button
{
@include
button
(
simple
,
gray
);
}
.sidebar-new-post-button
,
.sidebar-promote-moderator-button
,
.sidebar-revoke-moderator-button
{
display
:
block
;
box-sizing
:
border-box
;
width
:
100%
;
...
...
lms/templates/discussion/_thread.html
View file @
50e95de9
<
%!
from
django
.
core
.
urlresolvers
import
reverse
%
>
<
%!
from
datehelper
import
time_ago_in_words
%
>
<
%!
from
dateutil
.
parser
import
parse
%
>
<
%!
from
django_comment_client
.
utils
import
pluralize
%
>
<
%!
import
urllib
%
>
<
%
def
name=
"render_thread(course_id, thread, show_comments=False)"
>
<div
class=
"thread"
_id=
"${thread['id']}"
>
${render_content(thread, "thread", show_comments=show_comments)}
...
...
@@ -111,23 +113,21 @@
</
%
def>
<
%
def
name=
"render_info(content)"
>
<
%
def
url_for_user
(
user_id
)
:
return
reverse
('
django_comment_client
.
forum
.
views
.
user_profile
',
args=
[course_id,
user_id
])
%
>
<div
class=
"comment-time"
>
${time_ago_in_words(parse(content['updated_at']))} ago by
% if content['anonymous']:
anonymous
% else:
${content['username']}
<!---# TODO add link to user--
>
<a
href=
"${url_for_user(content['user_id'])}"
>
${content['username']}
</a
>
% endif
</div>
<div
class=
"comment-count"
>
% if content.get('comments_count', -1) >= 0:
<a
href=
"javascript:void(0)"
class=
"discussion-show-comments"
>
% if content.get('comments_count', -1) >= 2:
Show ${content['comments_count']} comments
% else:
Show ${content['comments_count']} comment
% endif
</a>
<a
href=
"javascript:void(0)"
class=
"discussion-show-comments"
>
Show ${content['comments_count']} ${pluralize('comment', content['comments_count'])}
</a>
% endif
</div>
</
%
def>
...
...
lms/templates/discussion/index.html
View file @
50e95de9
...
...
@@ -30,8 +30,8 @@
<
%
include
file=
"_trending_tags.html"
/>
</
section
>
</
nav
>
</
nav
>
</
section
>
<section
class=
"course-content"
>
${content}
...
...
lms/templates/discussion/user_profile.html
0 → 100644
View file @
50e95de9
<
%!
from
django_comment_client
.
utils
import
pluralize
%
>
<
%
inherit
file=
"../main.html"
/>
<
%
namespace
name=
'static'
file=
'../static_content.html'
/>
<
%
block
name=
"bodyclass"
>
discussion
</
%
block>
<
%
block
name=
"title"
><title>
Discussion – MITx 6.002x
</title></
%
block>
<
%
block
name=
"headextra"
>
<
%
static:css
group=
'course'
/>
</
%
block>
<
%
block
name=
"js_extra"
>
<
%
include
file=
"_js_dependencies.html"
/>
</
%
block>
<
%
include
file=
"../course_navigation.html"
args=
"active_page='discussion'"
/>
<section
class=
"container"
>
<div
class=
"course-wrapper"
>
<section
aria-label=
"User Profile"
class=
"user-profile"
>
<nav>
<article
class=
"sidebar-module discussion-sidebar"
>
<div
class=
"sidebar-username"
>
${user.username}
</div>
<div
class=
"sidebar-threads-count"
>
${discussion_user['threads_count']} ${pluralize('discussion', discussion_user['threads_count'])} started
</div>
<div
class=
"sidebar-comments-count"
>
${discussion_user['comments_count']} ${pluralize('comment', discussion_user['comments_count'])}
</div>
<a
href=
"#"
class=
"sidebar-promote-moderator-button"
>
Promote to Moderator
</a>
<a
href=
"#"
class=
"sidebar-revoke-moderator-button"
>
Revoke Moderator provileges
</a>
</article>
</nav>
</section>
<section
class=
"course-content"
>
</section>
</div>
</section>
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