0001-do-not-depend-on-auquotidien-to-show-fargo-pick-a-fi.patch
wcs/file_validation.py | ||
---|---|---|
22 | 22 | |
23 | 23 |
from qommon import get_logger |
24 | 24 |
from qommon.misc import http_get_page, json_loads, http_post_request, ConnectionError |
25 |
from quixote import get_publisher, get_request, get_response |
|
25 |
import qommon.form |
|
26 |
from quixote import get_publisher, get_request, get_response, redirect, get_session |
|
27 |
from quixote.directory import Directory |
|
28 |
from quixote.html import TemplateIO, htmltext |
|
26 | 29 | |
27 | 30 |
from wcs.api_utils import get_secret_and_orig, sign_url |
28 | 31 | |
... | ... | |
192 | 195 |
get_response().add_after_job( |
193 | 196 |
N_('Sending file %s in portfolio of %s') % (filename, user.display_name), |
194 | 197 |
afterjob) |
198 | ||
199 | ||
200 |
class FargoDirectory(Directory): |
|
201 |
_q_exports = ['pick'] |
|
202 | ||
203 |
@property |
|
204 |
def fargo_url(self): |
|
205 |
return get_publisher().get_site_option('fargo_url') |
|
206 | ||
207 |
def pick(self): |
|
208 |
request = get_request() |
|
209 |
if 'cancel' in request.form: |
|
210 |
get_response().add_javascript(['jquery.js']) |
|
211 |
get_response().page_template_key = 'iframe' |
|
212 |
r = TemplateIO(html=True) |
|
213 |
r += htmltext('<html><body>') |
|
214 |
r += htmltext('<script>window.top.document.fargo_close_dialog();</script>') |
|
215 |
r += htmltext('</body></html>') |
|
216 |
return r.getvalue() |
|
217 |
elif 'url' in request.form: |
|
218 |
# Download file |
|
219 |
# FIXME: handle error cases |
|
220 |
url = request.form['url'] |
|
221 |
document = urllib.urlopen(request.form['url']).read() |
|
222 |
scheme, netloc, path, qs, frag = urlparse.urlsplit(url) |
|
223 |
path = map(None, path.split('/')) |
|
224 |
name = urllib.unquote(path[-1]) |
|
225 |
download = qommon.form.PicklableUpload(name, content_type='application/pdf') |
|
226 |
download.__setstate__({ |
|
227 |
'data': document, |
|
228 |
}) |
|
229 |
token = get_session().add_tempfile(download) |
|
230 |
return self.set_token(token, name) |
|
231 |
else: |
|
232 |
# Display file picker |
|
233 |
frontoffice_url = get_publisher().get_frontoffice_url() |
|
234 |
self_url = frontoffice_url |
|
235 |
self_url += '/fargo/pick' |
|
236 |
return redirect('%spick?pick=%s' % (self.fargo_url, urllib.quote(self_url))) |
|
237 | ||
238 |
def set_token(self, token, title): |
|
239 |
get_response().add_javascript(['jquery.js']) |
|
240 |
get_response().page_template_key = 'iframe' |
|
241 |
r = TemplateIO(html=True) |
|
242 |
r += htmltext('<html><body>') |
|
243 |
r += htmltext('<script>window.top.document.fargo_set_token(%s, %s);</script>' % ( |
|
244 |
json.dumps(token), json.dumps(title))) |
|
245 |
r += htmltext('</body></html>') |
|
246 |
return r.getvalue() |
wcs/qommon/form.py | ||
---|---|---|
614 | 614 |
self.max_file_size_bytes = FileSizeWidget.parse_file_size(self.max_file_size) |
615 | 615 |
self.add(HiddenWidget, 'token') |
616 | 616 |
if not self.readonly: |
617 |
hint = '' |
|
618 |
if self.allow_portfolio_picking: |
|
619 |
root_url = get_publisher().get_root_url() |
|
620 |
if (file_validation.has_file_validation() |
|
621 |
and get_request().user |
|
622 |
and not self.readonly): |
|
623 |
get_response().add_javascript(['fargo.js']) |
|
624 |
params = (root_url, |
|
625 |
_('Pick a file from your dropbox'), |
|
626 |
_('Use file from my dropbox')) |
|
627 |
hint += htmltext('<p class="use-file-from-fargo"><span ' |
|
628 |
'data-src="%sfargo/pick" ' |
|
629 |
'data-width="500" ' |
|
630 |
'data-height="400" ' |
|
631 |
'data-title="%s" ' |
|
632 |
'rel="popup">%s</span></p>' % params) |
|
633 |
hint += self.hint or '' |
|
617 | 634 |
attrs = {'data-url': get_publisher().get_root_url() + 'tmp-upload'} |
618 | 635 |
self.file_type = kwargs.pop('file_type', None) |
619 | 636 |
if self.file_type: |
... | ... | |
621 | 638 |
if self.max_file_size_bytes: |
622 | 639 |
# this could be used for client size validation of file size |
623 | 640 |
attrs['data-max-file-size'] = str(self.max_file_size_bytes) |
624 |
self.add(FileWidget, 'file', render_br=False, attrs=attrs) |
|
641 |
self.add(FileWidget, 'file', hint=hint, render_br=False, attrs=attrs)
|
|
625 | 642 |
if self.document_type.get('metadata'): |
626 | 643 |
if self.readonly: |
627 | 644 |
self.add(HiddenWidget, 'validation_url') |
... | ... | |
786 | 803 |
if not valid_file_type: |
787 | 804 |
self.error = _('invalid file type') |
788 | 805 | |
806 |
def render_hint(self, hint): |
|
807 |
return '' |
|
808 | ||
789 | 809 | |
790 | 810 |
class PicklableUpload(Upload): |
791 | 811 |
def __getstate__(self): |
wcs/qommon/static/css/qommon.css | ||
---|---|---|
97 | 97 |
margin-right: 2em; |
98 | 98 |
} |
99 | 99 | |
100 |
p.use-file-from-fargo span { |
|
101 |
border-bottom: 1px dotted #999; |
|
102 |
cursor: pointer; |
|
103 |
} |
|
104 | ||
100 | 105 |
div.form .title, form.quixote .title { |
101 | 106 |
font-weight: bold; |
102 | 107 |
} |
wcs/qommon/static/js/fargo.js | ||
---|---|---|
46 | 46 |
$(base_widget).find('.fileinfo').show(); |
47 | 47 |
$(base_widget).find('input[type=hidden]').val(token); |
48 | 48 |
$(base_widget).find('input[type=file]').hide(); |
49 |
$(base_widget).find('.use-file-from-fargo').hide(); |
|
49 | 50 |
} |
50 | 51 |
document.fargo_close_dialog(); |
51 | 52 |
} |
wcs/qommon/static/js/qommon.fileupload.js | ||
---|---|---|
3 | 3 |
var base_widget = $(this); |
4 | 4 |
if ($(base_widget).find('input[type=hidden]').val()) { |
5 | 5 |
$(base_widget).find('input[type=file]').hide(); |
6 |
$(base_widget).find('.use-file-from-fargo').hide(); |
|
6 | 7 |
} else { |
7 | 8 |
$(base_widget).find('.fileinfo').hide(); |
8 | 9 |
} |
... | ... | |
36 | 37 |
enable(); |
37 | 38 |
$(base_widget).parents('form').find('input[name=submit]').prop('disabled', false); |
38 | 39 |
$(this).hide(); |
40 |
$(base_widget).find('.use-file-from-fargo').hide(); |
|
39 | 41 |
}, |
40 | 42 |
progress: function (e, data) { |
41 | 43 |
var progress = parseInt(data.loaded / data.total * 100, 10); |
... | ... | |
46 | 48 |
$(base_widget).find('input[name$="$token"]').val(''); |
47 | 49 |
$(base_widget).find('.fileinfo').hide(); |
48 | 50 |
$(base_widget).find('input[type=file]').show(); |
51 |
$(base_widget).find('.use-file-from-fargo').show(); |
|
49 | 52 |
return false; |
50 | 53 |
}); |
51 | 54 |
$(this).find('a.change').click(function() { |
wcs/root.py | ||
---|---|---|
51 | 51 |
from myspace import MyspaceDirectory |
52 | 52 |
from forms.preview import PreviewDirectory |
53 | 53 | |
54 |
from wcs import file_validation |
|
54 | 55 | |
55 | 56 |
class CompatibilityDirectory(Directory): |
56 | 57 |
_q_exports = [''] |
... | ... | |
197 | 198 |
_q_exports = ['admin', 'backoffice', 'forms', 'login', 'logout', 'saml', |
198 | 199 |
'ident', 'register', 'afterjobs', 'themes', 'myspace', 'user', 'roles', |
199 | 200 |
'pages', ('tmp-upload', 'tmp_upload'), 'api', '__version__', |
200 |
'tryauth', 'auth', 'preview', ('reload-top', 'reload_top')] |
|
201 |
'tryauth', 'auth', 'preview', ('reload-top', 'reload_top'), 'fargo']
|
|
201 | 202 | |
202 | 203 |
api = ApiDirectory() |
203 | 204 |
themes = template.ThemesDirectory() |
204 | 205 |
myspace = MyspaceDirectory() |
205 | 206 |
pages = qommon.pages.PagesDirectory() |
207 |
fargo = file_validation.FargoDirectory() |
|
206 | 208 | |
207 | 209 |
def tryauth(self): |
208 | 210 |
return forms.root.tryauth(get_publisher().get_root_url()) |
209 |
- |