ソースを参照

[core] Move create collection or core to the new dashboard

Romain Rigaux 11 年 前
コミット
d9c9349

+ 0 - 1
apps/search/src/search/api.py

@@ -230,7 +230,6 @@ class SolrApi(BaseSolrApi):
           )
 
     for fq in query['fqs']:
-      print fq
       if fq['type'] == 'field':
         # This does not work if spaces in Solr: 
         # params += (('fq', ' '.join([urllib.unquote(utf_quoter('{!tag=%s}{!field f=%s}%s' % (fq['field'], fq['field'], _filter))) for _filter in fq['filter']])),)

+ 4 - 29
apps/search/src/search/models.py

@@ -208,33 +208,8 @@ class Sorting(models.Model):
 
 
 class CollectionManager(models.Manager):
-
-  def get_or_create(self, name, solr_properties, is_core_only=False, is_enabled=True, user=None):
-    try:
-      return self.get(name=name), False
-    except Collection.DoesNotExist:
-      facets = Facet.objects.create()
-      result = Result.objects.create()      
-      sorting = Sorting.objects.create()
-      cores = json.dumps(solr_properties)
-
-      collection = Collection.objects.create(
-          name=name,
-          label=name,
-          enabled=is_enabled,
-          cores=cores,
-          is_core_only=is_core_only,
-          facets=facets,
-          result=result,
-          sorting=sorting
-      )
-
-      collection.update_properties({'collection': collection.get_default(user)})
-      collection.save()
-
-      return collection, True      
-
-  def create2(self, name, label):
+ 
+  def create2(self, name, label, is_core_only=False):
     facets = Facet.objects.create()
     result = Result.objects.create()      
     sorting = Sorting.objects.create()
