diff --git a/common/static/coffee/src/discussion/utils.coffee b/common/static/coffee/src/discussion/utils.coffee index b7b7cb2..c5a7724 100644 --- a/common/static/coffee/src/discussion/utils.coffee +++ b/common/static/coffee/src/discussion/utils.coffee @@ -80,6 +80,9 @@ class @DiscussionUtil permanent_link_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}" permanent_link_comment : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}##{param2}" user_profile : "/courses/#{$$course_id}/discussion/forum/users/#{param}" + + user_stats : "/courses/#{$$course_id}/discussion/panel/stats" + followed_threads : "/courses/#{$$course_id}/discussion/forum/users/#{param}/followed" threads : "/courses/#{$$course_id}/discussion/forum" }[name] diff --git a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee index c4539ff..958cb14 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_list_view.coffee @@ -197,6 +197,7 @@ if Backbone? @template = _.template($("#discussion-home").html()) $(".discussion-column").html(@template) $(".post-list a").removeClass("active") + @retrieveUserStats() thread_id = null toggleTopicDrop: (event) => @@ -320,6 +321,16 @@ if Backbone? if callback? callback() + retrieveUserStats: () -> + url = DiscussionUtil.urlFor("user_stats") + DiscussionUtil.safeAjax + url: url + type: "GET" + success: (response, textStatus) => + alert('success') + error: (response) => + alert('error') + retrieveDiscussions: (discussion_ids) -> @discussionIds = discussion_ids.join(',') @mode = 'commentables' diff --git a/lms/djangoapps/django_comment_client/base/urls.py b/lms/djangoapps/django_comment_client/base/urls.py index 41bf568..ab62ba6 100644 --- a/lms/djangoapps/django_comment_client/base/urls.py +++ b/lms/djangoapps/django_comment_client/base/urls.py @@ -3,6 +3,7 @@ from django.conf.urls.defaults import url, patterns urlpatterns = patterns('django_comment_client.base.views', # nopep8 url(r'upload$', 'upload', name='upload'), url(r'users/(?P<user_id>\w+)/update_moderator_status$', 'update_moderator_status', name='update_moderator_status'), + url(r'panel/stats', 'user_stats', name='user_stats'), url(r'threads/tags/autocomplete$', 'tags_autocomplete', name='tags_autocomplete'), url(r'threads/(?P<thread_id>[\w\-]+)/update$', 'update_thread', name='update_thread'), url(r'threads/(?P<thread_id>[\w\-]+)/reply$', 'create_comment', name='create_comment'), @@ -17,7 +18,6 @@ urlpatterns = patterns('django_comment_client.base.views', # nopep8 url(r'threads/(?P<thread_id>[\w\-]+)/follow$', 'follow_thread', name='follow_thread'), url(r'threads/(?P<thread_id>[\w\-]+)/unfollow$', 'unfollow_thread', name='unfollow_thread'), url(r'threads/(?P<thread_id>[\w\-]+)/close$', 'openclose_thread', name='openclose_thread'), - url(r'comments/(?P<comment_id>[\w\-]+)/update$', 'update_comment', name='update_comment'), url(r'comments/(?P<comment_id>[\w\-]+)/endorse$', 'endorse_comment', name='endorse_comment'), url(r'comments/(?P<comment_id>[\w\-]+)/reply$', 'create_sub_comment', name='create_sub_comment'), diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index b2e3ea3..f9ef330 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -649,3 +649,20 @@ def upload(request, course_id): # ajax upload file to a question or answer 'file_url': file_url, } }) + +@login_required +def user_stats(request, course_id): + try: + profiled_user = cc.User(id=request.user.id, course_id=course_id) + print "\n\n\n*******************\n\n\n" + print profiled_user.course_id + query_params = {} + + user_stats_results = profiled_user.stats(query_params) + + return utils.JsonResponse({ + 'stats': user_stats_results + }) + + except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError, User.DoesNotExist): + raise Http404 diff --git a/lms/djangoapps/django_comment_client/forum/urls.py b/lms/djangoapps/django_comment_client/forum/urls.py index 863267f..5c35a64 100644 --- a/lms/djangoapps/django_comment_client/forum/urls.py +++ b/lms/djangoapps/django_comment_client/forum/urls.py @@ -4,6 +4,7 @@ urlpatterns = patterns('django_comment_client.forum.views', # nopep8 url(r'users/(?P<user_id>\w+)/followed$', 'followed_threads', name='followed_threads'), 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\-.]+)/threads/(?P<thread_id>\w+)$', 'single_thread', name='single_thread'), url(r'^(?P<discussion_id>[\w\-.]+)/inline$', 'inline_discussion', name='inline_discussion'), url(r'', 'forum_form_discussion', name='forum_form_discussion'), ) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 6668826..c3e2708 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -387,7 +387,8 @@ def safe_content(content): 'updated_at', 'depth', 'type', 'commentable_id', 'comments_count', 'at_position_list', 'children', 'highlighted_title', 'highlighted_body', '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', + 'stats' ] diff --git a/lms/lib/comment_client/user.py b/lms/lib/comment_client/user.py index 2370052..275558f 100644 --- a/lms/lib/comment_client/user.py +++ b/lms/lib/comment_client/user.py @@ -75,6 +75,15 @@ class User(models.Model): response = perform_request('get', url, params) return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) + def stats(self, query_params={}): + if not self.course_id: + raise CommentClientError("Must provide course_id when retrieving stats for the user") + url = _url_for_user_stats(self.id,self.course_id) + params = {'course_id': self.course_id} + params = merge_dict(params, query_params) + response = perform_request('get', url, params) + return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) + def _retrieve(self, *args, **kwargs): url = self.url(action='get', params=self.attributes) retrieve_params = self.default_retrieve_params @@ -97,8 +106,15 @@ def _url_for_subscription(user_id): def _url_for_user_active_threads(user_id): + print("\n\n\n*********** ACTIVE THREADS **********\n\n\n") return "{prefix}/users/{user_id}/active_threads".format(prefix=settings.PREFIX, user_id=user_id) def _url_for_user_subscribed_threads(user_id): return "{prefix}/users/{user_id}/subscribed_threads".format(prefix=settings.PREFIX, user_id=user_id) + +def _url_for_user_stats(user_id,course_id): + print("\n\n\n*********** USER STATS **********\n\n\n") + return "{prefix}/users/{user_id}/stats?course_id={course_id}".format(prefix=settings.PREFIX, user_id=user_id,course_id=course_id) + +