diff options
Diffstat (limited to 'cli/app/controllers')
| -rw-r--r-- | cli/app/controllers/crud_controller.py | 3 | ||||
| -rw-r--r-- | cli/app/controllers/page_controller.py | 6 | ||||
| -rw-r--r-- | cli/app/controllers/tile_controller.py | 9 |
3 files changed, 18 insertions, 0 deletions
diff --git a/cli/app/controllers/crud_controller.py b/cli/app/controllers/crud_controller.py index 28b2a25..7692d26 100644 --- a/cli/app/controllers/crud_controller.py +++ b/cli/app/controllers/crud_controller.py @@ -13,6 +13,8 @@ class CrudView(FlaskView): excluded_methods = ['on_index', 'on_show', 'on_create', 'on_update', 'on_destroy'] # implement these methods: + def where(self, query, args): + return query def on_index(self, session, data): return data def on_show(self, session, data): @@ -35,6 +37,7 @@ class CrudView(FlaskView): offset, limit = parse_search_args(request.args) sort, order, order_by, order_by_id = parse_sort_args(request.args, self.model) query = session.query(self.model) + query = self.where(query, request.args) if order_by_id is not None: query = query.order_by(order_by, order_by_id) else: diff --git a/cli/app/controllers/page_controller.py b/cli/app/controllers/page_controller.py index 5263cf0..d393625 100644 --- a/cli/app/controllers/page_controller.py +++ b/cli/app/controllers/page_controller.py @@ -11,5 +11,11 @@ class PageView(CrudView): model = Page form = PageForm + def where(self, query, args): + graph_id = args.get('graph_id', default=None) + if graph_id is not None: + query = query.where(Page.graph_id == int(graph_id)) + return query + def on_destroy(self, session, item): session.query(Tile).filter(Tile.page_id == item.id).delete(synchronize_session=False) diff --git a/cli/app/controllers/tile_controller.py b/cli/app/controllers/tile_controller.py index c47237b..fc36943 100644 --- a/cli/app/controllers/tile_controller.py +++ b/cli/app/controllers/tile_controller.py @@ -9,3 +9,12 @@ from app.controllers.crud_controller import CrudView class TileView(CrudView): model = Tile form = TileForm + + def where(self, query, args): + graph_id = args.get('graph_id', default=None) + if graph_id is not None: + query = query.where(Tile.graph_id == int(graph_id)) + page_id = args.get('page_id', default=None) + if page_id is not None: + query = query.where(Tile.page_id == int(page_id)) + return query |
