summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/app/controllers/crud_controller.py3
-rw-r--r--cli/app/controllers/page_controller.py6
-rw-r--r--cli/app/controllers/tile_controller.py9
-rw-r--r--cli/app/sql/models/graph.py8
-rw-r--r--cli/app/sql/models/page.py7
-rw-r--r--cli/app/sql/models/tile.py8
6 files changed, 40 insertions, 1 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
diff --git a/cli/app/sql/models/graph.py b/cli/app/sql/models/graph.py
index 59d55c8..ef5a817 100644
--- a/cli/app/sql/models/graph.py
+++ b/cli/app/sql/models/graph.py
@@ -5,7 +5,6 @@ from wtforms_alchemy import ModelForm
from app.sql.common import db, Base, Session
-from app.utils.file_utils import sha256_tree
from app.settings import app_cfg
from os.path import join
@@ -33,3 +32,10 @@ class Graph(Base):
'created_at': self.created_at,
'updated_at': self.updated_at,
}
+
+class GraphForm(ModelForm):
+ class Meta:
+ model = Graph
+ exclude = ['settings', 'created_at', 'updated_at']
+ def get_session():
+ return Session()
diff --git a/cli/app/sql/models/page.py b/cli/app/sql/models/page.py
index 09470b5..1362bb3 100644
--- a/cli/app/sql/models/page.py
+++ b/cli/app/sql/models/page.py
@@ -32,3 +32,10 @@ class Page(Base):
'created_at': self.created_at,
'updated_at': self.updated_at,
}
+
+class PageForm(ModelForm):
+ class Meta:
+ model = Page
+ exclude = ['graph_id', 'settings', 'created_at', 'updated_at']
+ def get_session():
+ return Session()
diff --git a/cli/app/sql/models/tile.py b/cli/app/sql/models/tile.py
index 7ca311d..01b3fab 100644
--- a/cli/app/sql/models/tile.py
+++ b/cli/app/sql/models/tile.py
@@ -33,3 +33,11 @@ class Tile(Base):
'created_at': self.created_at,
'updated_at': self.updated_at,
}
+
+
+class TileForm(ModelForm):
+ class Meta:
+ model = Tile
+ exclude = ['graph_id', 'page_id', 'target_page_id', 'settings', 'created_at', 'updated_at']
+ def get_session():
+ return Session()