diff --git a/oshipka/persistance/__init__.py b/oshipka/persistance/__init__.py
index 956570f..63b5191 100644
--- a/oshipka/persistance/__init__.py
+++ b/oshipka/persistance/__init__.py
@@ -331,6 +331,7 @@ SENSITIVE_PREFIX = "__SENSITIVE__."
def populate_static(app):
+ print("populating...")
static_media_dir = os.path.join(STATIC_DATA_DIR, "media")
if os.path.exists(static_media_dir):
dir_util.copy_tree(static_media_dir, MEDIA_DIR)
@@ -368,6 +369,7 @@ def populate_static(app):
instance = create_model(model, row)
db.session.add(instance)
db.session.commit()
+ print("Finished populating")
def filter_m_n(serialized_args):
diff --git a/oshipka/webapp/views.py b/oshipka/webapp/views.py
index 206e381..a76da8b 100644
--- a/oshipka/webapp/views.py
+++ b/oshipka/webapp/views.py
@@ -80,7 +80,13 @@ def default_list_args_get_func(vc):
def default_list_func(vc):
- vc.instances = vc.model_view.model.query.all()
+ per_page = request.args.get('per_page')
+ order_by = request.args.get('order_by')
+ order_by_dir = request.args.get('order_by_dir')
+ # .order_by(getattr(vc.model_view.model, order_by).desc())
+ pagination = vc.model_view.model.query.paginate(per_page=per_page, error_out=False)
+ vc.template_ctx['pagination'] = pagination
+ vc.instances = pagination.items
def get_filters(serialized_args):
@@ -93,7 +99,10 @@ def default_search_func(vc):
query = vc.model_view.model.search_query("*{q}*".format(q=q))
filters = get_filters(vc.serialized_args)
filtered_query = apply_filters(query, filters)
- vc.instances = filtered_query.all()
+ per_page = request.args.get('per_page')
+ pagination = filtered_query.paginate(per_page=per_page, error_out=False)
+ vc.template_ctx['pagination'] = pagination
+ vc.instances = pagination.items
def default_update_func(vc):
diff --git a/vm_gen/templates/html/_list.html b/vm_gen/templates/html/_list.html
index 5dd71eb..0df4d5e 100644
--- a/vm_gen/templates/html/_list.html
+++ b/vm_gen/templates/html/_list.html
@@ -1,3 +1,6 @@
{% for instance in instances %}
{% include "[[ name|camel_to_snake ]]/_list_item.html" %}
-{% endfor %}
\ No newline at end of file
+{% endfor %}
+
+{% import "_macros.html" as m %}
+{{ m.render_pagination(pagination, 'list_[[ name|camel_to_snake ]]') }}
\ No newline at end of file
diff --git a/vm_gen/templates/html/_table.html b/vm_gen/templates/html/_table.html
index 78f06d6..de84dd8 100644
--- a/vm_gen/templates/html/_table.html
+++ b/vm_gen/templates/html/_table.html
@@ -28,7 +28,7 @@
{% endif %}
[%- endfor %]