fileupload: translate error messages, allow to limit max file size client side
This commit is contained in:
parent
638bdd8261
commit
6737ca6e16
|
@ -36,6 +36,10 @@ class AppSettings(object):
|
|||
def TRUNCATE_FILENAME(self):
|
||||
return getattr(self.settings, 'DOCBOW_TRUNCATE_FILENAME', 80)
|
||||
|
||||
@property
|
||||
def MAX_FILE_SIZE(self):
|
||||
return getattr(self.settings, 'DOCBOW_MAX_FILE_SIZE', 10*1024*1024)
|
||||
|
||||
import sys
|
||||
|
||||
app_settings = AppSettings()
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -135,8 +135,8 @@
|
|||
$(this).fadeOut(function () {
|
||||
if (data.errorThrown !== 'abort') {
|
||||
var file = data.files[index];
|
||||
file.error = file.error || data.errorThrown
|
||||
|| true;
|
||||
file.error = file.error || 'httpError'
|
||||
|| 'unknownError';
|
||||
that._renderDownload([file])
|
||||
.css('display', 'none')
|
||||
.replaceAll(this)
|
||||
|
@ -639,4 +639,4 @@
|
|||
|
||||
});
|
||||
|
||||
}(jQuery));
|
||||
}(jQuery));
|
||||
|
|
|
@ -24,11 +24,13 @@
|
|||
<td class="name">${name}</td>
|
||||
<td class="size">${sizef}</td>
|
||||
{{open_tv}}if error{{close_tv}}
|
||||
<td class="error" colspan="2">Error:
|
||||
{{open_tv}}if error === 'maxFileSize'{{close_tv}}File is too big
|
||||
{{open_tv}}else error === 'minFileSize'{{close_tv}}File is too small
|
||||
{{open_tv}}else error === 'acceptFileTypes'{{close_tv}}Filetype not allowed
|
||||
{{open_tv}}else error === 'maxNumberOfFiles'{{close_tv}}Max number of files exceeded
|
||||
<td class="error" colspan="2">{% trans "Error" %} :
|
||||
{{open_tv}}if error === 'maxFileSize'{{close_tv}}{% blocktrans %}File is too big, limit is {{ max_file_size }} bytes{% endblocktrans %}
|
||||
{{open_tv}}else error === 'minFileSize'{{close_tv}}{% trans "File is too small" %}
|
||||
{{open_tv}}else error === 'acceptFileTypes'{{close_tv}}{% trans "Filetype not allowed" %}
|
||||
{{open_tv}}else error === 'maxNumberOfFiles'{{close_tv}}{% trans "Max number of files exceeded" %}
|
||||
{{open_tv}}else error === 'httpError'{{close_tv}}{% trans "HTTP Error" %}
|
||||
{{open_tv}}else error === 'unknownError'{{close_tv}}{% trans "Unknown error" %}
|
||||
{{open_tv}}else{{close_tv}}${error}
|
||||
{{open_tv}}/if{{close_tv}}
|
||||
</td>
|
||||
|
@ -83,7 +85,7 @@
|
|||
<script type="text/javascript">
|
||||
$(function () {
|
||||
'use strict';
|
||||
$('#{{name}}-fileupload').fileupload({url: '{{upload_url}}', autoUpload: true, dropZone: $(document)});
|
||||
$('#{{name}}-fileupload').fileupload({url: '{{upload_url}}', maxFileSize: {{max_file_size}}, autoUpload: true, dropZone: $(document)});
|
||||
$.getJSON('{{ upload_url }}', function (files) {
|
||||
var fu = $('#{{name}}-fileupload').data('fileupload');
|
||||
fu._adjustMaxNumberOfFiles(-files.length);
|
||||
|
|
|
@ -9,6 +9,8 @@ from django.template.loader import render_to_string
|
|||
|
||||
from upload_views import get_files_for_id
|
||||
|
||||
from . import app_settings
|
||||
|
||||
class TextInpuWithPredefinedValues(MultiWidget):
|
||||
CLIENT_CODE = '''
|
||||
<script type="text/javascript">
|
||||
|
@ -71,6 +73,7 @@ class JqueryFileUploadFileInput(MultiFileInput):
|
|||
'open_tv': '{{',
|
||||
'close_tv': '}}',
|
||||
'upload_url': self.url,
|
||||
'max_file_size': app_settings.MAX_FILE_SIZE,
|
||||
'extensions': self.extensions,
|
||||
'attached_file_kind': self.attached_file_kind,
|
||||
'files': self.files,
|
||||
|
|
|
@ -79,6 +79,7 @@ __ENVIRONMENT_DEFAULTS = dict(
|
|||
CRISPY_TEMPLATE_PACK='uni_form',
|
||||
DOCBOW_TIMESTAMP_PROVIDER='certum',
|
||||
RAVEN_CONFIG_DSN='',
|
||||
DOCBOW_MAX_FILE_SIZE=10*1024*1024,
|
||||
)
|
||||
|
||||
for key, default in __ENVIRONMENT_DEFAULTS.iteritems():
|
||||
|
@ -98,6 +99,8 @@ for key, default in __ENVIRONMENT_DEFAULTS.iteritems():
|
|||
value = [ unicode(x, 'utf8') for x in value ]
|
||||
elif isinstance(default, unicode):
|
||||
value = unicode(value, 'utf8')
|
||||
elif isinstance(default, int):
|
||||
value = int(value)
|
||||
except KeyError:
|
||||
value = default
|
||||
globals()[key] = value
|
||||
|
|
Loading…
Reference in New Issue