Mercurial > libervia-web
annotate src/browser/file_tools.py @ 449:981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
- browser_side --> src/browser
- public --> src/browser_side/public
- libervia.py --> src/browser/libervia_main.py
- libervia_server --> src/server
- libervia_server/libervia.sh --> src/libervia.sh
- twisted --> src/twisted
- new module src/common
- split constants.py in 3 files:
- src/common/constants.py
- src/browser/constants.py
- src/server/constants.py
- output --> html (generated by pyjsbuild during the installation)
- new option/parameter "data_dir" (-d) to indicates the directory containing html and server_css
- setup.py installs libervia to the following paths:
- src/common --> <LIB>/libervia/common
- src/server --> <LIB>/libervia/server
- src/twisted --> <LIB>/twisted
- html --> <SHARE>/libervia/html
- server_side --> <SHARE>libervia/server_side
- LIBERVIA_INSTALL environment variable takes 2 new options with prompt confirmation:
- clean: remove previous installation directories
- purge: remove building and previous installation directories
You may need to update your sat.conf and/or launching script to update the following options/parameters:
- ssl_certificate
- data_dir
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 20 May 2014 06:41:16 +0200 |
parents | browser_side/file_tools.py@d52f529a6d42 |
children |
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 |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
398
diff
changeset
|
20 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
398
diff
changeset
|
21 log = getLogger(__name__) |
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.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
|
23 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
|
24 from pyjamas import Window |
370
30d03d9f07e4
browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents:
363
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 |
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 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
|
34 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
35 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
|
36 """ |
387
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
37 @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
|
38 @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
|
39 @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
|
40 - 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
|
41 - 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
|
42 - 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
|
43 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
|
44 """ |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 (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
|
62 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
|
63 types = [] |
462fc3359ee3
browser_side: radiocol accepts mime type audio/mp3 in addition to audio/mpeg
souliane <souliane@mailoo.org>
parents:
392
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 return True |
387
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
73 |
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 class FileUploadPanel(FormPanel): |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
76 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
77 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
|
78 """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
|
79 @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
|
80 @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
|
81 @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
|
82 @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
|
83 @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
|
84 """ |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
85 FormPanel.__init__(self) |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
86 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
|
87 'cancel_button': 'Cancel', |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
88 '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
|
89 '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
|
90 '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
|
91 '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
|
92 '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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 self.vPanel = VerticalPanel() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
100 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
|
101 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
|
102 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
103 hPanel = HorizontalPanel() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
104 hPanel.setSpacing(5) |
392
f539f6f8ee9c
browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents:
387
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
109 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
|
110 hPanel.add(self.upload_btn) |
392
f539f6f8ee9c
browser_side: standardize the dialogs size and buttons display:
souliane <souliane@mailoo.org>
parents:
387
diff
changeset
|
111 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
|
112 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
113 self.status = Label() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
114 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
|
115 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
116 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
|
117 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
118 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
|
119 self.addFormHandler(self) |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
120 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
121 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
|
122 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
|
123 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
124 def onCloseBtnClick(self): |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
125 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
|
126 self.close_cb() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
127 else: |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
398
diff
changeset
|
128 log.warning("no close method defined") |
387
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
129 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
130 def onSubmitBtnClick(self): |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
131 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
|
132 return |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
133 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
|
134 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
|
135 self.submit() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
136 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
137 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
|
138 pass |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
139 |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
140 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
|
141 result = event.getResults() |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
142 if result != "OK": |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 else: |
933bce4cb816
browser_side: factorize the code from AvatarUpload to a new class FileUploadPanel
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
147 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
|
148 self.close_cb() |