Mercurial > libervia-web
annotate browser_side/file_tools.py @ 407:6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 16 Mar 2014 21:03:50 +0100 |
parents | 462fc3359ee3 |
children | d52f529a6d42 |
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 | 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]: |
398
462fc3359ee3
browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents:
392
diff
changeset
|
61 types = [] |
462fc3359ee3
browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents:
392
diff
changeset
|
62 for type_ in ["- %s (%s)" % (z, y) for (x, y, z) in self.types]: |
462fc3359ee3
browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents:
392
diff
changeset
|
63 if type_ not in types: |
462fc3359ee3
browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents:
392
diff
changeset
|
64 types.append(type_) |
283
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 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
|
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 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
|
68 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
|
69 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
|
70 return True |
387
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 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
73 class FileUploadPanel(FormPanel): |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
74 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
75 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
|
76 """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
|
77 @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
|
78 @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
|
79 @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
|
80 @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
|
81 @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
|
82 """ |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
83 FormPanel.__init__(self) |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
84 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
|
85 'cancel_button': 'Cancel', |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
86 '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
|
87 '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
|
88 '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
|
89 '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
|
90 '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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 self.vPanel = VerticalPanel() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
98 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
|
99 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
|
100 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
101 hPanel = HorizontalPanel() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
102 hPanel.setSpacing(5) |
392
f539f6f8ee9c
browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents:
387
diff
changeset
|
103 hPanel.setStyleName('marginAuto') |
387
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
104 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
|
105 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
|
106 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
107 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
|
108 hPanel.add(self.upload_btn) |
392
f539f6f8ee9c
browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents:
387
diff
changeset
|
109 hPanel.add(Button(self.texts['cancel_button'], getattr(self, "onCloseBtnClick"))) |
387
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
110 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
111 self.status = Label() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
112 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
|
113 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
114 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
|
115 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
116 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
|
117 self.addFormHandler(self) |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
118 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
119 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
|
120 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
|
121 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
122 def onCloseBtnClick(self): |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
123 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
|
124 self.close_cb() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
125 else: |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
126 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
|
127 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
128 def onSubmitBtnClick(self): |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
129 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
|
130 return |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
131 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
|
132 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
|
133 self.submit() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
134 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
135 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
|
136 pass |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
137 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
138 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
|
139 result = event.getResults() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
140 if result != "OK": |
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['errback']) |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
142 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
|
143 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
|
144 else: |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
145 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
|
146 self.close_cb() |