Commit 823ba4f3 authored by Paul Brown's avatar Paul Brown

corrections to docs after proofreading

parent 0b31e803
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Advanced Functionality Advanced Functionality
====================== ======================
Enabling CSRF Validation Enabling CSRF Protection
------------------------ ------------------------
To add CSRF protection to the forms that are generated by *ModelView* instances, use the To add CSRF protection to the forms that are generated by *ModelView* instances, use the
...@@ -16,14 +16,14 @@ SecureForm class in your *ModelView* subclass by specifying the *form_base_class ...@@ -16,14 +16,14 @@ SecureForm class in your *ModelView* subclass by specifying the *form_base_class
form_base_class = SecureForm form_base_class = SecureForm
SecureForm requires WTForms 2 or greater. It uses the WTForms SessionCSRF class SecureForm requires WTForms 2 or greater. It uses the WTForms SessionCSRF class
to generate the tokens for you, and validate them when the forms are submitted. to generate and validate the tokens for you when the forms are submitted.
Localization With Flask-Babelex Localization With Flask-Babelex
------------------------------- -------------------------------
**** ****
Flask-Admin comes with translations built-in for several languages. Flask-Admin comes with translations for several languages.
Enabling localization is simple: Enabling localization is simple:
#. Install `Flask-BabelEx <http://github.com/mrjoes/flask-babelex/>`_ to do the heavy #. Install `Flask-BabelEx <http://github.com/mrjoes/flask-babelex/>`_ to do the heavy
...@@ -48,13 +48,13 @@ Enabling localization is simple: ...@@ -48,13 +48,13 @@ Enabling localization is simple:
session['lang'] = request.args.get('lang') session['lang'] = request.args.get('lang')
return session.get('lang', 'en') return session.get('lang', 'en')
Now, you could try out a French version of the application at: `http://localhost:5000/admin/?lang=fr <http://localhost:5000/admin/?lang=fr>`_. Now, you could try a French version of the application at: `http://localhost:5000/admin/?lang=fr <http://localhost:5000/admin/?lang=fr>`_.
Go ahead and add your own logic to the locale selector function. The application could store locale in Go ahead and add your own logic to the locale selector function. The application can store locale in
a user profile, cookie, session, etc. And it could interrogate the `Accept-Language` a user profile, cookie, session, etc. It can also use the `Accept-Language`
header for making the selection automatically. header to make the selection automatically.
If the builtin translations are not enough, look at the `Flask-BabelEx documentation <https://pythonhosted.org/Flask-BabelEx/>`_ If the built-in 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.
.. _file-admin: .. _file-admin:
...@@ -64,8 +64,8 @@ Managing Files & Folders ...@@ -64,8 +64,8 @@ Managing Files & Folders
**** ****
To manage static files, that are not tied to your db model, Flask-Admin comes with To manage static files instead of database records, Flask-Admin comes with
the FileAdmin plugin. It gives you the ability to upload, delete, rename, etc. You the FileAdmin plug-in. It gives you the ability to upload, delete, rename, etc. You
can use it by adding a FileAdmin view to your app:: can use it by adding a FileAdmin view to your app::
from flask_admin.contrib.fileadmin import FileAdmin from flask_admin.contrib.fileadmin import FileAdmin
...@@ -87,7 +87,7 @@ Adding A Redis Console ...@@ -87,7 +87,7 @@ Adding A Redis Console
**** ****
Another plugin that's available, is the Redis Console. If you have a Redis Another plug-in that's available is the Redis Console. If you have a Redis
instance running on the same machine as your app, you can:: instance running on the same machine as your app, you can::
from redis import Redis from redis import Redis
...@@ -113,7 +113,7 @@ file / image uploads that need to be tied to a field in your model. ...@@ -113,7 +113,7 @@ file / image uploads that need to be tied to a field in your model.
WYSIWIG Text Fields WYSIWIG Text Fields
******************* *******************
To handle complicated text content, you can use To handle complicated text content, you can use
`CKEditor <http://ckeditor.com/>`_ by subclassing some of the builtin WTForms `CKEditor <http://ckeditor.com/>`_ by subclassing some of the built-in WTForms
classes as follows:: classes as follows::
from wtforms import TextAreaField from wtforms import TextAreaField
...@@ -151,20 +151,19 @@ functionality by including the necessary CKEditor javascript on the `create` and ...@@ -151,20 +151,19 @@ functionality by including the necessary CKEditor javascript on the `create` and
File & Image Fields File & Image Fields
******************* *******************
Flask-Admin comes with a builtin :meth:`~flask_admin.form.upload.FileUploadField` Flask-Admin comes with a built-in :meth:`~flask_admin.form.upload.FileUploadField`
and :meth:`~flask_admin.form.upload.ImageUploadField`. To make use and :meth:`~flask_admin.form.upload.ImageUploadField`. To make use
of them, you'll need to specify an upload directory, and add them to the forms in question. of them, you'll need to specify an upload directory and add them to the forms in question.
Image handling also requires you to have `Pillow <https://pypi.python.org/pypi/Pillow/2.8.2>`_ Image handling also requires you to have `Pillow <https://pypi.python.org/pypi/Pillow/2.8.2>`_
installed if you need to do any processing on the image files. installed if you need to do any processing on the image files.
Have a look at the example at Have a look at the example at
https://github.com/flask-admin/Flask-Admin/tree/master/examples/forms. https://github.com/flask-admin/Flask-Admin/tree/master/examples/forms.
If you are using the MongoEngine backend, Flask-Admin supports GridFS-backed image- and file uploads, done through WTForms fields. Documentation can be found If you are using the MongoEngine backend, Flask-Admin supports GridFS-backed image and file uploads through WTForms fields. Documentation can be found at :mod:`flask_admin.contrib.mongoengine.fields`.
at :mod:`flask_admin.contrib.mongoengine.fields`.
If you just want to manage static files in a directory, without tying them to a database model, then If you just want to manage static files in a directory, without tying them to a database model, then
rather use the handy :ref:`File-Admin<file-admin>` plugin. use the :ref:`File-Admin<file-admin>` plug-in.
Managing Geographical Models Managing Geographical Models
---------------------------- ----------------------------
...@@ -172,8 +171,7 @@ Managing Geographical Models ...@@ -172,8 +171,7 @@ Managing Geographical Models
**** ****
If you want to store spatial information in a GIS database, Flask-Admin has If you want to store spatial information in a GIS database, Flask-Admin has
you covered. The GeoAlchemy backend you covered. The GeoAlchemy backend extends the SQLAlchemy backend (just as
extends the SQLAlchemy backend (just as
`GeoAlchemy <http://geoalchemy-2.readthedocs.org/>`_ extends SQLAlchemy) to give you a pretty and functional map-based `GeoAlchemy <http://geoalchemy-2.readthedocs.org/>`_ extends SQLAlchemy) to give you a pretty and functional map-based
editor for your admin pages. editor for your admin pages.
...@@ -188,7 +186,7 @@ Some notable features include: ...@@ -188,7 +186,7 @@ Some notable features include:
- Works with a `Geometry <http://geoalchemy-2.readthedocs.org/en/latest/types.html#geoalchemy2.types.Geometry>`_ SQL field that is integrated with `Shapely <http://toblerity.org/shapely/>`_ objects. - Works with a `Geometry <http://geoalchemy-2.readthedocs.org/en/latest/types.html#geoalchemy2.types.Geometry>`_ SQL field that is integrated with `Shapely <http://toblerity.org/shapely/>`_ objects.
To get started, define some fields on your model using GeoAlchemy's *Geometry* To get started, define some fields on your model using GeoAlchemy's *Geometry*
field. An then, add model views to your interface using the ModelView class field. Next, add model views to your interface using the ModelView class
from the GeoAlchemy backend, rather than the usual SQLAlchemy backend:: from the GeoAlchemy backend, rather than the usual SQLAlchemy backend::
from geoalchemy2 import Geometry from geoalchemy2 import Geometry
...@@ -242,12 +240,12 @@ them one by one. This works well, but it is difficult to customize. ...@@ -242,12 +240,12 @@ them one by one. This works well, but it is difficult to customize.
Starting from version 1.0.7, Flask-Admin supports form rendering rules, to give you fine grained control of how Starting from version 1.0.7, Flask-Admin supports form rendering rules, to give you fine grained control of how
the forms for your modules should be displayed. the forms for your modules should be displayed.
The basic idea is pretty simple: the customizable rendering rules replace a static macro, so that you can tell The basic idea is pretty simple: the customizable rendering rules replace a static macro, so you can tell
Flask-Admin how each form should be rendered. As an extension, however, the rendering rules also let you do a Flask-Admin how each form should be rendered. As an extension, however, the rendering rules also let you do a
bit more: You can use them to output HTML, call Jinja2 macros, render fields and so on. bit more: You can use them to output HTML, call Jinja2 macros, render fields, and so on.
Essentially, form rendering rules abstract the rendering, so that it becomes separate from the form definition. So, Essentially, form rendering rules separate the form rendering from the form definition.
for example, it no longer matters in which sequence your form fields are defined. For example, it no longer matters in which sequence your form fields are defined.
To start using the form rendering rules, put a list of form field names into the `form_create_rules` To start using the form rendering rules, put a list of form field names into the `form_create_rules`
property one of your admin views:: property one of your admin views::
...@@ -260,7 +258,7 @@ In this example, only three fields will be rendered and `email` field will be ab ...@@ -260,7 +258,7 @@ In this example, only three fields will be rendered and `email` field will be ab
Whenever Flask-Admin sees a string value in `form_create_rules`, it automatically assumes that it is a Whenever Flask-Admin sees a string value in `form_create_rules`, it automatically assumes that it is a
form field reference and creates a :class:`flask_admin.form.rules.Field` class instance for that field. form field reference and creates a :class:`flask_admin.form.rules.Field` class instance for that field.
Lets say we want to display some text between the `email` and `first_name` fields. This can be accomplished by Let's say we want to display some text between the `email` and `first_name` fields. This can be accomplished by
using the :class:`flask_admin.form.rules.Text` class:: using the :class:`flask_admin.form.rules.Text` class::
from flask_admin.form import rules from flask_admin.form import rules
...@@ -320,7 +318,7 @@ Flask-Admin has limited support for models with multiple primary keys. It only c ...@@ -320,7 +318,7 @@ Flask-Admin has limited support for models with multiple primary keys. It only c
all but one primary keys are foreign keys to another model. For example, model inheritance following all but one primary keys are foreign keys to another model. For example, model inheritance following
this convention. this convention.
Lets Model a car with its tyres:: Let's Model a car with its tyres::
class Car(db.Model): class Car(db.Model):
__tablename__ = 'cars' __tablename__ = 'cars'
...@@ -488,7 +486,7 @@ backends) and specific backend documentation, for example ...@@ -488,7 +486,7 @@ backends) and specific backend documentation, for example
:class:`~flask_admin.contrib.sqla.ModelView`. There's much more :class:`~flask_admin.contrib.sqla.ModelView`. There's much more
than what is displayed in this table. than what is displayed in this table.
Overriding The Form Scaffolding Overriding the Form Scaffolding
------------------------------- -------------------------------
**** ****
......
This diff is collapsed.
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