diff options
| author | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-11-12 18:18:35 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-11-12 18:18:35 -0500 |
| commit | fcd9465d564b08ae289417fb0616942b38fd0836 (patch) | |
| tree | f4d93b9c9ebde6aff9f8c2157bae62aeb4229c37 /ustayml/views/students.py | |
| parent | 8c82c32015b2c780f2b5662ff495f55153a5a26f (diff) | |
Move pagination functions to db.py
Diffstat (limited to 'ustayml/views/students.py')
| -rw-r--r-- | ustayml/views/students.py | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/ustayml/views/students.py b/ustayml/views/students.py index fef1a82..ba1de04 100644 --- a/ustayml/views/students.py +++ b/ustayml/views/students.py @@ -1,4 +1,3 @@ -import math import datetime from flask import ( Blueprint, flash, g, redirect, render_template, request, url_for @@ -6,7 +5,7 @@ from flask import ( from werkzeug.exceptions import abort from ustayml.views.auth import login_required -from ustayml.db import get_db +from ustayml.db import get_db, get_paginated_items bp = Blueprint('students', __name__, url_prefix='/students') @@ -70,17 +69,4 @@ def details(id): return render_template( 'students/details.html', date=datetime.datetime.now() - ) - - -# Helper functions - -def get_paginated_items(query: str, params: list=[], pagination: dict={}): - limit = pagination.get('pagesize', 100) - offset = pagination.get('page', 0) * limit - with get_db().cursor() as cursor: - cursor.execute(f"{query} LIMIT %s OFFSET %s;", params + [limit, offset]) - pagination['n_pages'] = math.ceil(cursor.rowcount / limit) - pagination['rowcount'] = cursor.rowcount - items = cursor.fetchall() - return items + )
\ No newline at end of file |
