add browser-side validation of document size (#18599)
This commit is contained in:
parent
2c2fcfa8a7
commit
0aeef5bc1f
|
@ -85,6 +85,7 @@ class Homepage(Documents, SingleTableMixin, CommonUpload):
|
|||
def get_context_data(self, **kwargs):
|
||||
ctx = super(Homepage, self).get_context_data(**kwargs)
|
||||
ctx['include_edit_link'] = settings.INCLUDE_EDIT_LINK
|
||||
ctx['max_document_size'] = settings.FARGO_MAX_DOCUMENT_SIZE
|
||||
return ctx
|
||||
|
||||
def get_success_url(self):
|
||||
|
|
|
@ -23,7 +23,16 @@
|
|||
}
|
||||
});
|
||||
$('#send-file input[type=file]').on('change', function() {
|
||||
$('#send-file input[type=submit]').click();
|
||||
$('#id_content input[type=file]').change();
|
||||
});
|
||||
$('#id_content').on('change', function() {
|
||||
var fileSize = this.files[0].size;
|
||||
if (fileSize > {{ max_document_size }}) {
|
||||
$('.invalid-file-error').show();
|
||||
}
|
||||
else {
|
||||
$('#send-file input[type=submit]').click();
|
||||
}
|
||||
});
|
||||
$('#send-file button').on('click', function() {
|
||||
$('#send-file input[type=file]').click();
|
||||
|
@ -44,6 +53,14 @@
|
|||
{{ form.as_p }}
|
||||
<input type="submit" name="submit" value="Upload">
|
||||
</div>
|
||||
<div class="invalid-file-error" style="display: none">
|
||||
<p>
|
||||
{% blocktrans with max_size_mb=max_document_size|filesizeformat %}
|
||||
Error: an uploaded document can't exceed {{ max_size_mb }}.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
<p>{% trans "Please try again with a smaller document." %}</p>
|
||||
</div>
|
||||
<button>{% trans "Upload a new document" %}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue