diff src/browser/sat_browser/file_tools.py @ 481:bbdc5357dc00

browser and server sides: refactor HTTP request result values + handle "NoReply" error
author souliane <souliane@mailoo.org>
date Sun, 15 Jun 2014 17:52:08 +0200
parents 97c72fe4a5f2
children 5d8632a7bfde
line wrap: on
line diff
--- a/src/browser/sat_browser/file_tools.py	Sat Jun 14 19:20:27 2014 +0200
+++ b/src/browser/sat_browser/file_tools.py	Sun Jun 15 17:52:08 2014 +0200
@@ -19,6 +19,8 @@
 
 from sat.core.log import getLogger
 log = getLogger(__name__)
+from constants import Const as C
+from sat.core.i18n import D_
 from pyjamas.ui.FileUpload import FileUpload
 from pyjamas.ui.FormPanel import FormPanel
 from pyjamas import Window
@@ -83,13 +85,13 @@
         @param close_cb: the close button callback method
         """
         FormPanel.__init__(self)
-        self.texts = {'ok_button': 'Upload file',
-                     'cancel_button': 'Cancel',
-                     'body': 'Please select a file.',
-                     'submitting': '<strong>Submitting, please wait...</strong>',
-                     'errback': "Your file has been rejected...",
-                     'body_errback': 'Please select another file.',
-                     'callback': "Your file has been accepted!"}
+        self.texts = {'ok_button': D_('Upload file'),
+                     'cancel_button': D_('Cancel'),
+                     'body': D_('Please select a file.'),
+                     'submitting': D_('<strong>Submitting, please wait...</strong>'),
+                     'errback': D_("Your file has been rejected..."),
+                     'body_errback': D_('Please select another file.'),
+                     'callback': D_("Your file has been accepted!")}
         if isinstance(texts, dict):
             self.texts.update(texts)
         self.close_cb = close_cb
@@ -139,10 +141,13 @@
 
     def onSubmitComplete(self, event):
         result = event.getResults()
-        if result != "OK":
+        if result == C.UPLOAD_KO:
             Window.alert(self.texts['errback'])
             self.message.setHTML(self.texts['body_errback'])
             self.upload_btn.setEnabled(True)
-        else:
+        elif result == C.UPLOAD_OK:
             Window.alert(self.texts['callback'])
             self.close_cb()
+        else:
+            Window.alert(_('Submit error: %s' % result))
+            self.upload_btn.setEnabled(True)