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
02084e12
Commit
02084e12
authored
Mar 26, 2016
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1241 from pawl/remove_unnecessary_indention
remove unnecessary indention in form.py convert
parents
624b0d8e
03a2bc6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
96 deletions
+94
-96
form.py
flask_admin/contrib/sqla/form.py
+94
-96
No files found.
flask_admin/contrib/sqla/form.py
View file @
02084e12
...
...
@@ -147,118 +147,116 @@ class AdminModelConverter(ModelConverterBase):
# Check if it is relation or property
if
hasattr
(
prop
,
'direction'
):
return
self
.
_convert_relation
(
prop
,
kwargs
)
else
:
# Ignore pk/fk
if
hasattr
(
prop
,
'columns'
):
# Check if more than one column mapped to the property
if
len
(
prop
.
columns
)
>
1
:
columns
=
filter_foreign_columns
(
model
.
__table__
,
prop
.
columns
)
if
len
(
columns
)
>
1
:
warnings
.
warn
(
'Can not convert multiple-column properties (
%
s.
%
s)'
%
(
model
,
prop
.
key
))
return
None
elif
hasattr
(
prop
,
'columns'
):
# Ignore pk/fk
# Check if more than one column mapped to the property
if
len
(
prop
.
columns
)
>
1
:
columns
=
filter_foreign_columns
(
model
.
__table__
,
prop
.
columns
)
if
len
(
columns
)
>
1
:
warnings
.
warn
(
'Can not convert multiple-column properties (
%
s.
%
s)'
%
(
model
,
prop
.
key
))
return
None
column
=
columns
[
0
]
else
:
# Grab column
column
=
prop
.
columns
[
0
]
form_columns
=
getattr
(
self
.
view
,
'form_columns'
,
None
)
or
()
# Do not display foreign keys - use relations, except when explicitly instructed
if
column
.
foreign_keys
and
prop
.
key
not
in
form_columns
:
return
None
# Only display "real" columns
if
not
isinstance
(
column
,
Column
):
return
None
unique
=
False
column
=
columns
[
0
]
if
column
.
primary_key
:
if
hidden_pk
:
# If requested to add hidden field, show it
return
fields
.
HiddenField
()
else
:
# Grab column
column
=
prop
.
columns
[
0
]
# By default, don't show primary keys either
# If PK is not explicitly allowed, ignore it
if
prop
.
key
not
in
form_columns
:
return
None
form_columns
=
getattr
(
self
.
view
,
'form_columns'
,
None
)
or
()
# Current Unique Validator does not work with multicolumns-pks
if
not
has_multiple_pks
(
model
):
kwargs
[
'validators'
]
.
append
(
Unique
(
self
.
session
,
model
,
column
))
unique
=
True
# If field is unique, validate it
if
column
.
unique
and
not
unique
:
kwargs
[
'validators'
]
.
append
(
Unique
(
self
.
session
,
model
,
column
))
optional_types
=
getattr
(
self
.
view
,
'form_optional_types'
,
(
Boolean
,))
if
(
not
column
.
nullable
and
not
isinstance
(
column
.
type
,
optional_types
)
and
not
column
.
default
and
not
column
.
server_default
):
kwargs
[
'validators'
]
.
append
(
validators
.
InputRequired
())
# Do not display foreign keys - use relations, except when explicitly instructed
if
column
.
foreign_keys
and
prop
.
key
not
in
form_columns
:
return
None
# Apply label and description if it isn't inline form field
if
self
.
view
.
model
==
mapper
.
class_
:
kwargs
[
'label'
]
=
self
.
_get_label
(
prop
.
key
,
kwargs
)
kwargs
[
'description'
]
=
self
.
_get_description
(
prop
.
key
,
kwargs
)
# Only display "real" columns
if
not
isinstance
(
column
,
Column
):
return
None
# Figure out default value
default
=
getattr
(
column
,
'default'
,
None
)
value
=
None
unique
=
False
if
default
is
not
None
:
value
=
getattr
(
default
,
'arg'
,
None
)
if
column
.
primary_key
:
if
hidden_pk
:
# If requested to add hidden field, show it
return
fields
.
HiddenField
()
if
value
is
not
None
:
if
getattr
(
default
,
'is_callable'
,
False
):
value
=
lambda
:
default
.
arg
(
None
)
else
:
# By default, don't show primary keys either
# If PK is not explicitly allowed, ignore it
if
prop
.
key
not
in
form_columns
:
return
None
# Current Unique Validator does not work with multicolumns-pks
if
not
has_multiple_pks
(
model
):
kwargs
[
'validators'
]
.
append
(
Unique
(
self
.
session
,
model
,
column
))
unique
=
True
# If field is unique, validate it
if
column
.
unique
and
not
unique
:
kwargs
[
'validators'
]
.
append
(
Unique
(
self
.
session
,
model
,
column
))
optional_types
=
getattr
(
self
.
view
,
'form_optional_types'
,
(
Boolean
,))
if
(
not
column
.
nullable
and
not
isinstance
(
column
.
type
,
optional_types
)
and
not
column
.
default
and
not
column
.
server_default
):
kwargs
[
'validators'
]
.
append
(
validators
.
InputRequired
())
# Apply label and description if it isn't inline form field
if
self
.
view
.
model
==
mapper
.
class_
:
kwargs
[
'label'
]
=
self
.
_get_label
(
prop
.
key
,
kwargs
)
kwargs
[
'description'
]
=
self
.
_get_description
(
prop
.
key
,
kwargs
)
# Figure out default value
default
=
getattr
(
column
,
'default'
,
None
)
value
=
None
if
default
is
not
None
:
value
=
getattr
(
default
,
'arg'
,
None
)
if
value
is
not
None
:
if
getattr
(
default
,
'is_callable'
,
False
):
value
=
lambda
:
default
.
arg
(
None
)
else
:
if
not
getattr
(
default
,
'is_scalar'
,
True
):
value
=
None
if
not
getattr
(
default
,
'is_scalar'
,
True
):
value
=
None
if
value
is
not
None
:
kwargs
[
'default'
]
=
value
if
value
is
not
None
:
kwargs
[
'default'
]
=
value
# Check nullable
if
column
.
nullable
:
kwargs
[
'validators'
]
.
append
(
validators
.
Optional
())
# Check nullable
if
column
.
nullable
:
kwargs
[
'validators'
]
.
append
(
validators
.
Optional
())
# Override field type if necessary
override
=
self
.
_get_field_override
(
prop
.
key
)
if
override
:
return
override
(
**
kwargs
)
# Override field type if necessary
override
=
self
.
_get_field_override
(
prop
.
key
)
if
override
:
return
override
(
**
kwargs
)
# Check choices
form_choices
=
getattr
(
self
.
view
,
'form_choices'
,
None
)
# Check choices
form_choices
=
getattr
(
self
.
view
,
'form_choices'
,
None
)
if
mapper
.
class_
==
self
.
view
.
model
and
form_choices
:
choices
=
form_choices
.
get
(
column
.
key
)
if
choices
:
return
form
.
Select2Field
(
choices
=
choices
,
allow_blank
=
column
.
nullable
,
**
kwargs
)
if
mapper
.
class_
==
self
.
view
.
model
and
form_choices
:
choices
=
form_choices
.
get
(
column
.
key
)
if
choices
:
return
form
.
Select2Field
(
choices
=
choices
,
allow_blank
=
column
.
nullable
,
**
kwargs
)
# Run converter
converter
=
self
.
get_converter
(
column
)
# Run converter
converter
=
self
.
get_converter
(
column
)
if
converter
is
None
:
return
None
if
converter
is
None
:
return
None
return
converter
(
model
=
model
,
mapper
=
mapper
,
prop
=
prop
,
column
=
column
,
field_args
=
kwargs
)
return
converter
(
model
=
model
,
mapper
=
mapper
,
prop
=
prop
,
column
=
column
,
field_args
=
kwargs
)
return
None
...
...
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