diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index ac57742ca6..86fe285af0 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -10,30 +10,13 @@ import comment_client from django.core import exceptions from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_POST, require_GET -from django.http import HttpResponse -from django.utils import simplejson from django.views.decorators import csrf from django.core.files.storage import get_storage_class from django.utils.translation import ugettext as _ from django.conf import settings -class JsonResponse(HttpResponse): - def __init__(self, data=None): - content = simplejson.dumps(data, - indent=2, - ensure_ascii=False) - super(JsonResponse, self).__init__(content, - mimetype='application/json; charset=utf8') +from django_comment_client.utils import JsonResponse, JsonError -class JsonError(HttpResponse): - def __init__(self, status, error_message=""): - content = simplejson.dumps({'errors': error_message}, - indent=2, - ensure_ascii=False) - super(JsonError, self).__init__(content, - status=status, - mimetype='application/json; charset=utf8') - def thread_author_only(fn): def verified_fn(request, *args, **kwargs): thread_id = args.get('thread_id', False) or \ diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index a7eb01e219..17bfa4c687 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -60,7 +60,7 @@ def forum_form_discussion(request, course_id, discussion_id): search_text = request.GET.get('text', '') if len(search_text) > 0: - threads = comment_client.search(search_text, discussion_id) + threads = comment_client.search_threads({'text': search_text, 'commentable_id': discussion_id}) else: threads = comment_client.get_threads(discussion_id, recursive=False) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 35c2a86a9a..30c74c0bb0 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -3,6 +3,8 @@ from courseware.models import StudentModuleCache from courseware.module_render import get_module from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore +from django.http import HttpResponse +from django.utils import simplejson from django.conf import settings import operator @@ -88,3 +90,19 @@ def initialize_discussion_info(request, course): 'discussion_id': url_course_id, 'category': 'General', }] + +class JsonResponse(HttpResponse): + def __init__(self, data=None): + content = simplejson.dumps(data, + indent=2, + ensure_ascii=False) + super(JsonResponse, self).__init__(content, + mimetype='application/json; charset=utf8') + +class JsonError(HttpResponse): + def __init__(self, error_message=""): + content = simplejson.dumps({'errors': error_message}, + indent=2, + ensure_ascii=False) + super(JsonError, self).__init__(content, + mimetype='application/json; charset=utf8') diff --git a/lms/envs/common.py b/lms/envs/common.py index ef4d64839b..17e4decf3b 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -273,6 +273,7 @@ TEMPLATE_LOADERS = ( MIDDLEWARE_CLASSES = ( 'util.middleware.ExceptionLoggingMiddleware', + 'django_comment_client.middleware.AjaxExceptionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/lms/lib/comment_client.py b/lms/lib/comment_client.py index 0b3a14e770..e530527ef3 100644 --- a/lms/lib/comment_client.py +++ b/lms/lib/comment_client.py @@ -6,7 +6,8 @@ SERVICE_HOST = 'http://localhost:4567' PREFIX = SERVICE_HOST + '/api/v1' class CommentClientError(Exception): - pass + def __init__(self, msg): + self.message = msg class CommentClientUnknownError(CommentClientError): pass diff --git a/lms/static/coffee/src/discussion.coffee b/lms/static/coffee/src/discussion.coffee index a60c8ff6f0..42234c6f60 100644 --- a/lms/static/coffee/src/discussion.coffee +++ b/lms/static/coffee/src/discussion.coffee @@ -168,6 +168,9 @@ Discussion = else editView = $("