annotate browser_side/file_tools.py @ 391:c86d7a8d2c1e

browser_side: added a dialog in Settings/Account to update/delete the XMPP account
author souliane <souliane@mailoo.org>
date Mon, 03 Mar 2014 15:44:54 +0100
parents 933bce4cb816
children f539f6f8ee9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
cb07078f8d6f browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
cb07078f8d6f browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
cb07078f8d6f browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
4 # Libervia: a Salut à Toi frontend
340
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org>
31
cb07078f8d6f browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
10 # (at your option) any later version.
31
cb07078f8d6f browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
15 # GNU Affero General Public License for more details.
31
cb07078f8d6f browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 332
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
31
cb07078f8d6f browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff changeset
19
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
20 from pyjamas.ui.FileUpload import FileUpload
387
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
21 from pyjamas.ui.FormPanel import FormPanel
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
22 from pyjamas import Window
370
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 363
diff changeset
23 from pyjamas import DOM
387
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
24 from pyjamas.ui.VerticalPanel import VerticalPanel
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
25 from pyjamas.ui.HTML import HTML
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
27 from pyjamas.ui.Button import Button
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
28 from pyjamas.ui.Label import Label
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
29
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
30
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
31 class FilterFileUpload(FileUpload):
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
32
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
33 def __init__(self, name, max_size, types=None):
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
34 """
387
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
35 @param name: the input element name and id
283
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
36 @param max_size: maximum file size in MB
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
37 @param types: allowed types as a list of couples (x, y, z):
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
38 - x: MIME content type e.g. "audio/ogg"
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
39 - y: file extension e.g. "*.ogg"
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
40 - z: description for the user e.g. "Ogg Vorbis Audio"
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
41 If types is None, all file format are accepted
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
42 """
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
43 FileUpload.__init__(self)
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
44 self.setName(name)
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
45 while DOM.getElementById(name):
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
46 name = "%s_" % name
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
47 self.setID(name)
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
48 self._id = name
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
49 self.max_size = max_size
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
50 self.types = types
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
51
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
52 def getFileInfo(self):
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
53 from __pyjamas__ import JS
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
54 JS("var file = top.document.getElementById(this._id).files[0]; return [file.size, file.type]")
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
55
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
56 def check(self):
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
57 if self.getFilename() == "":
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
58 return False
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
59 (size, filetype) = self.getFileInfo()
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
60 if self.types and filetype not in [x for (x, y, z) in self.types]:
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
61 types = ["- %s (%s)" % (z, y) for (x, y, z) in self.types]
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
62 Window.alert('This file type is not accepted.\nAccepted file types are:\n\n%s' % "\n".join(types))
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
63 return False
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
64 if size > self.max_size * pow(2, 20):
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
65 Window.alert('This file is too big!\nMaximum file size: %d MB.' % self.max_size)
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
66 return False
0eba1c4f9c6f browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents: 279
diff changeset
67 return True
387
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
68
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
69
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
70 class FileUploadPanel(FormPanel):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
71
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
72 def __init__(self, action_url, input_id, max_size, texts=None, close_cb=None):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
73 """Build a form panel to upload a file.
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
74 @param action_url: the form action URL
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
75 @param input_id: the input element name and id
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
76 @param max_size: maximum file size in MB
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
77 @param texts: a dict to ovewrite the default textual values
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
78 @param close_cb: the close button callback method
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
79 """
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
80 FormPanel.__init__(self)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
81 self.texts = {'ok_button': 'Upload file',
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
82 'cancel_button': 'Cancel',
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
83 'body': 'Please select a file.',
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
84 'submitting': '<strong>Submitting, please wait...</strong>',
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
85 'errback': "Your file has been rejected...",
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
86 'body_errback': 'Please select another file.',
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
87 'callback': "Your file has been accepted!"}
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
88 if isinstance(texts, dict):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
89 self.texts.update(texts)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
90 self.close_cb = close_cb
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
91 self.setEncoding(FormPanel.ENCODING_MULTIPART)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
92 self.setMethod(FormPanel.METHOD_POST)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
93 self.setAction(action_url)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
94 self.vPanel = VerticalPanel()
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
95 self.message = HTML(self.texts['body'])
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
96 self.vPanel.add(self.message)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
97
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
98 hPanel = HorizontalPanel()
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
99 hPanel.setSpacing(5)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
100 self.file_upload = FilterFileUpload(input_id, max_size)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
101 self.vPanel.add(self.file_upload)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
102
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
103 hPanel.add(Button(self.texts['cancel_button'], getattr(self, "onCloseBtnClick")))
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
104 self.upload_btn = Button(self.texts['ok_button'], getattr(self, "onSubmitBtnClick"))
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
105 hPanel.add(self.upload_btn)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
106
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
107 self.status = Label()
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
108 hPanel.add(self.status)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
109
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
110 self.vPanel.add(hPanel)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
111
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
112 self.add(self.vPanel)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
113 self.addFormHandler(self)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
114
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
115 def setCloseCb(self, close_cb):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
116 self.close_cb = close_cb
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
117
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
118 def onCloseBtnClick(self):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
119 if self.close_cb:
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
120 self.close_cb()
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
121 else:
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
122 print ("WARNING: no close method defined")
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
123
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
124 def onSubmitBtnClick(self):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
125 if not self.file_upload.check():
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
126 return
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
127 self.message.setHTML(self.texts['submitting'])
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
128 self.upload_btn.setEnabled(False)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
129 self.submit()
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
130
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
131 def onSubmit(self, event):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
132 pass
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
133
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
134 def onSubmitComplete(self, event):
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
135 result = event.getResults()
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
136 if result != "OK":
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
137 Window.alert(self.texts['errback'])
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
138 self.message.setHTML(self.texts['body_errback'])
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
139 self.upload_btn.setEnabled(True)
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
140 else:
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
141 Window.alert(self.texts['callback'])
933bce4cb816 browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents: 370
diff changeset
142 self.close_cb()