Browse Source

HUE-1678 [search] Disable multiValued fields from sorting

Removed multiValued from field list
Fixed default collection selected on search page
Fixed problem with Requests2
Enrico Berti 12 năm trước cách đây
mục cha
commit
eeb0c77

+ 7 - 1
apps/search/src/search/templates/admin_collection_sorting.mako

@@ -159,7 +159,13 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
       return new SortingField(obj.field, obj.label, obj.asc, obj.include);
     }));
 
-    self.sortingFieldsList = ko.observableArray(${ hue_collection.fields(user) | n,unicode });
+    var _cleanedFields = ko.utils.arrayFilter(${ hue_collection.fields_data(user) | n,unicode }, function (fieldObj) {
+      return fieldObj.type != "multiValued";
+    });
+
+    self.sortingFieldsList = ko.observableArray(ko.utils.arrayMap(_cleanedFields, function (fieldObj) {
+      return fieldObj.name;
+    }));
 
     self.newFieldSelect = ko.observable();
     self.newFieldSelect.subscribe(function (newValue) {

+ 6 - 1
apps/search/src/search/views.py

@@ -49,7 +49,12 @@ def index(request):
     else:
       return no_collections(request)
 
-  initial_collection = request.COOKIES.get('hueSearchLastCollection', 0)
+  initial_collection = request.COOKIES.get('hueSearchLastCollection', hue_collections[0].id)
+  try:
+    Collection.objects.get(id=initial_collection)
+  except Exception, e:
+    initial_collection = hue_collections[0].id
+
   search_form = QueryForm(request.GET, initial_collection=initial_collection)
   response = {}
   error = {}

+ 3 - 2
desktop/core/src/desktop/lib/rest/resource.py

@@ -49,8 +49,9 @@ class Resource(object):
     """
     Decide whether the body should be a json dict or string
     """
-    if len(resp.content) != 0 and \
-          'application/json' in resp.headers['content-type']:
+
+    if len(resp.content) != 0 and resp.headers.get('content-type') and \
+          'application/json' in resp.headers.get('content-type'):
       try:
         return resp.json()
       except Exception, ex: