From c9bfcee3dff9e826fb0ce3780f9a8b1b3d8825d2 Mon Sep 17 00:00:00 2001 From: NguyenND Date: Mon, 27 Apr 2026 13:51:15 -0400 Subject: [PATCH] 04/27 Fixed some issues 3 --- app/routes/issues.py | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/app/routes/issues.py b/app/routes/issues.py index d3b5a22..384bfbf 100644 --- a/app/routes/issues.py +++ b/app/routes/issues.py @@ -47,6 +47,25 @@ def _notify_followers(issue, title, body, exclude_user_ids=None): # ── List ────────────────────────────────────────────────────────────────────── +class _SLAFilteredPage: + """Minimal pagination-compatible wrapper used when an SLA filter is active. + + The SLA status is a computed value (not a DB column), so it cannot be + filtered at the query level. When sla_filter is set we load all matching + rows, apply the Python-side filter, and wrap the result in this object so + the template can use the same interface (.items, .pages, .page, .iter_pages) + without any template changes. Pagination is suppressed (single page) since + the full filtered set is always returned. + """ + def __init__(self, items): + self.items = items + self.page = 1 + self.pages = 1 + + def iter_pages(self, **kwargs): + return iter([1]) + + @bp.route('/') @login_required def index(): @@ -79,13 +98,20 @@ def index(): Area.facility_id == int(facility_filter) ) - # SLA filter — applied in Python after DB query since SLA is computed - issues_paged = q.paginate(page=page, per_page=25, error_out=False) - + # SLA filter — SLA status is computed in Python (not a DB column). + # When active: load all matching rows, filter in Python, wrap in a + # single-page compatible object so the template interface is unchanged. + # When inactive: use standard DB-level pagination (25 per page). if sla_filter: - filtered_items = [i for i in issues_paged.items if sla_status(i) == sla_filter] + all_issues = q.all() + filtered = [i for i in all_issues if sla_status(i) == sla_filter] + issues_paged = _SLAFilteredPage(filtered) + logger.debug( + 'ISSUES | index | sla_filter=%s | matched=%s of %s', + sla_filter, len(filtered), len(all_issues), + ) else: - filtered_items = issues_paged.items + issues_paged = q.paginate(page=page, per_page=25, error_out=False) # Build a set of issue IDs the current user is following so the template # can render the following badge and inline unfollow button without an @@ -111,7 +137,6 @@ def index(): return render_template('issues/list.html', issues=issues_paged, - issue_items=filtered_items, severity_filter=severity_filter, status_filter=status_filter, sla_filter=sla_filter, @@ -688,4 +713,4 @@ def quick_assign(issue_id): logger.info('ISSUE QUICK-ASSIGN | issue_id=%s | assigned_to=%s | by=%s', issue.id, label, current_user.username) - return jsonify({'ok': True, 'label': label}) + return jsonify({'ok': True, 'label': label}) \ No newline at end of file