Bläddra i källkod

[search] Improve admin layout and fix 500 error on properties tab

Romain Rigaux 12 år sedan
förälder
incheckning
27896742e8

+ 1 - 1
apps/search/src/search/conf.py

@@ -38,4 +38,4 @@ SOLR_URL = Config(
 #)
 
 # ZOOKEEPER URL
-# for COLLECTIONS
+# for COLLECTIONS

+ 1 - 1
apps/search/src/search/search_controler.py

@@ -43,7 +43,7 @@ class SearchController(object):
   def get_new_collections(self):
     solr_collections = SolrApi(SOLR_URL.get()).collections()
     for name in Collection.objects.values_list('name', flat=True):
-      solr_collections.pop(name)
+      solr_collections.pop(name, None)
 
     return solr_collections
 

+ 1 - 1
apps/search/src/search/templates/admin_collections_wizard.mako

@@ -65,7 +65,7 @@ ${ commonheader(_('Search'), "search", user) | n,unicode }
   <h1>${_('No available indexes')}</h1>
 
   <div class="row-fluid">
-    ${ _('Already installed all the collections. You can change the indexes URL in hue.ini.') }
+    ${ _('All the available collections have been installed or you are pointing to a bad Solr URL in hue.ini.') }
   </div>
   % endif
 

+ 2 - 7
apps/search/src/search/templates/layout.mako

@@ -69,9 +69,8 @@
       <li class="${ utils.is_selected(section, 'properties') }">
         <a href="${ url('search:admin_collection_properties', collection=collection) }"><i class="icon-reorder"></i> ${_('Properties')}</a>
       </li>
-      ## Yes or no????? No for now
-      <li class="${ utils.is_selected(section, 'cores') }">
-        <a href="${ url('search:admin_collection_properties', collection=collection) }"><i class="icon-reorder"></i> ${_('Cores')}</a>
+      <li>
+        <a href="${ url('search:index') }?collection=${ collection }"><i class="icon-share-alt"></i> ${ _('Query') }</a>
       </li>
 
       <li class="nav-header">${_('Template')}</li>
@@ -88,10 +87,6 @@
         <a href="${ url('search:admin_collection_highlighting', collection=collection) }">${_('4. Highlighting')}</a>
       </li>
 
-      <li class="nav-header">${_('Search')}</li>
-      <li>
-        <a href="${ url('search:index') }?collection=${ collection }"><i class="icon-share-alt"></i> ${ _('Query') }</a>
-      </li>
     </ul>
   </div>
 </%def>

+ 6 - 5
apps/search/src/search/templates/search.mako

@@ -147,11 +147,12 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
       <textarea id="mustacheTmpl" class="hide">${ hue_collection.result.get_template(with_highlighting=True) | n,unicode }</textarea>
       <script>
 
-      <%
-        docs = response['response']['docs']
-        for doc in response['response']['docs']:
-          if doc['id'] in response.get('highlighting', []):
-            doc.update(response['highlighting'][doc['id']])
+        <%
+          docs = response['response']['docs']
+          for doc in response['response']['docs']:
+            # Beware, schema requires an 'id' field, silently do nothing
+            if 'id' in doc and doc['id'] in response.get('highlighting', []):
+              doc.update(response['highlighting'][doc['id']])
         %>
 
         function genericFormatDate(val, item, format){

+ 3 - 15
apps/search/src/search/views.py

@@ -159,9 +159,8 @@ def admin_collection_properties(request, collection):
 
 @allow_admin_only
 def admin_collection_template(request, collection):
-  solr_collection = SolrApi(SOLR_URL.get()).collection(collection)
-  hue_collection = Collection.objects.get(name=collection)
-  hue_collections = Collection.objects.all()
+  hue_collection = Collection.objects.get(name=collection)  
+  solr_collection = SolrApi(SOLR_URL.get()).collection(collection)  
 
   if request.method == 'POST':
     hue_collection.result.update_from_post(request.POST)
@@ -181,7 +180,6 @@ def admin_collection_template(request, collection):
   return render('admin_collection_template.mako', request, {
     'solr_collection': solr_collection,
     'hue_collection': hue_collection,
-    'hue_collections': hue_collections,
     'sample_data': json.dumps(response["response"]["docs"]),
   })
 
@@ -190,7 +188,6 @@ def admin_collection_template(request, collection):
 def admin_collection_facets(request, collection):
   solr_collection = SolrApi(SOLR_URL.get()).collection(collection)
   hue_collection = Collection.objects.get(name=collection)
-  hue_collections = Collection.objects.all()
 
   if request.method == 'POST':
     hue_collection.facets.update_from_post(request.POST)
@@ -200,7 +197,6 @@ def admin_collection_facets(request, collection):
   return render('admin_collection_facets.mako', request, {
     'solr_collection': solr_collection,
     'hue_collection': hue_collection,
-    'hue_collections': hue_collections,
   })
 
 
@@ -208,7 +204,6 @@ def admin_collection_facets(request, collection):
 def admin_collection_sorting(request, collection):
   solr_collection = SolrApi(SOLR_URL.get()).collection(collection)
   hue_collection = Collection.objects.get(name=collection)
-  hue_collections = Collection.objects.all()
 
   if request.method == 'POST':
     hue_collection.sorting.update_from_post(request.POST)
@@ -218,15 +213,13 @@ def admin_collection_sorting(request, collection):
   return render('admin_collection_sorting.mako', request, {
     'solr_collection': solr_collection,
     'hue_collection': hue_collection,
-    'hue_collections': hue_collections,
   })
 
 
 @allow_admin_only
 def admin_collection_highlighting(request, collection):
-  solr_collection = SolrApi(SOLR_URL.get()).collection(collection)
   hue_collection = Collection.objects.get(name=collection)
-  hue_collections = Collection.objects.all()
+  solr_collection = SolrApi(SOLR_URL.get()).collection(collection)
 
   if request.method == 'POST':
     hue_collection.result.update_from_post(request.POST)
@@ -236,7 +229,6 @@ def admin_collection_highlighting(request, collection):
   return render('admin_collection_highlighting.mako', request, {
     'solr_collection': solr_collection,
     'hue_collection': hue_collection,
-    'hue_collections': hue_collections,
   })
 
 
@@ -246,12 +238,10 @@ def admin_collection_highlighting(request, collection):
 def admin_collection_solr_properties(request, collection):
   solr_collection = SolrApi(SOLR_URL.get()).collection(collection)
   hue_collection = Collection.objects.get(name=collection)
-  hue_collections = Collection.objects.all()
 
   content = render('admin_collection_properties_solr_properties.mako', request, {
     'solr_collection': solr_collection,
     'hue_collection': hue_collection,
-    'hue_collections': hue_collections,
   }, force_template=True).content
 
   return HttpResponse(json.dumps({'content': content}), mimetype="application/json")
@@ -261,12 +251,10 @@ def admin_collection_solr_properties(request, collection):
 def admin_collection_schema(request, collection):
   solr_schema = SolrApi(SOLR_URL.get()).schema(collection)
   hue_collection = Collection.objects.get(name=collection)
-  hue_collections = Collection.objects.all()
 
   content = render('admin_collection_properties_solr_schema.mako', request, {
     'solr_schema': solr_schema,
     'hue_collection': hue_collection,
-    'hue_collections': hue_collections,
   }, force_template=True).content
 
   return HttpResponse(json.dumps({'content': content}), mimetype="application/json")