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
87566626
Commit
87566626
authored
Sep 30, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #78. Ignore protected properties by default and add support for hybrid properties.
parent
4257d964
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
3 deletions
+25
-3
form.py
flask_admin/contrib/sqlamodel/form.py
+25
-3
No files found.
flask_admin/contrib/sqlamodel/form.py
View file @
87566626
...
...
@@ -246,7 +246,8 @@ def get_form(model, converter,
base_class
=
form
.
BaseForm
,
only
=
None
,
exclude
=
None
,
field_args
=
None
,
hidden_pk
=
False
):
hidden_pk
=
False
,
ignore_hidden
=
True
):
"""
Generate form from the model.
...
...
@@ -264,6 +265,8 @@ def get_form(model, converter,
Dictionary with additional field arguments
:param hidden_pk:
Generate hidden field with model primary key or not
:param ignore_hidden:
If set to True (default), will ignore properties that start with underscore
"""
# TODO: Support new 0.8 API
...
...
@@ -274,15 +277,34 @@ def get_form(model, converter,
field_args
=
field_args
or
{}
properties
=
((
p
.
key
,
p
)
for
p
in
mapper
.
iterate_properties
)
if
only
:
props
=
dict
(
properties
)
def
find
(
name
):
# Try to look it up in properties lsit first
p
=
props
.
get
(
name
)
if
p
is
not
None
:
return
p
# If it is hybrid property or alias, look it up in a model itself
p
=
getattr
(
model
,
name
,
None
)
if
p
is
not
None
and
hasattr
(
p
,
'property'
):
return
p
.
property
raise
ValueError
(
'Invalid model property name
%
s.
%
s'
%
(
model
,
name
))
# Filter properties while maintaining property order in 'only' list
temp
=
dict
(
properties
)
properties
=
((
x
,
temp
[
x
])
for
x
in
only
)
properties
=
((
x
,
find
(
x
))
for
x
in
only
)
elif
exclude
:
properties
=
(
x
for
x
in
properties
if
x
[
0
]
not
in
exclude
)
field_dict
=
{}
for
name
,
prop
in
properties
:
# Ignore protected properties
if
ignore_hidden
and
name
.
startswith
(
'_'
):
continue
field
=
converter
.
convert
(
model
,
mapper
,
prop
,
field_args
.
get
(
name
),
hidden_pk
)
if
field
is
not
None
:
field_dict
[
name
]
=
field
...
...
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