diff --git a/app/blueprints/admin.py b/app/blueprints/admin.py index 1d62d39..bbbd790 100644 --- a/app/blueprints/admin.py +++ b/app/blueprints/admin.py @@ -697,17 +697,18 @@ def record_list(): subquery = base_stmt.subquery() count_stmt = select(func.count()).select_from(subquery) total = session.execute(count_stmt).scalar() + per_page = 50 # order & limit stmt = stmt.order_by(desc(Record.id)) if current_page > 1: - stmt = stmt.offset((current_page-1) * 20) - stmt = stmt.limit(20) + stmt = stmt.offset((current_page-1) * per_page) + stmt = stmt.limit(per_page) result = session.execute(stmt) rows = result.all() # print(stmt, '==', flush=True) - last_page = math.ceil(total / 20) + last_page = math.ceil(total / per_page) pagination = { 'current_page': current_page, 'last_page': last_page, @@ -999,6 +1000,7 @@ def __init__(self, register): self.template = 'admin/list-view.html' def dispatch_request(self): + # login_requried if not current_user.is_authenticated: return redirect('/login') @@ -1016,7 +1018,7 @@ def dispatch_request(self): #print(query, flush=True) if list_filter := self.register.get('list_filter'): - if q := request.args.get('q'): + if q := request.args.get('q'): many_or = or_() for x in list_filter: attr = getattr(self.register['model'], x) @@ -1031,9 +1033,11 @@ def dispatch_request(self): elif field := collection_filter.get('field'): query = query.filter(field==int(collection_id)) - items = query.all() - return render_template(self.template, items=items, register=self.register) + total = query.count() + items = query.limit(50).all() + + return render_template(self.template, items=items, register=self.register, total=total) class FormView(View): diff --git a/app/blueprints/admin_register.py b/app/blueprints/admin_register.py index 3e53be3..a159915 100644 --- a/app/blueprints/admin_register.py +++ b/app/blueprints/admin_register.py @@ -135,7 +135,8 @@ 'list_display': ('full_name', 'full_name_en', 'is_collector', 'is_identifier',), 'list_collection_filter': { 'related': Collection.people, - } + }, + 'list_filter': ('full_name', 'full_name_en'), }, 'taxon': { 'name': 'taxon', diff --git a/app/templates/admin/list-view.html b/app/templates/admin/list-view.html index 8a3270e..4ae0142 100644 --- a/app/templates/admin/list-view.html +++ b/app/templates/admin/list-view.html @@ -8,6 +8,19 @@ +{% if register.query %} +
Results: {{ "{:,}".format(total) }}
+