Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Feb 1, 2015
1 parent 4245c59 commit 6107dc6
Show file tree
Hide file tree
Showing 29 changed files with 177 additions and 105 deletions.
Binary file modified docs/_build/doctrees/advanced.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/api.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/quickcharts.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/quickfiles.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/security.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/versionmigration.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/versions.doctree
Binary file not shown.
Binary file modified docs/_build/html/_images/login_db.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 38 additions & 12 deletions docs/_build/html/_sources/quickfiles.txt
@@ -1,7 +1,8 @@
Model Views with Files and Images
=================================

You can implement views with images or files embedded on the model's definition
You can implement views with images or files embedded on the model's definition. You can do it using SQLAlchemy or
MongoDB (MongoEngine). When using SQLAlchemy, files and images are saved on the filesystem, on MongoDB on the db (GridFS).

Define your model (models.py)
-----------------------------
Expand All @@ -14,22 +15,44 @@ Define your model (models.py)
class Person(Model):
id = Column(Integer, primary_key=True)
name = Column(String(150), unique = True, nullable=False)
photo = Column(ImageColumn, nullable=False )
photo = Column(ImageColumn(size=(300, 300, True), thumbnail_size=(30, 30, True)))

def photo_img(self):
im = ImageManager()
if self.photo:
return Markup('<a href="' + url_for('PersonModelView.show',pk=str(self.id)) + '" class="thumbnail"><img src="' + im.get_url(self.photo) + '" alt="Photo" class="img-rounded img-responsive"></a>')
return Markup('<a href="' + url_for('PersonModelView.show',pk=str(self.id)) +\
'" class="thumbnail"><img src="' + im.get_url(self.photo) +\
'" alt="Photo" class="img-rounded img-responsive"></a>')
else:
return Markup('<a href="' + url_for('PersonModelView.show',pk=str(self.id)) + '" class="thumbnail"><img src="//:0" alt="Photo" class="img-responsive"></a>')

Create an additional method in this case *photo_img*, to inject your own custom HTML, to show your saved images. In this example the customized method is showing the images, and linking them with the show view.
return Markup('<a href="' + url_for('PersonModelView.show',pk=str(self.id)) +\
'" class="thumbnail"><img src="//:0" alt="Photo" class="img-responsive"></a>')

def photo_img_thumbnail(self):
im = ImageManager()
if self.photo:
return Markup('<a href="' + url_for('PersonModelView.show',pk=str(self.id)) +\
'" class="thumbnail"><img src="' + im.get_url_thumbnail(self.photo) +\
'" alt="Photo" class="img-rounded img-responsive"></a>')
else:
return Markup('<a href="' + url_for('PersonModelView.show',pk=str(self.id)) +\
'" class="thumbnail"><img src="//:0" alt="Photo" class="img-responsive"></a>')

Later reference this method like it's a column on your view.

Create two additional methods in this case *photo_img* and *photo_img_thumbnail*, to inject your own custom HTML,
to show your saved images. In this example the customized method is showing the images, and linking them with the show view.
Notice how the methods are calling *get_url* and *get_url_thumbnail* from ImageManager, these are returning the
url for the images, each image is saved on the filesystem using the global config **IMG_UPLOAD_FOLDER**.
Each image will have two files with different sizes, images are saved as <uuid>_sep_<filename>, and <uuid>_sep_<filename>_thumb

.. note::
The "ImageColumn" type, is an extended type from Flask-AppBuilder.

Later reference this method like it's a column on your view.

To implement image or file support using GridFS from MongoDB is even easier, take a look at the example:

https://github.com/dpgaspar/Flask-AppBuilder/tree/master/examples/mongoimages

Define your Views (views.py)
----------------------------

Expand All @@ -43,15 +66,18 @@ Define your Views (views.py)

list_widget = ListThumbnail

label_columns = {'name':'Name','photo':'Photo','photo_img':'Photo'}
list_columns = ['photo_img', 'name']
label_columns = {'name':'Name','photo':'Photo','photo_img':'Photo', 'photo_img_thumbnail':'Photo'}
list_columns = ['photo_img_thumbnail', 'name']
show_columns = ['photo_img','name']

Notice that we are overriding the *list_widget*, the widget that is normally used by ModelView. This will display a thumbnail list, excellent for displaying images.
We are overriding the *list_widget*, the widget that is normally used by ModelView.
This will display a thumbnail list, excellent for displaying images.

We are not using the *image* column but the method *photo_img* we have created. This method will display the image and link it to the show view.
We're not using the *image* column but the methods *photo_img* and *photo_img_thumbnail* we have created.
These methods will display the images and link them to show view.

And that's it! images will be saved on the server. Their file names will result in the concatenation of UUID with their original name. They will be resized for optimization.
And that's it! images will be saved on the server.
Their file names will result in the concatenation of UUID with their original name. They will be resized for optimization.

