basic error handling
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user