Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
068c6606
Commit
068c6606
authored
Oct 14, 2015
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1077 from pawl/fix_error_localization_2
Use WTForms translations for (non-custom) validation errors
parents
3dcc7b28
f2d8ddce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
babel.py
flask_admin/babel.py
+24
-0
validators.py
flask_admin/contrib/sqla/validators.py
+3
-3
__init__.py
flask_admin/form/__init__.py
+6
-0
No files found.
flask_admin/babel.py
View file @
068c6606
...
@@ -6,11 +6,19 @@ except ImportError:
...
@@ -6,11 +6,19 @@ except ImportError:
return
string
%
variables
return
string
%
variables
def
ngettext
(
singular
,
plural
,
num
,
**
variables
):
def
ngettext
(
singular
,
plural
,
num
,
**
variables
):
variables
.
setdefault
(
'num'
,
num
)
return
(
singular
if
num
==
1
else
plural
)
%
variables
return
(
singular
if
num
==
1
else
plural
)
%
variables
def
lazy_gettext
(
string
,
**
variables
):
def
lazy_gettext
(
string
,
**
variables
):
return
gettext
(
string
,
**
variables
)
return
gettext
(
string
,
**
variables
)
class
Translations
(
object
):
''' dummy Translations class for WTForms, no translation support '''
def
gettext
(
self
,
string
):
return
gettext
(
string
)
def
ngettext
(
self
,
singular
,
plural
,
n
):
return
ngettext
(
singular
,
plural
,
n
)
else
:
else
:
from
flask_admin
import
translations
from
flask_admin
import
translations
...
@@ -34,5 +42,21 @@ else:
...
@@ -34,5 +42,21 @@ else:
ngettext
=
domain
.
ngettext
ngettext
=
domain
.
ngettext
lazy_gettext
=
domain
.
lazy_gettext
lazy_gettext
=
domain
.
lazy_gettext
try
:
from
wtforms.i18n
import
messages_path
except
ImportError
:
from
wtforms.ext.i18n.utils
import
messages_path
wtforms_domain
=
Domain
(
messages_path
(),
domain
=
'wtforms'
)
class
Translations
(
object
):
''' Fixes WTForms translation support and uses wtforms translations '''
def
gettext
(
self
,
string
):
return
wtforms_domain
.
gettext
(
string
)
def
ngettext
(
self
,
singular
,
plural
,
n
):
return
wtforms_domain
.
ngettext
(
singular
,
plural
,
n
)
# lazy imports
# lazy imports
from
.helpers
import
get_current_view
from
.helpers
import
get_current_view
flask_admin/contrib/sqla/validators.py
View file @
068c6606
...
@@ -58,10 +58,10 @@ class ItemsRequired(InputRequired):
...
@@ -58,10 +58,10 @@ class ItemsRequired(InputRequired):
if
len
(
field
.
data
)
<
self
.
min
:
if
len
(
field
.
data
)
<
self
.
min
:
if
self
.
message
is
None
:
if
self
.
message
is
None
:
message
=
field
.
ngettext
(
message
=
field
.
ngettext
(
u"At least
%
d item is required"
,
u"At least
%
(num)
d item is required"
,
u"At least
%
d items are required"
,
u"At least
%
(num)
d items are required"
,
self
.
min
self
.
min
)
%
(
self
.
min
,)
)
else
:
else
:
message
=
self
.
message
message
=
self
.
message
...
...
flask_admin/form/__init__.py
View file @
068c6606
from
wtforms
import
form
,
__version__
as
wtforms_version
from
wtforms
import
form
,
__version__
as
wtforms_version
from
wtforms.fields.core
import
UnboundField
from
wtforms.fields.core
import
UnboundField
from
flask_admin.babel
import
Translations
from
.fields
import
*
from
.fields
import
*
from
.widgets
import
*
from
.widgets
import
*
...
@@ -7,11 +8,16 @@ from .upload import *
...
@@ -7,11 +8,16 @@ from .upload import *
class
BaseForm
(
form
.
Form
):
class
BaseForm
(
form
.
Form
):
_translations
=
Translations
()
def
__init__
(
self
,
formdata
=
None
,
obj
=
None
,
prefix
=
u''
,
**
kwargs
):
def
__init__
(
self
,
formdata
=
None
,
obj
=
None
,
prefix
=
u''
,
**
kwargs
):
self
.
_obj
=
obj
self
.
_obj
=
obj
super
(
BaseForm
,
self
)
.
__init__
(
formdata
=
formdata
,
obj
=
obj
,
prefix
=
prefix
,
**
kwargs
)
super
(
BaseForm
,
self
)
.
__init__
(
formdata
=
formdata
,
obj
=
obj
,
prefix
=
prefix
,
**
kwargs
)
def
_get_translations
(
self
):
return
self
.
_translations
class
FormOpts
(
object
):
class
FormOpts
(
object
):
__slots__
=
[
'widget_args'
,
'form_rules'
]
__slots__
=
[
'widget_args'
,
'form_rules'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment