Bläddra i källkod

HUE-7776 [dashboard] Move Solr exceptionextractor to the model to avoid import conflicts

Romain Rigaux 8 år sedan
förälder
incheckning
a8a569968c

+ 1 - 16
desktop/libs/dashboard/src/dashboard/api.py

@@ -35,7 +35,7 @@ from dashboard.data_export import download as export_download
 from dashboard.decorators import allow_viewer_only
 from dashboard.facet_builder import _guess_gap, _zoom_range_facet, _new_range_facet
 from dashboard.models import Collection2, augment_solr_response, pairwise2, augment_solr_exception,\
-  NESTED_FACET_FORM, COMPARE_FACET, QUERY_FACET
+  NESTED_FACET_FORM, COMPARE_FACET, QUERY_FACET, extract_solr_exception_message
 
 
 LOG = logging.getLogger(__name__)
@@ -570,18 +570,3 @@ def get_collections(request):
       result['message'] = force_unicode(e)
 
   return JsonResponse(result)
-
-
-def extract_solr_exception_message(e):
-  response = {}
-
-  try:
-    message = json.loads(e.message)
-    msg = message['error'].get('msg')
-    response['error'] = msg if msg else message['error']['trace']
-  except Exception, e2:
-    LOG.exception('Failed to extract json message: %s' % force_unicode(e2))
-    LOG.exception('Failed to parse json response: %s' % force_unicode(e))
-    response['error'] = force_unicode(e)
-
-  return response

+ 17 - 1
desktop/libs/dashboard/src/dashboard/models.py

@@ -28,7 +28,7 @@ from django.core.urlresolvers import reverse
 from django.utils.html import escape
 from django.utils.translation import ugettext as _
 
-from desktop.lib.i18n import smart_unicode, smart_str
+from desktop.lib.i18n import smart_unicode, smart_str, force_unicode
 from desktop.models import get_data_link
 
 from dashboard.dashboard_api import get_engine
@@ -879,3 +879,19 @@ def augment_solr_exception(response, collection):
       ]
     }
   })
+
+
+
+def extract_solr_exception_message(e):
+  response = {}
+
+  try:
+    message = json.loads(e.message)
+    msg = message['error'].get('msg')
+    response['error'] = msg if msg else message['error']['trace']
+  except Exception, e2:
+    LOG.exception('Failed to extract json message: %s' % force_unicode(e2))
+    LOG.exception('Failed to parse json response: %s' % force_unicode(e))
+    response['error'] = force_unicode(e)
+
+  return response

+ 1 - 1
desktop/libs/notebook/src/notebook/decorators.py

@@ -30,7 +30,7 @@ from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import smart_unicode
 from desktop.lib.rest.http_client import RestException
 from desktop.models import Document2, Document, FilesystemException
-from dashboard.api import extract_solr_exception_message
+from dashboard.models import extract_solr_exception_message
 
 from notebook.conf import check_permissions
 from notebook.connectors.base import QueryExpired, QueryError, SessionExpired, AuthenticationRequired, OperationTimeout,\