misc: check file size before upload (#13395)
This commit is contained in:
parent
9ec92726b6
commit
dc0a00446c
|
@ -712,9 +712,7 @@ class FileWithPreviewWidget(CompositeWidget):
|
|||
self.get_widget('token').set_value(self.value.token)
|
||||
|
||||
def add_media(self):
|
||||
get_response().add_javascript(['jquery.js', 'jquery-ui.js',
|
||||
'jquery.iframe-transport.js', 'jquery.fileupload.js',
|
||||
'qommon.fileupload.js'])
|
||||
get_response().add_javascript(['qommon.fileupload.js'])
|
||||
if not self.readonly and get_request().user and self.allow_portfolio_picking:
|
||||
get_response().add_javascript(['fargo.js'])
|
||||
|
||||
|
|
|
@ -88,6 +88,13 @@ class HTTPResponse(quixote.http_response.HTTPResponse):
|
|||
self.add_javascript(['jquery.js',
|
||||
'../ckeditor/ckeditor/ckeditor.js',
|
||||
'../ckeditor/ckeditor/adapters/jquery.js'])
|
||||
if script_name == 'qommon.fileupload.js':
|
||||
self.add_javascript(['../../i18n.js',
|
||||
'jquery.js',
|
||||
'jquery-ui.js',
|
||||
'jquery.iframe-transport.js',
|
||||
'jquery.fileupload.js',
|
||||
])
|
||||
self.javascript_scripts.append(str(mapped_script_name))
|
||||
if script_name == 'afterjob.js':
|
||||
self.add_javascript_code('var QOMMON_ROOT_URL = "%s";\n' % \
|
||||
|
|
|
@ -316,6 +316,14 @@ $.WcsFileUpload = {
|
|||
},
|
||||
|
||||
upload: function(base_widget, data) {
|
||||
var max_file_size = $(base_widget).find('input[type=file]').data('max-file-size');
|
||||
if (max_file_size && data.files[0].size > max_file_size) {
|
||||
$(base_widget).find('.fileprogress .bar').css('width', '100%');
|
||||
$(base_widget).find('.fileprogress').addClass('upload-error');
|
||||
$(base_widget).find('.fileprogress .bar').text(WCS_I18N.file_size_error);
|
||||
$(base_widget).find('.fileprogress').show();
|
||||
return;
|
||||
}
|
||||
$(base_widget).find('.fileprogress').removeClass('upload-error');
|
||||
$(base_widget).find('.fileprogress .bar').text(
|
||||
$(base_widget).find('.fileprogress .bar').data('upload'));
|
||||
|
|
|
@ -363,6 +363,7 @@ class RootDirectory(Directory):
|
|||
get_response().set_content_type('text/javascript')
|
||||
strings = {
|
||||
'confirmation': _('Are you sure?'),
|
||||
'file_size_error': _('File size exceeds limits'),
|
||||
'geoloc_unknown_error': _('Geolocation: unknown error'),
|
||||
'geoloc_permission_denied': _('Geolocation: permission denied'),
|
||||
'geoloc_position_unavailable': _('Geolocation: position unavailable'),
|
||||
|
|
Loading…
Reference in New Issue