Commit b6bcae27 authored by Petrus J.v.Rensburg's avatar Petrus J.v.Rensburg

Cut some duplicate content from 'advanced features' page.

parent ad7f4e2a
...@@ -10,6 +10,8 @@ As an alternative to passing a Flask application object to the Admin constructor ...@@ -10,6 +10,8 @@ As an alternative to passing a Flask application object to the Admin constructor
# Add views here # Add views here
admin.init_app(app) admin.init_app(app)
****
Localization with Flask-Babelex Localization with Flask-Babelex
------------------------------------------ ------------------------------------------
Enabling localization is relatively simple. Enabling localization is relatively simple.
...@@ -47,12 +49,16 @@ Enabling localization is relatively simple. ...@@ -47,12 +49,16 @@ Enabling localization is relatively simple.
If the builtin translations are not enough, look at the `Flask-BabelEx documentation <https://pythonhosted.org/Flask-BabelEx/>`_ If the builtin translations are not enough, look at the `Flask-BabelEx documentation <https://pythonhosted.org/Flask-BabelEx/>`_
to see how you can add your own. to see how you can add your own.
****
Handling Foreign Key relations inline Handling Foreign Key relations inline
-------------------------------------------- --------------------------------------------
Many-to-many relations Many-to-many relations
---------------------------------- ----------------------------------
****
.. _file-admin: .. _file-admin:
Managing Files & Folders Managing Files & Folders
...@@ -83,6 +89,8 @@ Sample screenshot: ...@@ -83,6 +89,8 @@ Sample screenshot:
You can disable uploads, disable file or directory deletion, restrict file uploads to certain types and so on. You can disable uploads, disable file or directory deletion, restrict file uploads to certain types and so on.
Check :mod:`flask_admin.contrib.fileadmin` documentation on how to do it. Check :mod:`flask_admin.contrib.fileadmin` documentation on how to do it.
****
Managing geographical models Managing geographical models
-------------------------------------- --------------------------------------
...@@ -165,6 +173,7 @@ If you have any ideas or suggestions, make a pull request! ...@@ -165,6 +173,7 @@ If you have any ideas or suggestions, make a pull request!
.. _GeoJSON: http://geojson.org/ .. _GeoJSON: http://geojson.org/
.. _Geometry: http://geoalchemy-2.readthedocs.org/en/latest/types.html#geoalchemy2.types.Geometry .. _Geometry: http://geoalchemy-2.readthedocs.org/en/latest/types.html#geoalchemy2.types.Geometry
****
Customising builtin forms via form rendering rules Customising builtin forms via form rendering rules
-------------------------------------------------------- --------------------------------------------------------
...@@ -224,6 +233,8 @@ Form Rendering Rule Description ...@@ -224,6 +233,8 @@ Form Rendering Rule Description
:class:`flask_admin.form.rules.FieldSet` Renders form header and child rules :class:`flask_admin.form.rules.FieldSet` Renders form header and child rules
======================================================= ======================================================== ======================================================= ========================================================
****
Enabling CSRF Validation Enabling CSRF Validation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Adding CSRF validation will require overriding the :class:`flask_admin.form.BaseForm` by using :attr:`flask_admin.model.BaseModelView.form_base_class`. Adding CSRF validation will require overriding the :class:`flask_admin.form.BaseForm` by using :attr:`flask_admin.model.BaseModelView.form_base_class`.
...@@ -287,11 +298,7 @@ For WTForms 1, you can use use Flask-WTF's Form class:: ...@@ -287,11 +298,7 @@ For WTForms 1, you can use use Flask-WTF's Form class::
app.run(debug=True) app.run(debug=True)
Further reading ****
^^^^^^^^^^^^^^^
For additional documentation, check :mod:`flask_admin.form.rules` module source code (it is quite short) and
look at the `forms example <https://github.com/flask-admin/flask-admin/tree/master/examples/forms>`_ on GitHub.
Using different database backends Using different database backends
---------------------------------------- ----------------------------------------
...@@ -328,33 +335,7 @@ are dedicated to helping you through this process. See :doc:`model_guidelines`. ...@@ -328,33 +335,7 @@ are dedicated to helping you through this process. See :doc:`model_guidelines`.
.. _MongoEngine: http://mongoengine.org/ .. _MongoEngine: http://mongoengine.org/
.. _MongoDB: http://www.mongodb.org/ .. _MongoDB: http://www.mongodb.org/
****
Implementing your own authentication
----------------------------------------------------
Flask-Admin does not make any assumptions about the authentication system you might be using. So, by default, the admin
interface is completely open.
To control access to the admin interface, you can specify an *is_accessible* method when extending the *BaseView* class.
So, for example, if you are using Flask-Login for authentication, the following will ensure that only logged-in users
have access to the view in question::
class MyView(BaseView):
def is_accessible(self):
return login.current_user.is_authenticated()
To redirect the user to another page if authentication fails, you will need to specify an *_handle_view* method::
class MyView(BaseView):
def is_accessible(self):
return login.current_user.is_authenticated()
def _handle_view(self, name, **kwargs):
if not self.is_accessible():
return redirect(url_for('login', next=request.url))
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.
Migrating from Django Migrating from Django
------------------------- -------------------------
......
...@@ -121,6 +121,10 @@ could be as simple as:: ...@@ -121,6 +121,10 @@ could be as simple as::
def is_accessible(self): def is_accessible(self):
return login.current_user.is_authenticated() return login.current_user.is_authenticated()
def _handle_view(self, name, **kwargs):
if not self.is_accessible():
return redirect(url_for('login', next=request.url))
Components that are not accessible to a particular user, will also not be displayed Components that are not accessible to a particular user, will also not be displayed
in the menu for that user. But, you would still need to implement all of the relevant login, in the menu for that user. But, you would still need to implement all of the relevant login,
registration and account management views yourself. registration and account management views yourself.
...@@ -693,7 +697,9 @@ Further Reading ...@@ -693,7 +697,9 @@ Further Reading
:maxdepth: 2 :maxdepth: 2
advanced advanced
adding_a_new_model_backend
api/index api/index
changelog
**** ****
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment