Gitlab CSE Unil

Skip to content
Snippets Groups Projects

Django

Merged M. Chardon requested to merge django into javascript
4 files
+ 68
16
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 32
0
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
def validate_json_file(value):
message = _(
"File extension '%(extension)s' is not allowed. "
"Allowed extensions are: '%(allowed_extensions)s'."
)
code = 'invalid_json_extension'
if value.content_type :
options = {
# the file types which are going to be allowed for upload
# must be a mimetype
"acceptedformats": (
"image/jpeg",
"image/jpg",
"image/png",
)
}
# allowed file type
extension = value.content_type
if extension not in options["acceptedformats"]:
raise ValidationError(
message,
code=code,
params={
'extension': extension,
'allowed_extensions': ', '.join(options["acceptedformats"])
}
)
\ No newline at end of file
Loading