Browse Source

HUE-6262 [core] Converter should separate history docs from saved docs

Jenny Kim 8 years ago
parent
commit
6a92439
1 changed files with 9 additions and 13 deletions
  1. 9 13
      desktop/core/src/desktop/converters.py

+ 9 - 13
desktop/core/src/desktop/converters.py

@@ -57,9 +57,6 @@ class DocumentConverter(object):
             notebook = import_saved_beeswax_query(doc.content_object)
             data = notebook.get_data()
 
-            if doc.is_historic():
-              data['isSaved'] = False
-
             doc2 = self._create_doc2(
                 document=doc,
                 doctype=data['type'],
@@ -68,9 +65,6 @@ class DocumentConverter(object):
                 data=notebook.get_json()
             )
 
-            if doc.is_historic():
-              doc2.is_history = False
-
             self.imported_docs.append(doc2)
         except Exception, e:
           self.failed_docs.append(doc)
@@ -82,7 +76,7 @@ class DocumentConverter(object):
     try:
       from beeswax.models import SavedQuery, HQL, IMPALA, RDBMS
 
-      docs = self._get_unconverted_docs(SavedQuery, with_history=True).filter(extra__in=[HQL, IMPALA, RDBMS]).order_by('-last_modified')
+      docs = self._get_unconverted_docs(SavedQuery, only_history=True).filter(extra__in=[HQL, IMPALA, RDBMS]).order_by('-last_modified')
 
       for doc in docs:
         try:
@@ -192,17 +186,19 @@ class DocumentConverter(object):
         LOG.exception("Failed to set is_trashed field with exception: %s" % e)
 
 
-  def _get_unconverted_docs(self, content_type, with_history=False):
+  def _get_unconverted_docs(self, content_type, only_history=False):
     docs = Document.objects.get_docs(self.user, content_type).filter(owner=self.user)
 
     tags = [
-      DocumentTag.objects.get_trash_tag(user=self.user), # No trashed docs
-      DocumentTag.objects.get_example_tag(user=self.user), # No examples
-      self.imported_tag # No already imported docs
+      DocumentTag.objects.get_trash_tag(user=self.user),  # No trashed docs
+      DocumentTag.objects.get_example_tag(user=self.user),  # No examples
+      self.imported_tag  # No already imported docs
     ]
 
-    if not with_history:
-      tags.append(DocumentTag.objects.get_history_tag(user=self.user)) # No history yet
+    if only_history:
+      docs = docs.filter(tags__in=[DocumentTag.objects.get_history_tag(user=self.user)])
+    else:  # Exclude history docs by default
+      tags.append(DocumentTag.objects.get_history_tag(user=self.user))
 
     return docs.exclude(tags__in=tags)