.. note::
You can define image resizing using configuration key *IMG_SIZE*
Expand Down
22 changes: 6 additions & 16 deletions docs/_build/html/_sources/versionmigration.txt
Expand Up @@ -6,36 +6,26 @@ Migrating from 1.2.X to 1.3.X

There are some breaking features:

1 - Security models have changed, user's can have multiple roles, not just one. So you have to migrate you db.
1 - Security models have changed, user's can have multiple roles, not just one. So you have to upgrade your db.

- The security models schema have changed.

If you are using sqlite, mysql or pgsql, use the following procedure:
If you are using sqlite, mysql, pgsql, mssql or oracle, use the following procedure:

1 - *Backup your DB*.

2 - If you haven't already, upgrade to flask-appbuilder 1.3.0.

3 - Issue the following commands, on your project folder where config.py exists::

cd /your-main-project-folder/
wget https://raw.github.com/dpgaspar/Flask-AppBuilder/master/bin/migrate_db_1.3.py
python migrate_db_1.3.py
$ cd /your-main-project-folder/
$ fabmanager upgrade-db

4 - Test and Run (if you have a run.py for development) ::

$ fabmanager run

python run.py

If not (DB is not sqlite, mysql or pgsql), you will have to alter the schema your self. use the following procedure:

1 - *Backup your DB*.

2 - If you haven't already, upgrade to flask-appbuilder 0.7.0.

3 - issue the corresponding DDL commands to:

ALTER TABLE ab_user MODIFY COLUMN password VARCHAR(256)
For **sqlite** you'll have to drop role_id columns and FK yourself. follow the script instructions to finish the upgrade.


2 - Security. If you were already extending security, this is even more encouraged from now on, but internally many things have
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/_sources/versions.txt
Expand Up @@ -22,10 +22,10 @@ Improvements and Bug fixes on 1.3.0
- New, support for many to many relations on ModelView related_view.
- New, AppBuilder.add_link supports endpoint names on href parameter, internally will try to use url_for(href).
- Fix, Zero division catch on aggregate average function.
- New, added form validators for field min and max length.
- New, Image size can be configured per column, ImageColumn support size and thumbnail size parameters.
- (TODO) - fabmanager create-app para SQLA e MongoDB com diferentes esqueletos.
- (TODO) - fabmanager support for factory apps.
- (TODO) - DOCS (Security, custom, templates).
- (TODO) - criar exemplo de utilização de base_template.

Improvements and Bug fixes on 1.2.1
-----------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/api.html
Expand Up @@ -1933,8 +1933,8 @@ <h3>Extra Columns<a class="headerlink" href="#extra-columns" title="Permalink to

<dl class="class">
<dt id="flask.ext.appbuilder.models.mixins.ImageColumn">
<em class="property">class </em><tt class="descclassname">flask.ext.appbuilder.models.mixins.</tt><tt class="descname">ImageColumn</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#flask.ext.appbuilder.models.mixins.ImageColumn" title="Permalink to this definition"></a></dt>
<dd><p>Extends SQLAlchemy to support and mostly identify a Image Column</p>
<em class="property">class </em><tt class="descclassname">flask.ext.appbuilder.models.mixins.</tt><tt class="descname">ImageColumn</tt><big>(</big><em>thumbnail_size=(20</em>, <em>20</em>, <em>True)</em>, <em>size=(100</em>, <em>100</em>, <em>True)</em>, <em>**kw</em><big>)</big><a class="headerlink" href="#flask.ext.appbuilder.models.mixins.ImageColumn" title="Permalink to this definition"></a></dt>
<dd><p>Extends SQLAlchemy to support and mostly identify an Image Column</p>
<dl class="attribute">
<dt id="flask.ext.appbuilder.models.mixins.ImageColumn.impl">
<tt class="descname">impl</tt><a class="headerlink" href="#flask.ext.appbuilder.models.mixins.ImageColumn.impl" title="Permalink to this definition"></a></dt>
Expand Down
Binary file modified docs/_build/html/objects.inv
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/_build/html/py-modindex.html
Expand Up @@ -89,7 +89,7 @@ <h1>Python Module Index</h1>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="api.html#module-flask.ext.appbuilder.baseviews"><tt class="xref">flask.ext.appbuilder.baseviews</tt></a></td><td>
<a href="views.html#module-flask.ext.appbuilder.baseviews"><tt class="xref">flask.ext.appbuilder.baseviews</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
Expand Down Expand Up @@ -119,7 +119,7 @@ <h1>Python Module Index</h1>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="api.html#module-flask.ext.appbuilder.security.decorators"><tt class="xref">flask.ext.appbuilder.security.decorators</tt></a></td><td>
<a href="views.html#module-flask.ext.appbuilder.security.decorators"><tt class="xref">flask.ext.appbuilder.security.decorators</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
Expand Down

0 comments on commit 6107dc6

Please sign in to comment.