Fix #1: Source size not shown on uploading extension #8
|
@ -14,7 +14,9 @@ from constants.base import (
|
|||
import files.models
|
||||
import files.utils as utils
|
||||
|
||||
MAX_UPLOAD_SIZE = 10485760 # 10MB
|
||||
# Soft limit for the files, effectively we accept up to 1MB extra
|
||||
MAX_UPLOAD_SIZE_MB = 10
|
||||
BYTES_TO_MEGABYTE = 1048576 # constant
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -63,11 +65,12 @@ class FileForm(forms.ModelForm):
|
|||
return
|
||||
|
||||
source = self.cleaned_data['source']
|
||||
if source.size > MAX_UPLOAD_SIZE:
|
||||
# We accept files up to 1MB higher than the limit, so the error message can always show complete integers
|
||||
if source.size >= (MAX_UPLOAD_SIZE_MB + 1) * BYTES_TO_MEGABYTE:
|
||||
raise forms.ValidationError(
|
||||
{
|
||||
'source': [
|
||||
'Please keep filesize under 10MB. Current filesize is {source.size} bytes'
|
||||
f'Please keep filesize under {MAX_UPLOAD_SIZE_MB}MB. Current filesize is {source.size // BYTES_TO_MEGABYTE}MB.'
|
||||
]
|
||||
},
|
||||
code='invalid',
|
||||
|
|
Loading…
Reference in New Issue