hook up panel to new stats service
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'),
|
||||
)
|
||||
|
||||
@@ -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'
|
||||
|
||||
]
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user