@@ -242,8 +217,8 @@ class CollectionManager(models.Manager):
     collection = Collection.objects.create(
         name=name,
         label=label,
-        cores=json.dumps({}),
-        is_core_only=False,
+        cores=json.dumps({'version': 2}),
+        is_core_only=is_core_only,
         facets=facets,
         result=result,
         sorting=sorting

+ 3 - 38
apps/search/src/search/search_controller.py

@@ -40,44 +40,6 @@ class SearchController(object):
     # TODO perms
     return Collection.objects.filter(enabled=True)
 
-  def get_new_collections(self):
-    try:
-      solr_collections = SolrApi(SOLR_URL.get(), self.user).collections()
-      for name in Collection.objects.values_list('name', flat=True):
-        solr_collections.pop(name, None)
-    except Exception, e:
-      LOG.warn('No Zookeeper servlet running on Solr server: %s' % e)
-      solr_collections = []
-
-    return solr_collections
-
-  def get_new_cores(self):
-    try:
-      solr_cores = SolrApi(SOLR_URL.get(), self.user).cores()
-      for name in Collection.objects.values_list('name', flat=True):
-        solr_cores.pop(name, None)
-    except Exception, e:
-      solr_cores = []
-      LOG.warn('No Single core setup on Solr server: %s' % e)
-
-    return solr_cores
-
-  def add_new_collection(self, attrs):
-    if attrs['type'] == 'collection':
-      collections = self.get_new_collections()
-      collection = collections[attrs['name']]
-
-      hue_collection, created = Collection.objects.get_or_create(name=attrs['name'], solr_properties=collection, is_enabled=True, user=self.user)
-      return hue_collection
-    elif attrs['type'] == 'core':
-      cores = self.get_new_cores()
-      core = cores[attrs['name']]
-
-      hue_collection, created = Collection.objects.get_or_create(name=attrs['name'], solr_properties=core, is_enabled=True, is_core_only=True, user=self.user)
-      return hue_collection
-    else:
-      raise PopupException(_('Collection type does not exist: %s') % attrs)
-
   def delete_collection(self, collection_id):
     id = collection_id
     try:
@@ -129,3 +91,6 @@ class SearchController(object):
 
   def get_solr_collection(self):
     return SolrApi(SOLR_URL.get(), self.user).collections()
+  
+  def get_all_indexes(self):
+    return self.get_solr_collection().keys() + SolrApi(SOLR_URL.get(), self.user).cores().keys()

+ 6 - 66
apps/search/src/search/templates/admin_collections.mako

@@ -28,9 +28,6 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
 
 <div class="search-bar" style="height: 30px">
     <div class="pull-right" style="margin-top: 4px; margin-right: 20px">    
-    <button type="button" class="btn importBtn">
-      <i class="fa fa-plus-circle"></i> ${ _('Import Index') }
-    </button>
     <a class="btn importBtn" href="${ url('indexer:collections') }">
       <i class="fa fa-database"></i> ${ _('Indexes') }
     </a>
@@ -56,7 +53,12 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
   <div class="row-fluid" data-bind="visible: collections().length == 0 && !isLoading()">
     <div class="span10 offset1 center importBtn" style="cursor: pointer">
       <i class="fa fa-plus-circle waiting"></i>
-      <h1 class="emptyMessage">${ _('There are currently no collections defined.') }<br/><a href="javascript:void(0)" class="importBtn">${ _('Click here to add') }</a> ${ _('one or more.') }</h1>
+      <h1 class="emptyMessage">
+        ${ _('There are currently no collections defined.') }<br/>
+        <a class="btn importBtn" href="${ url('search:new_search') }">
+          <i class="fa fa-file-o"></i> ${ _('Dashboard') }
+        </a> 
+      </h1>
     </div>
   </div>
   <div class="row-fluid" data-bind="visible: isLoading()">
@@ -83,31 +85,8 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
     </li>
   </script>
   </div>
-
 </div>
 
-<div id="importModal" class="modal hide fade">
-  <div class="modal-header">
-    <button type="button" class="close" data-dismiss="modal">&times;</button>
-    <h3>${ _('Import Collections and Cores') }</h3>
-  </div>
-  <div class="modal-body">
-    <img src="/static/art/spinner.gif" data-bind="visible: isLoadingImportables()" />
-    <div data-bind="visible: !isLoadingImportables()">
-      <h5>${ _('Collections') }</h5>
-      <div class="alert" data-bind="visible: importableCollections().length == 0">${ _('All available collections from the Solr URL in hue.ini have been imported.') }</div>
-      <table data-bind="visible: importableCollections().length > 0, template: {name: 'importableTemplate', foreach: importableCollections}"></table>
-
-      <h5 style="margin-top: 20px">${ _('Cores') }</h5>
-      <div class="alert" data-bind="visible: importableCores().length == 0">${ _('All available cores from the Solr URL in hue.ini have been imported.') }</div>
-      <table data-bind="visible: importableCores().length > 0, template: {name: 'importableTemplate', foreach: importableCores}"></table>
-    </div>
-  </div>
-  <div class="modal-footer">
-    <a href="javascript:void(0)" class="btn" data-dismiss="modal">${ _('Cancel') }</a>
-    <button id="importModalBtn" href="javascript:void(0)" class="btn btn-primary disable-feedback" data-bind="enable: selectedImportableCollections().length > 0 || selectedImportableCores().length > 0, click: importCollectionsAndCores">${ _('Import Selected') }</button>
-  </div>
-</div>
 
 <script id="importableTemplate" type="text/html">
   <tr>
@@ -156,8 +135,6 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
   var appProperties = {
     labels: [],
     listCollectionsUrl: "${ url("search:admin_collections") }?format=json",
-    listImportablesUrl: "${ url("search:admin_collections_import") }?format=json",
-    importUrl: "${ url("search:admin_collections_import") }",
     deleteUrl: "${ url("search:admin_collection_delete") }",
     copyUrl: "${ url("search:admin_collection_copy") }"
   }
@@ -186,47 +163,10 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
       }, 300);
     });
 
-    $("#importModal").modal({
-      show: false
-    });
-
     $("#deleteModal").modal({
       show: false
     });
 
