From 46a7c51df5687aa2ea4678e4eae59d032a549cda Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Thu, 9 Aug 2012 12:12:43 -0400 Subject: [PATCH 01/14] remove voting arrows if one cannot vote --- lms/djangoapps/django_comment_client/forum/views.py | 1 + lms/static/coffee/src/discussion/content.coffee | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index d4f6fda3c0..d0be18b06e 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -155,6 +155,7 @@ def get_annotated_content_info(course_id, content, user, is_thread): 'can_endorse': check_permissions_by_view(user, course_id, content, "endorse_comment") if not is_thread else False, 'can_delete': check_permissions_by_view(user, course_id, content, "delete_thread" if is_thread else "delete_comment"), 'can_openclose': check_permissions_by_view(user, course_id, content, "openclose_thread") if is_thread else False, + 'can_vote': check_permissions_by_view(user, course_id, content, "vote_for_thread" if is_thread else "vote_for_comment"), } return permissions diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index 16c224d165..bf389f80c3 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -386,3 +386,5 @@ initializeFollowThread = (thread) -> $local(".discussion-delete").remove() if not Discussion.getContentInfo id, 'can_openclose' $local(".discussion-openclose").remove() + if not Discussion.getContentInfo id, 'can_vote' + $local(".discussion-vote").remove() From 1bea419237c5822a0a7e5161b7d0d92418573de3 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Thu, 9 Aug 2012 13:02:43 -0400 Subject: [PATCH 02/14] fix discussion_module after merging from MITx/mitx --- common/lib/xmodule/xmodule/discussion_module.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/discussion_module.py b/common/lib/xmodule/xmodule/discussion_module.py index c3388a968c..694b0673be 100644 --- a/common/lib/xmodule/xmodule/discussion_module.py +++ b/common/lib/xmodule/xmodule/discussion_module.py @@ -17,9 +17,10 @@ class DiscussionModule(XModule): } return self.system.render_template('discussion/_discussion_module.html', context) - def __init__(self, system, location, definition, instance_state=None, shared_state=None, **kwargs): - XModule.__init__(self, system, location, definition, instance_state, shared_state, **kwargs) - + def __init__(self, system, location, definition, descriptor, instance_state=None, + shared_state=None, **kwargs): + XModule.__init__(self, system, location, definition, descriptor, + instance_state, shared_state, **kwargs) if isinstance(instance_state, str): instance_state = json.loads(instance_state) xml_data = etree.fromstring(definition['data']) From efad5632d878e3989ce6b239eb72b103233b6ee1 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Thu, 9 Aug 2012 13:03:28 -0400 Subject: [PATCH 03/14] set invisible instead of remove to preserve space of voting arrows when voting is disabled --- lms/static/coffee/src/discussion/content.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index bf389f80c3..51d144c5a1 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -387,4 +387,4 @@ initializeFollowThread = (thread) -> if not Discussion.getContentInfo id, 'can_openclose' $local(".discussion-openclose").remove() if not Discussion.getContentInfo id, 'can_vote' - $local(".discussion-vote").remove() + $local(".discussion-vote").css "visibility", "hidden" From b4621d056236b762a7a7ed2f167a989018bd011e Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Wed, 15 Aug 2012 11:21:11 -0400 Subject: [PATCH 04/14] added QueryCountDebugMiddleware --- lms/djangoapps/django_comment_client/utils.py | 28 ++++++++++++++++++- lms/envs/common.py | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index aac409435a..1aeef06ec7 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -5,7 +5,8 @@ from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore from django.http import HttpResponse from django.utils import simplejson - +from django.db import connection +import logging from django.conf import settings import operator import itertools @@ -128,6 +129,31 @@ class ViewNameMiddleware(object): def process_view(self, request, view_func, view_args, view_kwargs): request.view_name = view_func.__name__ +class QueryCountDebugMiddleware(object): + """ + This middleware will log the number of queries run + and the total time taken for each request (with a + status code of 200). It does not currently support + multi-db setups. + """ + def process_response(self, request, response): + if response.status_code == 200: + total_time = 0 + + for query in connection.queries: + query_time = query.get('time') + if query_time is None: + # django-debug-toolbar monkeypatches the connection + # cursor wrapper and adds extra information in each + # item in connection.queries. The query time is stored + # under the key "duration" rather than "time" and is + # in milliseconds, not seconds. + query_time = query.get('duration', 0) / 1000 + total_time += float(query_time) + + logging.info('%s queries run, total %s seconds' % (len(connection.queries), total_time)) + return response + def get_annotated_content_info(course_id, content, user, type): return { 'editable': check_permissions_by_view(user, course_id, content, "update_thread" if type == 'thread' else "update_comment"), diff --git a/lms/envs/common.py b/lms/envs/common.py index 931a88e0c7..eaa05f4a70 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -329,6 +329,7 @@ MIDDLEWARE_CLASSES = ( # 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django_comment_client.utils.ViewNameMiddleware', + 'django_comment_client.utils.QueryCountDebugMiddleware', ) ############################### Pipeline ####################################### From 7335c1529eae84d013ffc87a9568aba6fb7389c8 Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Wed, 15 Aug 2012 11:21:31 -0700 Subject: [PATCH 05/14] show all content in a course in the forum view --- .../django_comment_client/forum/urls.py | 2 +- .../django_comment_client/forum/views.py | 22 +++++++++---------- lms/lib/comment_client/thread.py | 8 +++++-- lms/templates/course_navigation.html | 2 +- lms/templates/discussion/_thread.html | 6 ++--- lms/templates/discussion/index.html | 4 ---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lms/djangoapps/django_comment_client/forum/urls.py b/lms/djangoapps/django_comment_client/forum/urls.py index bc6b08b3d6..76957a82d8 100644 --- a/lms/djangoapps/django_comment_client/forum/urls.py +++ b/lms/djangoapps/django_comment_client/forum/urls.py @@ -5,5 +5,5 @@ urlpatterns = patterns('django_comment_client.forum.views', url(r'users/(?P\w+)$', 'user_profile', name='user_profile'), url(r'(?P\w+)/threads/(?P\w+)$', 'single_thread', name='single_thread'), url(r'(?P\w+)/inline$', 'inline_discussion', name='inline_discussion'), - url(r'(?P\w+)$', 'forum_form_discussion', name='forum_form_discussion'), + url(r'', 'forum_form_discussion', name='forum_form_discussion'), ) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 79f6aa3931..ff711c237c 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -23,6 +23,10 @@ import dateutil THREADS_PER_PAGE = 5 PAGES_NEARBY_DELTA = 2 + +def _general_discussion_id(course_id): + return course_id.replace('/', '_').replace('.', '_') + def _should_perform_search(request): return bool(request.GET.get('text', False) or \ request.GET.get('tags', False)) @@ -56,7 +60,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs): base_url = { 'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])), - 'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id, discussion_id])), + 'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id])), 'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])), }[discussion_type]() @@ -92,11 +96,11 @@ def render_forum_discussion(*args, **kwargs): def render_user_discussion(*args, **kwargs): return render_discussion(discussion_type='user', *args, **kwargs) -def get_threads(request, course_id, discussion_id): +def get_threads(request, course_id, discussion_id=None): query_params = { 'page': request.GET.get('page', 1), 'per_page': THREADS_PER_PAGE, #TODO maybe change this later - 'sort_key': request.GET.get('sort_key', 'date'), + 'sort_key': request.GET.get('sort_key', 'activity'), 'sort_order': request.GET.get('sort_order', 'desc'), 'text': request.GET.get('text', ''), 'tags': request.GET.get('tags', ''), @@ -128,22 +132,19 @@ def render_search_bar(request, course_id, discussion_id=None, text=''): } return render_to_string('discussion/_search_bar.html', context) -def forum_form_discussion(request, course_id, discussion_id): +def forum_form_discussion(request, course_id): course = check_course(request.user, course_id) - threads, query_params = get_threads(request, course_id, discussion_id) - content = render_forum_discussion(request, course_id, threads, discussion_id=discussion_id, \ - query_params=query_params) + threads, query_params = get_threads(request, course_id) + content = render_forum_discussion(request, course_id, threads, discussion_id=_general_discussion_id(course_id), query_params=query_params) recent_active_threads = cc.search_recent_active_threads( course_id, recursive=False, - query_params={'follower_id': request.user.id, - 'commentable_id': discussion_id}, + query_params={'follower_id': request.user.id}, ) trending_tags = cc.search_trending_tags( course_id, - query_params={'commentable_id': discussion_id}, ) if request.is_ajax(): @@ -153,7 +154,6 @@ def forum_form_discussion(request, course_id, discussion_id): 'csrf': csrf(request)['csrf_token'], 'course': course, 'content': content, - 'accordion': render_accordion(request, course, discussion_id), 'recent_active_threads': recent_active_threads, 'trending_tags': trending_tags, } diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 510432e2f9..4025d15d61 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -35,13 +35,17 @@ class Thread(models.Model): url = cls.url(action='search') else: url = cls.url(action='get_all', params=extract(params, 'commentable_id')) - del params['commentable_id'] + if params.get('commentable_id'): + del params['commentable_id'] response = perform_request('get', url, params, *args, **kwargs) return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) @classmethod def url_for_threads(cls, params={}): - return "{prefix}/{commentable_id}/threads".format(prefix=settings.PREFIX, commentable_id=params['commentable_id']) + if params.get('commentable_id'): + return "{prefix}/{commentable_id}/threads".format(prefix=settings.PREFIX, commentable_id=params['commentable_id']) + else: + return "{prefix}/threads".format(prefix=settings.PREFIX) @classmethod def url_for_search_threads(cls, params={}): diff --git a/lms/templates/course_navigation.html b/lms/templates/course_navigation.html index 2d259e6d29..f6903d42b6 100644 --- a/lms/templates/course_navigation.html +++ b/lms/templates/course_navigation.html @@ -19,7 +19,7 @@ def url_class(url):
  • Textbook
  • % endif % if settings.MITX_FEATURES.get('ENABLE_DISCUSSION_SERVICE'): -
  • Discussion
  • +
  • Discussion
  • News
  • % endif % endif diff --git a/lms/templates/discussion/_thread.html b/lms/templates/discussion/_thread.html index 45ba3513d3..7975173396 100644 --- a/lms/templates/discussion/_thread.html +++ b/lms/templates/discussion/_thread.html @@ -44,10 +44,10 @@ <%def name="render_content(content, type, **kwargs)">
    -
    +
    ${render_vote(content)} -
    +
      % if type == 'comment':
    • Endorse
    • @@ -96,7 +96,7 @@ <%def name="render_tags(content, type, **kwargs)"> <% def url_for_tags(tags): - return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id, content['commentable_id']]) + '?' + urllib.urlencode({'tags': ",".join(tags)}) + return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': ",".join(tags)}) %> % if type == "thread":
      diff --git a/lms/templates/discussion/index.html b/lms/templates/discussion/index.html index 965e8e091f..f34152c569 100644 --- a/lms/templates/discussion/index.html +++ b/lms/templates/discussion/index.html @@ -16,10 +16,6 @@
      -
      -

      Discussion Boards

      - close -