Skip to content

Commit

Permalink
All form document fields can have a default upload size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jcougnaud committed Apr 23, 2024
1 parent bdf6b6c commit edcc67c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ OSIS_DOCUMENT_DOMAIN_LIST = [
OSIS_DOCUMENT_ALLOWED_EXTENSIONS = ['pdf', 'txt', 'docx', 'doc', 'odt', 'png', 'jpg']
# To enabled mimetype validation
ENABLE_MIMETYPE_VALIDATION = True
# All form document fields can have a default upload size limit (in Bytes).
MAX_UPLOAD_SIZE = 5242880
```

OSIS-Document is aimed at being run on multiple servers, so on your primary server, add it to your `urls.py`
Expand Down
8 changes: 7 additions & 1 deletion osis_document/contrib/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# ##############################################################################

from django import forms
from django.conf import settings
from django.contrib.postgres.forms import SplitArrayField
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -68,11 +69,16 @@ class FileUploadField(SplitArrayField):
'max_files': _("Too many files uploaded"),
'min_files': _("Too few files uploaded"),
'invalid_token': _("Invalid token"),
'item_invalid': _('Item %(nth)s in the array did not validate:'),
}

def __init__(self, **kwargs):
self.mimetypes = kwargs.pop('mimetypes', None)
self.max_size = kwargs.pop('max_size', None)

self.max_size = kwargs.pop(
'max_size',
settings.MAX_UPLOAD_SIZE if hasattr(settings, 'MAX_UPLOAD_SIZE') else None,
)
self.max_files = kwargs.pop('max_files', None)
self.min_files = kwargs.pop('min_files', None)
self.upload_to = kwargs.pop('upload_to', None)
Expand Down
4 changes: 4 additions & 0 deletions osis_document/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ msgstr ""
msgid "Invalid upload UUID"
msgstr ""

#, python-format
msgid "Item %(nth)s in the array did not validate:"
msgstr ""

msgid "MIME Type"
msgstr ""

Expand Down
4 changes: 4 additions & 0 deletions osis_document/locale/fr_BE/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ msgstr "Jeton invalide"
msgid "Invalid upload UUID"
msgstr "UUID de téléchargement non valide"

#, python-format
msgid "Item %(nth)s in the array did not validate:"
msgstr "L'élément n°%(nth)s du tableau n’est pas valide :"

msgid "MIME Type"
msgstr "Type MIME"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

setup(
name='OSIS Document',
version='0.10.6',
version='0.10.7',
description='Document management API and widget',
url='http://github.com/uclouvain/osis-document',
author='Université catholique de Louvain',
Expand Down

0 comments on commit edcc67c

Please sign in to comment.