Browse Source

[core] Do not 500 error when importing invalid documents

Romain Rigaux 10 năm trước cách đây
mục cha
commit
93e0478

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

@@ -145,7 +145,10 @@ def import_documents(request):
   f.flush()
 
   stdout = StringIO.StringIO()
-  management.call_command('loaddata', f.name, stdout=stdout)
+  try:
+    management.call_command('loaddata', f.name, stdout=stdout)
+  except Exception, e:
+    return JsonResponse({'message': smart_str(e)})
 
   Document.objects.sync()
 

+ 2 - 2
desktop/core/src/desktop/templates/common_import_export.mako

@@ -30,7 +30,7 @@ from django.utils.translation import ugettext as _
 <div id="import-documents" class="modal hide fade fileupload-modal">
   <div class="modal-header">
     <a href="#" class="close" data-dismiss="modal" data-clear="fileupload">&times;</a>
-    <h3>${_('Import documents')}</h3>
+    <h3>${_('Import Hue documents')}</h3>
   </div>
   <form method="POST" action="/desktop/api2/doc/import" style="display: inline" enctype="multipart/form-data">
     <div class="modal-body form-inline">
@@ -40,7 +40,7 @@ from django.utils.translation import ugettext as _
       </div>
       <div class="fileupload fileupload-new" data-provides="fileupload">
         <span class="btn btn-file" style="line-height: 29px">
-          <span class="fileupload-new">${ _('Select file') }</span>
+          <span class="fileupload-new">${ _('Select json file') }</span>
           <span class="fileupload-exists">${ _('Change') }</span>
           <input type="file" name="documents" accept=".json" />
         </span>