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): ...@@ -19,6 +19,10 @@ class PrivateFileField(models.FileField):
- ``content_types``: list of allowed content types. - ``content_types``: list of allowed content types.
- ``max_file_size``: maximum file size. - ``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): def __init__(self, *args, **kwargs):
self._upload = kwargs.pop('upload_subfolder', None) self._upload = kwargs.pop('upload_subfolder', None)
...@@ -39,12 +43,12 @@ class PrivateFileField(models.FileField): ...@@ -39,12 +43,12 @@ class PrivateFileField(models.FileField):
content_type = file.content_type content_type = file.content_type
if self.content_types and content_type not in self.content_types: 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: 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), max_size=filesizeformat(self.max_upload_size),
cur_size=filesizeformat(file.size) size=filesizeformat(file.size)
)) ))
return data return data
......
...@@ -8,7 +8,7 @@ msgid "" ...@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
...@@ -17,12 +17,11 @@ msgstr "" ...@@ -17,12 +17,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: fields.py:42 #: fields.py:23
msgid "Filetype not supported." msgid "File type not supported."
msgstr "" msgstr ""
#: fields.py:45 #: fields.py:24
#, python-brace-format #, python-brace-format
msgid "" msgid "The file may not be larger then {max_size}."
"Please keep the file size under {max_size}, the uploaded file is {cur_size}"
msgstr "" msgstr ""
...@@ -3,27 +3,26 @@ ...@@ -3,27 +3,26 @@
# This file is distributed under the same license as the PACKAGE package. # This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# #
#, fuzzy
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: 2016-10-06 16:59+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language: nl\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\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 #: fields.py:23
msgid "Filetype not supported." msgid "File type not supported."
msgstr "" msgstr "Bestandstype is niet ondersteund."
#: fields.py:45 #: fields.py:24
#, python-brace-format #, python-brace-format
msgid "" msgid "The file may not be larger then {max_size}."
"Please keep the file size under {max_size}, the uploaded file is {cur_size}" msgstr "Het bestand mag niet groter zijn dan {max_size}."
msgstr ""
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