Mercurial > libervia-web
annotate browser_side/tools.py @ 287:7a1dc69112b8
browser_side (plugin radiocol): send the current queue to new players
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 28 Nov 2013 21:43:12 +0100 |
parents | 0eba1c4f9c6f |
children | 52b1afd7ac3f |
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 |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
165 | 6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org> |
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
22 from pyjamas.ui.DragWidget import DragWidget |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
23 from pyjamas.ui.FileUpload import FileUpload |
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 |
217
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
25 import re |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
26 from nativedom import NativeDOM |
276
aebb96bfa8d1
frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents:
246
diff
changeset
|
27 from sat_frontends.tools import xml |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
28 |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
29 dom = NativeDOM() |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
30 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
31 |
31
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 def html_sanitize(html): |
cb07078f8d6f
browser_side: added naive html sanitize method
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 """Naive sanitization of HTML""" |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
34 return html.replace('<', '<').replace('>', '>') |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
35 |
217
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
36 |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
37 def inlineRoot(xhtml): |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
38 """ make root element inline """ |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
39 doc = dom.parseString(xhtml) |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
40 return xml.inlineRoot(doc) |
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
217
diff
changeset
|
41 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
42 |
217
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
43 def addURLToText(string): |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
44 """Check a text for what looks like an URL and make it clickable. Regexp |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
45 from http://daringfireball.net/2010/07/improved_regex_for_matching_urls""" |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
46 |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
47 def repl(match): |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
48 url = match.group(0) |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
49 if not re.match(r"""[a-z]{3,}://|mailto:|xmpp:""", url): |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
50 url = "http://" + url |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
51 return '<a href="%s" target="_blank" class="url">%s</a>' % (url, match.group(0)) |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
52 pattern = r"""(?i)\b((?:[a-z]{3,}://|(www|ftp)\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/|mailto:|xmpp:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?]))""" |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
53 return re.sub(pattern, repl, string) |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
54 |
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
55 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
56 def setPresenceStyle(item, state, base_style="contact"): |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
57 """ |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
58 @item: any UI element |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
59 @state: a value from ("", "chat", "away", "dnd", "xa") |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
60 """ |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
61 if not hasattr(item, 'presence_style'): |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
62 item.presence_style = None |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
63 style = '%s-%s' % (base_style, state or 'connected') |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
64 if style == item.presence_style: |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
65 return |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
66 if item.presence_style is not None: |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
67 item.removeStyleName(item.presence_style) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
68 item.addStyleName(style) |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
69 item.presence_style = style |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
70 |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
71 |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
72 class DragLabel(DragWidget): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
73 |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
74 def __init__(self, text, _type): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
75 DragWidget.__init__(self) |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
76 self._text = text |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
77 self._type = _type |
217
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
196
diff
changeset
|
78 |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
79 def onDragStart(self, event): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
80 dt = event.dataTransfer |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
81 dt.setData('text/plain', "%s\n%s" % (self._text, self._type)) |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
82 dt.setDragImage(self.getElement(), 15, 15) |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
83 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
84 |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
85 class LiberviaDragWidget(DragLabel): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
86 """ A DragLabel which keep the widget being dragged as class value """ |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
87 current = None # widget currently dragged |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
88 |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
89 def __init__(self, text, _type, widget): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
90 DragLabel.__init__(self, text, _type) |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
91 self.widget = widget |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
92 |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
93 def onDragStart(self, event): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
94 LiberviaDragWidget.current = self.widget |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
95 DragLabel.onDragStart(self, event) |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
96 |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
97 def onDragEnd(self, event): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
98 LiberviaDragWidget.current = None |
283
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
99 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
100 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
101 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
|
102 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
103 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
|
104 """ |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
105 @param name: the input element name |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
106 @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
|
107 @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
|
108 - 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
|
109 - 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
|
110 - 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
|
111 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
|
112 """ |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
113 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
|
114 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
|
115 from pyjamas import DOM |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 |
0eba1c4f9c6f
browser_side (plugins radiocol, xep-0054): check for file size or type before uploading
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 (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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 return True |