diff options
author | Frederick Muriuki Muriithi | 2025-06-12 15:27:53 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-06-12 15:27:53 -0500 |
commit | 9975c4542178071b5b15c6f2401a48fd10a1a2ff (patch) | |
tree | 230019acb4164f97acd4df5bf9b3e46b9a95c601 /uploader/publications/views.py | |
parent | cb5b92aa693235afb7fe160fea4721c059b5395b (diff) | |
download | gn-uploader-9975c4542178071b5b15c6f2401a48fd10a1a2ff.tar.gz |
Improve publication fetching for datatables.
Diffstat (limited to 'uploader/publications/views.py')
-rw-r--r-- | uploader/publications/views.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/uploader/publications/views.py b/uploader/publications/views.py index 8a65ff2..137052b 100644 --- a/uploader/publications/views.py +++ b/uploader/publications/views.py @@ -15,11 +15,12 @@ from flask import ( from uploader.authorisation import require_login from .models import ( - fetch_publications, fetch_publication_by_id, create_new_publications, fetch_publication_phenotypes) +from .datatables import fetch_publications + from gn_libs.debug import __pk__ pubbp = Blueprint("publications", __name__) @@ -44,23 +45,16 @@ def list_publications(): _search = request.args["search[value]"] with (database_connection(app.config["SQL_URI"]) as conn, conn.cursor(cursorclass=DictCursor) as cursor): - cursor.execute("SELECT COUNT(*) FROM Publication") - _totalrows = int(cursor.fetchone()["COUNT(*)"]) - _publications = tuple({ - **row, "index": idx - } for idx,row in enumerate( - fetch_publications( - conn, - _search, - offset=_length * (_page-1), - limit=_length), - start=(_start + 1))) + _publications, _current_rows, _totalfiltered, _totalrows = fetch_publications( + conn, + _search, + offset=_start, + limit=_length) return json.dumps({ "draw": _page, "recordsTotal": _totalrows, - "recordsFiltered": ( - len(_publications) if bool(_search) else _totalrows), + "recordsFiltered": _totalfiltered, "publications": _publications, "status": "success" }) |