-    % if is_redirect:
-        showImportModal();
-    % endif
-
-    $(".importBtn").on("click", function () {
-      showImportModal();
-    });
-
-    function showImportModal() {
-      $("#importModal").modal("show");
-      viewModel.updateImportables();
-    }
-
-    $(document).on("importing", function () {
-      var _btn = $("#importModalBtn");
-      _btn.attr("data-loading-text", _btn.text() + " ...");
-      _btn.button("loading");
-    });
-
-    $(document).on("imported", function (e, data) {
-      $("#importModal").modal("hide");
-      $("#importModalBtn").button("reset");
-      if (data.status == 0){
-        $(document).trigger("info", data.message + "<br/>${_('Imported: ')}" + data.imported.join(", "));
-      }
-      else if (data.status == 1){
-        $(document).trigger("info", data.message + "<br/>${_('Imported: ')}" + data.imported.join(", ") + "<br/>${_('Not imported: ')}" + data.notImported.join(", "));
-      }
-      else {
-        $(document).trigger("error", data.message+ "<br/>${_('Not imported: ')}" + data.notImported.join(", "));
-      }
-    });
-
     $(document).on("deleting", function () {
       var _btn = $("#deleteModalBtn");
       _btn.attr("data-loading-text", _btn.text() + " ...");

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

@@ -46,7 +46,13 @@ ${ commonheader(_('Search'), "search", user, "120px") | n,unicode }
       <h1>${ _('It seems there is nothing to search on ...') }</h1>
       % if user.is_superuser:
       <h1>
-        ${ _('... First create a search index with ') }
+        ${ _('... First create a search dashboard with ') }
+        <a class="btn importBtn" href="${ url('search:new_search') }">
+          <i class="fa fa-file-o"></i> ${ _('Dashboard') }
+        </a>      
+      </h1>
+      <h1>
+        ${ _('... or create a search index with ') }
         <a class="btn importBtn" href="${ url('indexer:collections') }">
           <i class="fa fa-database"></i> ${ _('Indexer') }
         </a>      

ファイルの差分が大きいため隠しています
+ 4 - 2
apps/search/src/search/tests.py


+ 0 - 1
apps/search/src/search/urls.py

@@ -39,7 +39,6 @@ urlpatterns = patterns('search.views',
   url(r'^get_collections$', 'get_collections', name='get_collections'),
   
   # Admin
-  url(r'^admin/collections_import$', 'admin_collections_import', name='admin_collections_import'),
   url(r'^admin/collection_delete$', 'admin_collection_delete', name='admin_collection_delete'),
   url(r'^admin/collection_copy$', 'admin_collection_copy', name='admin_collection_copy'),
 

+ 2 - 62
apps/search/src/search/views.py

@@ -67,7 +67,7 @@ def index(request):
 
 @allow_admin_only
 def new_search(request):
-  collections = SearchController(request.user).get_solr_collection().keys()
+  collections = SearchController(request.user).get_all_indexes()
   if not collections:
     return no_collections(request)
 
@@ -220,66 +220,6 @@ def admin_collections(request, is_redirect=False):
   })
 
 
-@allow_admin_only
-def admin_collections_import(request):
-  if request.method == 'POST':
-    searcher = SearchController(request.user)
-    imported = []
-    not_imported = []
-    status = -1
-    message = ""
-    importables = json.loads(request.POST["selected"])
-    for imp in importables:
-      try:
-        searcher.add_new_collection(imp)
-        imported.append(imp['name'])
-      except Exception, e:
-        not_imported.append(imp['name'] + ": " + unicode(str(e), "utf8"))
-
-    if len(imported) == len(importables):
-      status = 0;
-      message = _('Collection(s) or core(s) imported successfully!')
-    elif len(not_imported) == len(importables):
-      status = 2;
-      message = _('There was an error importing the collection(s) or core(s)')
-    else:
-      status = 1;
-      message = _('Collection(s) or core(s) partially imported')
-
-    result = {
-      'status': status,
-      'message': message,
-      'imported': imported,
-      'notImported': not_imported
-    }
-
-    return HttpResponse(json.dumps(result), mimetype="application/json")
-  else:
-    if request.GET.get('format') == 'json':
-      searcher = SearchController(request.user)
-      new_solr_collections = searcher.get_new_collections()
-      massaged_collections = []
-      for coll in new_solr_collections:
-        massaged_collections.append({
-          'type': 'collection',
-          'name': coll
-        })
-      new_solr_cores = searcher.get_new_cores()
-      massaged_cores = []
-      for core in new_solr_cores:
-        massaged_cores.append({
-          'type': 'core',
-          'name': core
-        })
-      response = {
-        'newSolrCollections': list(massaged_collections),
-        'newSolrCores': list(massaged_cores)
-      }
-      return HttpResponse(json.dumps(response), mimetype="application/json")
-    else:
-      return admin_collections(request, True)
-
-
 @allow_admin_only
 def admin_collection_delete(request):
   if request.method != 'POST':
@@ -516,7 +456,7 @@ def get_collections(request):
   result = {'status': -1, 'message': 'Error'}
 
   try:           
-    result['collection'] = SearchController(request.user).get_solr_collection().keys()
+    result['collection'] = SearchController(request.user).get_all_indexes()
     result['status'] = 0      
 
   except Exception, e:

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません