Explorar el Código

HUE-5618 [home] Use doc name while exporting individual docs

krish hace 9 años
padre
commit
92f7bfc8be
Se han modificado 2 ficheros con 9 adiciones y 1 borrados
  1. 5 1
      desktop/core/src/desktop/api2.py
  2. 4 0
      desktop/core/src/desktop/tests_doc2.py

+ 5 - 1
desktop/core/src/desktop/api2.py

@@ -405,7 +405,11 @@ def export_documents(request):
   # Get PKs of documents to export
   doc_ids = [doc.pk for doc in export_doc_set]
   num_docs = len(doc_ids)
-  filename = 'hue-documents-%s-(%s)' % (datetime.today().strftime('%Y-%m-%d'), num_docs)
+
+  if len(selection) == 1:
+    filename = docs[0].name
+  else:
+    filename = 'hue-documents-%s-(%s)' % (datetime.today().strftime('%Y-%m-%d'), num_docs)
 
   f = StringIO.StringIO()
 

+ 4 - 0
desktop/core/src/desktop/tests_doc2.py

@@ -881,6 +881,10 @@ class TestDocument2ImportExport(object):
     response = self.client.get('/desktop/api2/doc/export/', {'documents': json.dumps([workflow.id, workflow2.id])})
     assert_equal(response['Content-Disposition'], 'attachment; filename=hue-documents-%s-(4).json' % datetime.today().strftime('%Y-%m-%d'))
 
+    # Test that exporting single file gets the name of the document in the filename
+    response = self.client.get('/desktop/api2/doc/export/', {'documents': json.dumps([workflow.id])})
+    assert_equal(response['Content-Disposition'], 'attachment; filename=' + workflow.name + '.json')
+
 
   def test_export_directories_with_children(self):
     # Test that exporting a directory exports children docs