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
d291c236
Commit
d291c236
authored
Jan 31, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #159 from ctoth/master
More small English cleanups
parents
fb818885
867779e2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
44 deletions
+44
-44
actions.py
flask_admin/actions.py
+3
-3
fileadmin.py
flask_admin/contrib/fileadmin.py
+10
-10
view.py
flask_admin/contrib/mongoengine/view.py
+6
-6
view.py
flask_admin/contrib/sqlamodel/view.py
+22
-22
tools.py
flask_admin/tools.py
+3
-3
No files found.
flask_admin/actions.py
View file @
d291c236
...
@@ -29,10 +29,10 @@ class ActionsMixin(object):
...
@@ -29,10 +29,10 @@ class ActionsMixin(object):
Actions mixin.
Actions mixin.
In some cases, you might work with more than one "entity" (model, file, etc) in
In some cases, you might work with more than one "entity" (model, file, etc) in
your admin view and will want to perform actions on
group of entities at once
.
your admin view and will want to perform actions on
a group of entities simultaneously
.
In this case, you can add this functionality by doing this:
In this case, you can add this functionality by doing this:
1. Add mixin to your administrative view class
1. Add
this
mixin to your administrative view class
2. Call `init_actions` in your class constructor
2. Call `init_actions` in your class constructor
3. Expose actions view
3. Expose actions view
4. Import `actions.html` library and add call library macros in your template
4. Import `actions.html` library and add call library macros in your template
...
@@ -76,7 +76,7 @@ class ActionsMixin(object):
...
@@ -76,7 +76,7 @@ class ActionsMixin(object):
def
get_actions_list
(
self
):
def
get_actions_list
(
self
):
"""
"""
Return list and a dictionary of allowed actions.
Return
a
list and a dictionary of allowed actions.
"""
"""
actions
=
[]
actions
=
[]
actions_confirmation
=
{}
actions_confirmation
=
{}
...
...
flask_admin/contrib/fileadmin.py
View file @
d291c236
...
@@ -162,7 +162,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -162,7 +162,7 @@ class FileAdmin(BaseView, ActionsMixin):
:param base_url:
:param base_url:
Base URL for the files
Base URL for the files
:param name:
:param name:
Name of this view. If not provided, will
be defaulted
to the class name.
Name of this view. If not provided, will
default
to the class name.
:param category:
:param category:
View category
View category
:param endpoint:
:param endpoint:
...
@@ -171,7 +171,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -171,7 +171,7 @@ class FileAdmin(BaseView, ActionsMixin):
URL for view
URL for view
:param verify_path:
:param verify_path:
Verify if path exists. If set to `True` and path does not exist
Verify if path exists. If set to `True` and path does not exist
will
throw
exception.
will
raise an
exception.
"""
"""
self
.
base_path
=
base_path
self
.
base_path
=
base_path
self
.
base_url
=
base_url
self
.
base_url
=
base_url
...
@@ -198,7 +198,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -198,7 +198,7 @@ class FileAdmin(BaseView, ActionsMixin):
def
is_accessible_path
(
self
,
path
):
def
is_accessible_path
(
self
,
path
):
"""
"""
Verify if
path is accessible for
current user.
Verify if
the provided path is accessible for the
current user.
Override to customize behavior.
Override to customize behavior.
...
@@ -242,7 +242,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -242,7 +242,7 @@ class FileAdmin(BaseView, ActionsMixin):
def
is_file_editable
(
self
,
filename
):
def
is_file_editable
(
self
,
filename
):
"""
"""
Verify if
file can be edited.
Determine if the
file can be edited.
Override to customize behavior.
Override to customize behavior.
...
@@ -261,7 +261,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -261,7 +261,7 @@ class FileAdmin(BaseView, ActionsMixin):
def
is_in_folder
(
self
,
base_path
,
directory
):
def
is_in_folder
(
self
,
base_path
,
directory
):
"""
"""
Verify
if
`directory` is in `base_path` folder
Verify
that
`directory` is in `base_path` folder
:param base_path:
:param base_path:
Base directory path
Base directory path
...
@@ -319,9 +319,9 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -319,9 +319,9 @@ class FileAdmin(BaseView, ActionsMixin):
"""
"""
Verify and normalize path.
Verify and normalize path.
If
path is not relative to the base directory, will throw
404 exception.
If
the path is not relative to the base directory, will raise a
404 exception.
If
path does not exist, will also throw
404 exception.
If
the path does not exist, this will also raise a
404 exception.
"""
"""
base_path
=
self
.
get_base_path
()
base_path
=
self
.
get_base_path
()
...
@@ -353,7 +353,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -353,7 +353,7 @@ class FileAdmin(BaseView, ActionsMixin):
Index view method
Index view method
:param path:
:param path:
Optional directory path. If not provided, will use base directory
Optional directory path. If not provided, will use
the
base directory
"""
"""
# Get path and verify if it is valid
# Get path and verify if it is valid
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
...
@@ -406,7 +406,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -406,7 +406,7 @@ class FileAdmin(BaseView, ActionsMixin):
Upload view method
Upload view method
:param path:
:param path:
Optional directory path. If not provided, will use base directory
Optional directory path. If not provided, will use
the
base directory
"""
"""
# Get path and verify if it is valid
# Get path and verify if it is valid
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
...
@@ -439,7 +439,7 @@ class FileAdmin(BaseView, ActionsMixin):
...
@@ -439,7 +439,7 @@ class FileAdmin(BaseView, ActionsMixin):
Directory creation view method
Directory creation view method
:param path:
:param path:
Optional directory path. If not provided, will use base directory
Optional directory path. If not provided, will use
the
base directory
"""
"""
# Get path and verify if it is valid
# Get path and verify if it is valid
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
base_path
,
directory
,
path
=
self
.
_normalize_path
(
path
)
...
...
flask_admin/contrib/mongoengine/view.py
View file @
d291c236
...
@@ -75,7 +75,7 @@ class ModelView(BaseModelView):
...
@@ -75,7 +75,7 @@ class ModelView(BaseModelView):
"""
"""
Field to filter converter.
Field to filter converter.
Override this attribute to use non-default converter.
Override this attribute to use
a
non-default converter.
"""
"""
column_type_formatters
=
DEFAULT_FORMATTERS
column_type_formatters
=
DEFAULT_FORMATTERS
...
@@ -123,7 +123,7 @@ class ModelView(BaseModelView):
...
@@ -123,7 +123,7 @@ class ModelView(BaseModelView):
def
get_pk_value
(
self
,
model
):
def
get_pk_value
(
self
,
model
):
"""
"""
Return primary key value from the model instance
Return
the
primary key value from the model instance
:param model:
:param model:
Model instance
Model instance
...
@@ -154,7 +154,7 @@ class ModelView(BaseModelView):
...
@@ -154,7 +154,7 @@ class ModelView(BaseModelView):
def
scaffold_sortable_columns
(
self
):
def
scaffold_sortable_columns
(
self
):
"""
"""
Return
sortable columns dictionary
(name, field)
Return
a dictionary of sortable columns
(name, field)
"""
"""
columns
=
{}
columns
=
{}
...
@@ -222,7 +222,7 @@ class ModelView(BaseModelView):
...
@@ -222,7 +222,7 @@ class ModelView(BaseModelView):
def
is_valid_filter
(
self
,
filter
):
def
is_valid_filter
(
self
,
filter
):
"""
"""
Validate if
it is
valid MongoEngine filter
Validate if
the provided filter is a
valid MongoEngine filter
:param filter:
:param filter:
Filter object
Filter object
...
@@ -254,7 +254,7 @@ class ModelView(BaseModelView):
...
@@ -254,7 +254,7 @@ class ModelView(BaseModelView):
:param search:
:param search:
Search criteria
Search criteria
:param filters:
:param filters:
List of applied fiters
List of applied fi
l
ters
:param execute:
:param execute:
Run query immediately or not
Run query immediately or not
"""
"""
...
@@ -307,7 +307,7 @@ class ModelView(BaseModelView):
...
@@ -307,7 +307,7 @@ class ModelView(BaseModelView):
def
get_one
(
self
,
id
):
def
get_one
(
self
,
id
):
"""
"""
Return
single model instance by
ID
Return
a single model instance by its
ID
:param id:
:param id:
Model ID
Model ID
...
...
flask_admin/contrib/sqlamodel/view.py
View file @
d291c236
...
@@ -18,7 +18,7 @@ from .typefmt import DEFAULT_FORMATTERS
...
@@ -18,7 +18,7 @@ from .typefmt import DEFAULT_FORMATTERS
class
ModelView
(
BaseModelView
):
class
ModelView
(
BaseModelView
):
"""
"""
SQLA
L
chemy model view
SQLA
l
chemy model view
Usage sample::
Usage sample::
...
@@ -90,7 +90,7 @@ class ModelView(BaseModelView):
...
@@ -90,7 +90,7 @@ class ModelView(BaseModelView):
class MyModelView(ModelView):
class MyModelView(ModelView):
column_searchable_list = (User.name, User.email)
column_searchable_list = (User.name, User.email)
F
ollowing search rules apply:
The f
ollowing search rules apply:
- If you enter *ZZZ* in the UI search field, it will generate *ILIKE '
%
ZZZ
%
'*
- If you enter *ZZZ* in the UI search field, it will generate *ILIKE '
%
ZZZ
%
'*
statement against searchable columns.
statement against searchable columns.
...
@@ -103,8 +103,8 @@ class ModelView(BaseModelView):
...
@@ -103,8 +103,8 @@ class ModelView(BaseModelView):
- If you prefix your search term with ^, it will find all rows
- If you prefix your search term with ^, it will find all rows
that start with ^. So, if you entered *^ZZZ*, *ILIKE 'ZZZ
%
'* will be used.
that start with ^. So, if you entered *^ZZZ*, *ILIKE 'ZZZ
%
'* will be used.
- If you prefix your search term with =, it will
do
exact match.
- If you prefix your search term with =, it will
perform an
exact match.
For example, if you entered *=ZZZ*,
*ILIKE 'ZZZ'* statement
will be used.
For example, if you entered *=ZZZ*,
the statement *ILIKE 'ZZZ'*
will be used.
"""
"""
column_filters
=
None
column_filters
=
None
...
@@ -163,11 +163,11 @@ class ModelView(BaseModelView):
...
@@ -163,11 +163,11 @@ class ModelView(BaseModelView):
"""
"""
If set to `False` and user deletes more than one model using built in action,
If set to `False` and user deletes more than one model using built in action,
all models will be read from the database and then deleted one by one
all models will be read from the database and then deleted one by one
giving SQLAlchemy chance to manually cleanup any dependencies (many-to-many
giving SQLAlchemy
a
chance to manually cleanup any dependencies (many-to-many
relationships, etc).
relationships, etc).
If set to `True`, will run `DELETE` statement which is somewhat faster,
If set to `True`, will run
a
`DELETE` statement which is somewhat faster,
but m
ight
leave corrupted data if you forget to configure `DELETE
but m
ay
leave corrupted data if you forget to configure `DELETE
CASCADE` for your model.
CASCADE` for your model.
"""
"""
...
@@ -195,9 +195,9 @@ class ModelView(BaseModelView):
...
@@ -195,9 +195,9 @@ class ModelView(BaseModelView):
class MyModelView(ModelView):
class MyModelView(ModelView):
inline_models = (MyInlineModelForm(MyInlineModel),)
inline_models = (MyInlineModelForm(MyInlineModel),)
You can customize generated field name by:
You can customize
the
generated field name by:
1. Using
`form_name` property as option
:
1. Using
the `form_name` property as a key to the options dictionary
:
class MyModelView(ModelView):
class MyModelView(ModelView):
inline_models = ((Post, dict(form_label='Hello')))
inline_models = ((Post, dict(form_label='Hello')))
...
@@ -226,15 +226,15 @@ class ModelView(BaseModelView):
...
@@ -226,15 +226,15 @@ class ModelView(BaseModelView):
:param model:
:param model:
Model class
Model class
:param session:
:param session:
SQLA
L
chemy session
SQLA
l
chemy session
:param name:
:param name:
View name. If not set,
will default to
model name
View name. If not set,
defaults to the
model name
:param category:
:param category:
Category name
Category name
:param endpoint:
:param endpoint:
Endpoint name. If not set,
will default to
model name
Endpoint name. If not set,
defaults to the
model name
:param url:
:param url:
Base URL. If not set,
will default
to '/admin/' + endpoint
Base URL. If not set,
defaults
to '/admin/' + endpoint
"""
"""
self
.
session
=
session
self
.
session
=
session
...
@@ -270,19 +270,19 @@ class ModelView(BaseModelView):
...
@@ -270,19 +270,19 @@ class ModelView(BaseModelView):
# Scaffolding
# Scaffolding
def
scaffold_pk
(
self
):
def
scaffold_pk
(
self
):
"""
"""
Return primary key name from a model
Return
the
primary key name from a model
"""
"""
return
tools
.
get_primary_key
(
self
.
model
)
return
tools
.
get_primary_key
(
self
.
model
)
def
get_pk_value
(
self
,
model
):
def
get_pk_value
(
self
,
model
):
"""
"""
Return PK value from a model object.
Return
the
PK value from a model object.
"""
"""
return
getattr
(
model
,
self
.
_primary_key
)
return
getattr
(
model
,
self
.
_primary_key
)
def
scaffold_list_columns
(
self
):
def
scaffold_list_columns
(
self
):
"""
"""
Return list of columns from the model.
Return
a
list of columns from the model.
"""
"""
columns
=
[]
columns
=
[]
...
@@ -307,7 +307,7 @@ class ModelView(BaseModelView):
...
@@ -307,7 +307,7 @@ class ModelView(BaseModelView):
def
scaffold_sortable_columns
(
self
):
def
scaffold_sortable_columns
(
self
):
"""
"""
Return dictionary of sortable columns.
Return
a
dictionary of sortable columns.
Key is column name, value is sort column/field.
Key is column name, value is sort column/field.
"""
"""
columns
=
dict
()
columns
=
dict
()
...
@@ -322,7 +322,7 @@ class ModelView(BaseModelView):
...
@@ -322,7 +322,7 @@ class ModelView(BaseModelView):
column
=
p
.
columns
[
0
]
column
=
p
.
columns
[
0
]
# Can't sort
by on primary and
foreign keys by default
# Can't sort
on primary or
foreign keys by default
if
column
.
foreign_keys
:
if
column
.
foreign_keys
:
continue
continue
...
@@ -383,7 +383,7 @@ class ModelView(BaseModelView):
...
@@ -383,7 +383,7 @@ class ModelView(BaseModelView):
def
is_text_column_type
(
self
,
name
):
def
is_text_column_type
(
self
,
name
):
"""
"""
Verify if column type is text-based.
Verify if
the provided
column type is text-based.
:returns:
:returns:
``True`` for ``String``, ``Unicode``, ``Text``, ``UnicodeText``
``True`` for ``String``, ``Unicode``, ``Text``, ``UnicodeText``
...
@@ -479,7 +479,7 @@ class ModelView(BaseModelView):
...
@@ -479,7 +479,7 @@ class ModelView(BaseModelView):
def
is_valid_filter
(
self
,
filter
):
def
is_valid_filter
(
self
,
filter
):
"""
"""
Verify that provided filter object is derived from the
Verify that
the
provided filter object is derived from the
SQLAlchemy-compatible filter class.
SQLAlchemy-compatible filter class.
:param filter:
:param filter:
...
@@ -522,7 +522,7 @@ class ModelView(BaseModelView):
...
@@ -522,7 +522,7 @@ class ModelView(BaseModelView):
def
scaffold_auto_joins
(
self
):
def
scaffold_auto_joins
(
self
):
"""
"""
Return list of joined tables by going through the
Return
a
list of joined tables by going through the
displayed columns.
displayed columns.
"""
"""
if
not
self
.
column_auto_select_related
:
if
not
self
.
column_auto_select_related
:
...
@@ -669,7 +669,7 @@ class ModelView(BaseModelView):
...
@@ -669,7 +669,7 @@ class ModelView(BaseModelView):
def
get_one
(
self
,
id
):
def
get_one
(
self
,
id
):
"""
"""
Return
on
e model by its id.
Return
a singl
e model by its id.
:param id:
:param id:
Model id
Model id
...
...
flask_admin/tools.py
View file @
d291c236
...
@@ -30,7 +30,7 @@ def import_attribute(name):
...
@@ -30,7 +30,7 @@ def import_attribute(name):
:param name:
:param name:
String reference.
String reference.
Throw
s ImportError or AttributeError if module or attribute do not exist.
Raise
s ImportError or AttributeError if module or attribute do not exist.
Example::
Example::
...
@@ -80,7 +80,7 @@ def rec_getattr(obj, attr, default=None):
...
@@ -80,7 +80,7 @@ def rec_getattr(obj, attr, default=None):
def
get_dict_attr
(
obj
,
attr
,
default
=
None
):
def
get_dict_attr
(
obj
,
attr
,
default
=
None
):
"""
"""
Get attibute of the object without triggering its __getattr__.
Get att
r
ibute of the object without triggering its __getattr__.
:param obj:
:param obj:
Object
Object
...
@@ -98,7 +98,7 @@ def get_dict_attr(obj, attr, default=None):
...
@@ -98,7 +98,7 @@ def get_dict_attr(obj, attr, default=None):
def
get_property
(
obj
,
name
,
old_name
,
default
=
None
):
def
get_property
(
obj
,
name
,
old_name
,
default
=
None
):
"""
"""
Check if old property name exists and if it
i
s - show warning message
Check if old property name exists and if it
doe
s - show warning message
and return value.
and return value.
Otherwise, return new property value
Otherwise, return new property value
...
...
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