comparison 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
comparison
equal deleted inserted replaced
480:50b286866739 481:bbdc5357dc00
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.log import getLogger 20 from sat.core.log import getLogger
21 log = getLogger(__name__) 21 log = getLogger(__name__)
22 from constants import Const as C
23 from sat.core.i18n import D_
22 from pyjamas.ui.FileUpload import FileUpload 24 from pyjamas.ui.FileUpload import FileUpload
23 from pyjamas.ui.FormPanel import FormPanel 25 from pyjamas.ui.FormPanel import FormPanel
24 from pyjamas import Window 26 from pyjamas import Window
25 from pyjamas import DOM 27 from pyjamas import DOM
26 from pyjamas.ui.VerticalPanel import VerticalPanel 28 from pyjamas.ui.VerticalPanel import VerticalPanel
81 @param max_size: maximum file size in MB 83 @param max_size: maximum file size in MB
82 @param texts: a dict to ovewrite the default textual values 84 @param texts: a dict to ovewrite the default textual values
83 @param close_cb: the close button callback method 85 @param close_cb: the close button callback method
84 """ 86 """
85 FormPanel.__init__(self) 87 FormPanel.__init__(self)
86 self.texts = {'ok_button': 'Upload file', 88 self.texts = {'ok_button': D_('Upload file'),
87 'cancel_button': 'Cancel', 89 'cancel_button': D_('Cancel'),
88 'body': 'Please select a file.', 90 'body': D_('Please select a file.'),
89 'submitting': '<strong>Submitting, please wait...</strong>', 91 'submitting': D_('<strong>Submitting, please wait...</strong>'),
90 'errback': "Your file has been rejected...", 92 'errback': D_("Your file has been rejected..."),
91 'body_errback': 'Please select another file.', 93 'body_errback': D_('Please select another file.'),
92 'callback': "Your file has been accepted!"} 94 'callback': D_("Your file has been accepted!")}
93 if isinstance(texts, dict): 95 if isinstance(texts, dict):
94 self.texts.update(texts) 96 self.texts.update(texts)
95 self.close_cb = close_cb 97 self.close_cb = close_cb
96 self.setEncoding(FormPanel.ENCODING_MULTIPART) 98 self.setEncoding(FormPanel.ENCODING_MULTIPART)
97 self.setMethod(FormPanel.METHOD_POST) 99 self.setMethod(FormPanel.METHOD_POST)
137 def onSubmit(self, event): 139 def onSubmit(self, event):
138 pass 140 pass
139 141
140 def onSubmitComplete(self, event): 142 def onSubmitComplete(self, event):
141 result = event.getResults() 143 result = event.getResults()
142 if result != "OK": 144 if result == C.UPLOAD_KO:
143 Window.alert(self.texts['errback']) 145 Window.alert(self.texts['errback'])
144 self.message.setHTML(self.texts['body_errback']) 146 self.message.setHTML(self.texts['body_errback'])
145 self.upload_btn.setEnabled(True) 147 self.upload_btn.setEnabled(True)
146 else: 148 elif result == C.UPLOAD_OK:
147 Window.alert(self.texts['callback']) 149 Window.alert(self.texts['callback'])
148 self.close_cb() 150 self.close_cb()
151 else:
152 Window.alert(_('Submit error: %s' % result))
153 self.upload_btn.setEnabled(True)