Skip to content

Commit

Permalink
docs: migrate examples/quickhowto3 to version 3.x.x (dpgaspar#1488)
Browse files Browse the repository at this point in the history
Co-authored-by: LHDuma <luiz.duma@gmail.com>
Co-authored-by: Daniel Vaz Gaspar <danielvazgaspar@gmail.com>
  • Loading branch information
3 people authored Oct 22, 2020
1 parent c83cf29 commit 25b77d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
15 changes: 15 additions & 0 deletions examples/quickhowto3/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Quick How to Example #3
--------------------===

Simple contacts application.

Insert test data::

$ python testdata.py

Run it::

$ export FLASK_APP=app/__init__.py
$ flask fab create-admin
$ flask run

2 changes: 1 addition & 1 deletion examples/quickhowto3/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask import Flask
from flask_appbuilder import AppBuilder
from flask_sqlalchemy import SQLAlchemy
from flask_appbuilder.models import SQLA
from flask_appbuilder import SQLA
from sqlalchemy import event

logging.basicConfig(format="%(asctime)s:%(levelname)s:%(name)s:%(message)s")
Expand Down
27 changes: 13 additions & 14 deletions examples/quickhowto3/app/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_appbuilder import GeneralView
from flask_appbuilder.models.datamodel import SQLAModel
from flask_appbuilder import ModelView
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.charts.views import ChartView, TimeChartView
from flask_babel import lazy_gettext as _

Expand All @@ -16,8 +16,8 @@ def fill_gender():
session.rollback()


class ContactGeneralView(GeneralView):
datamodel = SQLAModel(Contact)
class ContactModelView(ModelView):
datamodel = SQLAInterface(Contact)

label_columns = {"group": "Contacts Group"}
list_columns = ["name", "personal_celphone", "birthday", "group"]
Expand Down Expand Up @@ -75,22 +75,21 @@ class ContactGeneralView(GeneralView):

class ContactChartView(ChartView):
chart_title = "Grouped contacts"
label_columns = ContactGeneralView.label_columns
label_columns = ContactModelView.label_columns
group_by_columns = ["group", "gender"]
datamodel = SQLAModel(Contact)
datamodel = SQLAInterface(Contact)


class ContactTimeChartView(TimeChartView):
chart_title = "Grouped Birth contacts"
chart_type = "AreaChart"
label_columns = ContactGeneralView.label_columns
label_columns = ContactModelView.label_columns
group_by_columns = ["birthday"]
datamodel = SQLAModel(Contact)
datamodel = SQLAInterface(Contact)


class GroupGeneralView(GeneralView):
datamodel = SQLAModel(Group)
related_views = [ContactGeneralView]
class GroupModelView(ModelView):
datamodel = SQLAInterface(Group)
related_views = [ContactModelView]


fixed_translations_import = [
Expand All @@ -103,14 +102,14 @@ class GroupGeneralView(GeneralView):

fill_gender()
appbuilder.add_view(
GroupGeneralView,
GroupModelView,
"List Groups",
icon="fa-folder-open-o",
category="Contacts",
category_icon="fa-envelope",
)
appbuilder.add_view(
ContactGeneralView, "List Contacts", icon="fa-envelope", category="Contacts"
ContactModelView, "List Contacts", icon="fa-envelope", category="Contacts"
)
appbuilder.add_separator("Contacts")
appbuilder.add_view(
Expand Down

0 comments on commit 25b77d6

Please sign in to comment.