فهرست منبع

[search] Convert existing Collection dashboards to Document2

Romain Rigaux 10 سال پیش
والد
کامیت
3892613f9e

+ 0 - 2
apps/search/src/search/management/commands/search_setup.py

@@ -17,10 +17,8 @@
 
 import logging
 
-from django.contrib.auth.models import User
 from django.core import management
 from django.core.management.base import NoArgsCommand
-from django.utils.translation import ugettext as _
 
 from desktop.models import Document
 from useradmin.models import install_sample_user

+ 6 - 6
apps/search/src/search/search_controller.py

@@ -82,24 +82,24 @@ class SearchController(object):
     try:
       for collection in self.get_shared_search_collections().filter(id__in=collection_ids):
         doc2 = Document2.objects.get(type='search-dashboard', id=collection.id)
-    
+
         name = doc2.name + '-copy'
         copy_doc = doc2.doc.get().copy(name=name, owner=self.user)
-    
+
         doc2.pk = None
         doc2.id = None
         doc2.uuid = str(uuid.uuid4())
         doc2.name = name
         doc2.owner = self.user
         doc2.save()
-    
+
         doc2.doc.all().delete()
         doc2.doc.add(copy_doc)
         doc2.save()
-    
+
         copy = Collection2(document=doc2)
-        copy['collection']['name'] = name
-    
+        copy['collection']['label'] = name
+
         doc2.update_data({'collection': copy['collection']})
         doc2.save()
       result['status'] = 0

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

@@ -171,7 +171,7 @@ def save(request):
     dashboard_doc.name = collection['label']
     dashboard_doc.description = collection['description']
     dashboard_doc.save()
-    
+
     response['status'] = 0
     response['id'] = dashboard_doc.id
     response['message'] = _('Page saved !')
@@ -181,6 +181,37 @@ def save(request):
   return JsonResponse(response)
 
 
+@allow_owner_only
+def save_definition(request):
+  response = {'status': -1}
+
+  collection = json.loads(request.POST.get('collection', '{}')) # id
+  query = json.loads(request.POST.get('query', '{}'))
+
+  query['name'] = 'My def'
+  query['uuid'] = 'uuid'
+  query['name'] = 'My def'
+
+  if collection and query:
+    collection = Collection.objects.get(id=collection['id'])
+
+    if query['id']:
+      definition_doc = Document2.objects.get(id=collection['id'])
+    else:
+      definition_doc = Document2.objects.create(name=query['name'], uuid=query['uuid'], type='search-definition', owner=request.user, dependencies=[collection])
+      #Document.objects.link(coordinator_doc, owner=coordinator_doc.owner, name=coordinator_doc.name, description=coordinator_doc.description, extra='coordinator2')
+
+    definition_doc.update_data(query)
+    definition_doc.save()
+    response['status'] = 0
+    response['id'] = definition_doc.id
+    response['message'] = _('Definition saved !')
+  else:
+    response['message'] = _('There is no collection to search.')
+
+  return JsonResponse(response)
+
+
 @allow_viewer_only
 def download(request):
   try:

+ 17 - 11
desktop/core/src/desktop/models.py

@@ -31,11 +31,10 @@ from django.db import models, transaction
 from django.db.models import Q
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
+from desktop import appmanager
 from desktop.lib.i18n import force_unicode
 from desktop.lib.exceptions_renderable import PopupException
 
-from desktop import appmanager
-
 
 LOG = logging.getLogger(__name__)
 
@@ -330,16 +329,21 @@ class DocumentManager(models.Manager):
         from search.models import Collection
 
         for dashboard in Collection.objects.all():
-          if not dashboard.doc.exists(): # not dashbord uuid?   
-            # if brand new
-            # if 3.7, 3.8
-            # if 3.6
-            data = ''         
-            dashboard_doc = Document2.objects.create(name=dashboard.name, uuid=str(uuid.uuid4()), type='search-dashboard', owner=dashboard.owner, description=dashboard.label)
-            Document.objects.link(dashboard_doc, owner=dashboard.owner, name=dashboard.name, description=dashboard.label, extra='search-dashboard')
-            # set uuid
-    
+          col_dict = dashboard.properties_dict['collection']
+          if not 'uuid' in col_dict:
+            _uuid = str(uuid.uuid4())
+            col_dict['uuid'] = _uuid
+            dashboard.update_properties({'collection': col_dict})
+            if dashboard.owner is None:
+              from useradmin.models import install_sample_user
+              owner = install_sample_user()
+            else:
+              owner = dashboard.owner
+            dashboard_doc = Document2.objects.create(name=dashboard.label, uuid=_uuid, type='search-dashboard', owner=owner, description=dashboard.label, data=dashboard.properties)
+            Document.objects.link(dashboard_doc, owner=owner, name=dashboard.label, description=dashboard.label, extra='search-dashboard')
+            dashboard.save()    
     except Exception, e:
+      print e
       LOG.warn(force_unicode(e))
 
     try:
@@ -510,6 +514,8 @@ class Document(models.Model):
         return staticfiles_storage.url('oozie/art/icon_oozie_bundle_48.png')
       elif self.extra == 'notebook':
         return staticfiles_storage.url('spark/art/icon_spark_48.png')
+      elif self.extra.startswith('search'):
+        return staticfiles_storage.url('search/art/icon_search_48.png')
       elif self.content_type.app_label == 'beeswax':
         if self.extra == '0':
           return staticfiles_storage.url(apps['beeswax'].icon_path)