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
eeacef04
Commit
eeacef04
authored
Oct 29, 2013
by
Petrus J.v.Rensburg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update 'usage tips' page.
parent
0c8c7ac6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
25 deletions
+28
-25
quickstart.rst
doc/quickstart.rst
+0
-1
tips.rst
doc/tips.rst
+28
-24
No files found.
doc/quickstart.rst
View file @
eeacef04
...
@@ -165,7 +165,6 @@ have access to the view in question::
...
@@ -165,7 +165,6 @@ have access to the view in question::
def is_accessible(self):
def is_accessible(self):
return login.current_user.is_authenticated()
return login.current_user.is_authenticated()
You can also implement policy-based security, conditionally allowing or disallowing access to parts of the
You can also implement policy-based security, conditionally allowing or disallowing access to parts of the
administrative interface. If a user does not have access to a particular view, the menu item won't be visible.
administrative interface. If a user does not have access to a particular view, the menu item won't be visible.
...
...
doc/tips.rst
View file @
eeacef04
...
@@ -4,38 +4,42 @@ Usage Tips
...
@@ -4,38 +4,42 @@ Usage Tips
General tips
General tips
------------
------------
1.
Whenever your administrative views share common functionality such as authentication,
1.
A reasonably obvious, but very useful, pattern is to wrap any shared functionality that your different admin views
form validation, make use of read-only views and so on - create your own base class which
might need into a base class that they can all inherit from (to help you keep things
inherits from proper Flask-Admin view class
.
`DRY <http://en.wikipedia.org/wiki/Don't_repeat_yourself>`_)
.
For example, if you need to check user permissions for every call, don't implement
For example, rather than manually checking user permissions in each of your admin views, you can implement a
`is_accessible` in every administrative view. Create your own base class, implement
base class such as ::
`is_accessible` there and use this class for all your views.
2. You can override used templates either by using `ModelView` properties (such as
class MyView(BaseView):
`list_template`, `create_template`, `edit_template`) or
def is_accessible(self):
putting customized version of the template into your `templates/admin/` directory
return login.current_user.is_authenticated()
3. If you need to customize look and feel of model forms, there are two options:
and every view that inherits from this, will have the permission checking done automatically. The important thing
- Override create/edit template
to notice, is that your base class needs to inherit from a built-in Flask-Admin view.
- Use new :mod:`flask.ext.admin.form.rules` form rendering rules
4. Flask-Admin has that manage file/image uploads and store result in model field. You can
2. You can override a default template either by passing the path to your own template in to the relevant `ModelView`
find documentation here :mod:`flask.ext.admin.form.upload`.
property (either `list_template`, `create_template` or `edit_template`) or by putting your own customized
version of a default template into your `templates/admin/` directory.
5. If you don't want to use Flask-Admin form scaffolding logic, you can override
3. To customize the overall look and feel of the default model forms, you have two options: Either, you could
:meth:`~flask.ext.admin.model.base.scaffold_form` and put your own form creation
override the default create/edit templates. Or, alternatively, you could make use of the form rendering rules
logic there. For example, if you use `WTForms-Alchemy <https://github.com/kvesteri/wtforms-alchemy>`_, all you have to do
(:mod:`flask.ext.admin.form.rules`) that were introduced in version 1.0.7.
is to put appropriate form generation code into your `ModelView` class into the
`scaffold_form` method.
4. To simplify the management of file uploads, Flask-Admin comes with a dedicated tool, for which you can find
documentation at: :mod:`flask.ext.admin.form.upload`.
5. If you don't want to the use the built-in Flask-Admin form scaffolding logic, you are free to roll your own
by simply overriding :meth:`~flask.ext.admin.model.base.scaffold_form`. For example, if you use
`WTForms-Alchemy <https://github.com/kvesteri/wtforms-alchemy>`_, you could put your form generation code
into a `scaffold_form` method in your `ModelView` class.
SQLAlchemy
SQLAlchemy
----------
----------
1. If `synonym_property` does not return SQLAlchemy field, Flask-Admin
1. If the `synonym_property` does not return a SQLAlchemy field, then Flask-Admin won't be able to figure out what to
won't be able to figure out what to do with it and won't generate form
do with it, so it won't generate a form field. In this case, you would need to manually contribute your own field::
field. In this case, you need to manually contribute field::
class MyView(ModelView):
class MyView(ModelView):
def scaffold_form(self):
def scaffold_form(self):
...
@@ -46,5 +50,5 @@ SQLAlchemy
...
@@ -46,5 +50,5 @@ SQLAlchemy
MongoEngine
MongoEngine
-----------
-----------
1. Flask-Admin supports GridFS
backed image and file uploads. Done through
1. Flask-Admin supports GridFS
-backed image- and file uploads, done through WTForms fields. Documentation can be found
WTForms fields and documentation can be found here
:mod:`flask.ext.admin.contrib.mongoengine.fields`.
at
:mod:`flask.ext.admin.contrib.mongoengine.fields`.
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