Commit 48ae1339 authored by Diederik van der Boor's avatar Diederik van der Boor
Browse files

Improve and translate field error messages

parent faff7384
......@@ -19,6 +19,10 @@ class PrivateFileField(models.FileField):
- ``content_types``: list of allowed content types.
- ``max_file_size``: maximum file size.
"""
default_error_messages = {
'invalid_file_type': _('File type not supported.'),
'file_too_large': _('The file may not be larger then {max_size}.'),
}
def __init__(self, *args, **kwargs):
self._upload = kwargs.pop('upload_subfolder', None)
......@@ -39,12 +43,12 @@ class PrivateFileField(models.FileField):
content_type = file.content_type
if self.content_types and content_type not in self.content_types:
raise ValidationError(_('Filetype not supported.'))
raise ValidationError(self.error_messages['invalid_file_type'])
if self.max_file_size and file.size > self.max_file_size:
raise ValidationError(_('Please keep the file size under {max_size}, the uploaded file is {cur_size}').format(
raise ValidationError(self.error_messages['file_too_large'].format(
max_size=filesizeformat(self.max_upload_size),
cur_size=filesizeformat(file.size)
size=filesizeformat(file.size)
))
return data
......
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-06 16:02+0200\n"
"POT-Creation-Date: 2016-10-06 16:59+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -17,12 +17,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: fields.py:42
msgid "Filetype not supported."
#: fields.py:23
msgid "File type not supported."
msgstr ""
#: fields.py:45
#: fields.py:24
#, python-brace-format
msgid ""
"Please keep the file size under {max_size}, the uploaded file is {cur_size}"
msgid "The file may not be larger then {max_size}."
msgstr ""
......@@ -3,27 +3,26 @@
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-06 16:02+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"POT-Creation-Date: 2016-10-06 16:59+0200\n"
"PO-Revision-Date: 2016-10-06 16:59+0100\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Last-Translator: Diederik van der Boor <vdboor@edoburu.nl>\n"
"Language-Team: \n"
"X-Generator: Poedit 1.7.4\n"
#: fields.py:42
msgid "Filetype not supported."
msgstr ""
#: fields.py:23
msgid "File type not supported."
msgstr "Bestandstype is niet ondersteund."
#: fields.py:45
#: fields.py:24
#, python-brace-format
msgid ""
"Please keep the file size under {max_size}, the uploaded file is {cur_size}"
msgstr ""
msgid "The file may not be larger then {max_size}."
msgstr "Het bestand mag niet groter zijn dan {max_size}."
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment