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
76558ff7
Commit
76558ff7
authored
Oct 02, 2012
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/mrjoes/flask-admin
parents
a1526ce9
8dfaff16
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
7 deletions
+70
-7
.gitignore
.gitignore
+1
-0
base.py
flask_admin/base.py
+35
-1
form.py
flask_admin/contrib/sqlamodel/form.py
+25
-3
view.py
flask_admin/contrib/sqlamodel/view.py
+8
-2
master.html
flask_admin/templates/admin/master.html
+1
-1
No files found.
.gitignore
View file @
76558ff7
...
...
@@ -12,3 +12,4 @@ dist/*
make.bat
venv
*.sqlite
*.sublime-*
flask_admin/base.py
View file @
76558ff7
from
functools
import
wraps
from
re
import
sub
from
flask
import
Blueprint
,
render_template
,
url_for
,
abort
from
flask
import
Blueprint
,
render_template
,
url_for
,
abort
,
g
from
flask.ext.admin
import
babel
...
...
@@ -86,6 +86,37 @@ class BaseView(object):
"""
__metaclass__
=
AdminViewMeta
@
property
def
_template_args
(
self
):
"""
Extra template arguments.
If you need to pass some extra parameters to the template,
you can override particular view function, contribute
arguments you want to pass to the template and call parent view.
These arguments are local for this request and will be discarded
in next request.
Any value passed through ``_template_args`` will override whatever
parent view function passed to the template.
For example::
class MyAdmin(ModelView):
@expose('/')
def index(self):
self._template_args['name'] = 'foobar'
self._template_args['code'] = '12345'
super(MyAdmin, self).index()
"""
args
=
getattr
(
g
,
'_admin_template_args'
,
None
)
if
args
is
None
:
args
=
g
.
_admin_template_args
=
dict
()
return
args
def
__init__
(
self
,
name
=
None
,
category
=
None
,
endpoint
=
None
,
url
=
None
,
static_folder
=
None
):
"""
Constructor.
...
...
@@ -180,6 +211,9 @@ class BaseView(object):
kwargs
[
'_gettext'
]
=
babel
.
gettext
kwargs
[
'_ngettext'
]
=
babel
.
ngettext
# Contribute extra arguments
kwargs
.
update
(
self
.
_template_args
)
return
render_template
(
template
,
**
kwargs
)
def
_prettify_name
(
self
,
name
):
...
...
flask_admin/contrib/sqlamodel/form.py
View file @
76558ff7
...
...
@@ -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
...
...
flask_admin/contrib/sqlamodel/view.py
View file @
76558ff7
...
...
@@ -451,6 +451,12 @@ class ModelView(BaseModelView):
return
joined
# Database-related API
def
get_query
(
self
):
"""
Return a query for the model type
"""
return
self
.
session
.
query
(
self
.
model
)
def
get_list
(
self
,
page
,
sort_column
,
sort_desc
,
search
,
filters
,
execute
=
True
):
"""
Return models from the database.
...
...
@@ -472,7 +478,7 @@ class ModelView(BaseModelView):
# Will contain names of joined tables to avoid duplicate joins
joins
=
set
()
query
=
self
.
session
.
query
(
self
.
model
)
query
=
self
.
get_query
(
)
# Apply search criteria
if
self
.
_search_supported
and
search
:
...
...
@@ -637,7 +643,7 @@ class ModelView(BaseModelView):
try
:
model_pk
=
getattr
(
self
.
model
,
self
.
_primary_key
)
query
=
self
.
session
.
query
(
self
.
model
)
.
filter
(
model_pk
.
in_
(
ids
))
query
=
self
.
get_query
(
)
.
filter
(
model_pk
.
in_
(
ids
))
if
self
.
fast_mass_delete
:
count
=
query
.
delete
(
synchronize_session
=
False
)
...
...
flask_admin/templates/admin/master.html
View file @
76558ff7
...
...
@@ -72,7 +72,7 @@
</div>
{% endblock %}
<script
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
type=
"text/javascript"
></script>
<script
src=
"http
s
://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
type=
"text/javascript"
></script>
<script
src=
"{{ url_for('admin.static', filename='bootstrap/js/bootstrap.min.js') }}"
type=
"text/javascript"
></script>
<script
src=
"{{ url_for('admin.static', filename='chosen/chosen.jquery.min.js') }}"
type=
"text/javascript"
></script>
...
...
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