From 72c3d6b50702982b8b6c282ecf5f4209e7430817 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 11 Feb 2019 15:59:29 -0600 Subject: [PATCH] join arbiter filter queries + use flush to get proposal.id on create --- backend/grant/admin/views.py | 1 + backend/grant/proposal/models.py | 2 +- backend/grant/utils/pagination.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/grant/admin/views.py b/backend/grant/admin/views.py index 44416db2..23ac8cb9 100644 --- a/backend/grant/admin/views.py +++ b/backend/grant/admin/views.py @@ -62,6 +62,7 @@ def stats(): .filter(Proposal.status == ProposalStatus.PENDING) \ .scalar() proposal_no_arbiter_count = db.session.query(func.count(Proposal.id)) \ + .join(Proposal.arbiter) \ .filter(Proposal.status == ProposalStatus.LIVE) \ .filter(ProposalArbiter.status == ProposalArbiterStatus.MISSING) \ .scalar() diff --git a/backend/grant/proposal/models.py b/backend/grant/proposal/models.py index 8806b127..36d42316 100644 --- a/backend/grant/proposal/models.py +++ b/backend/grant/proposal/models.py @@ -277,7 +277,7 @@ class Proposal(db.Model): # arbiter needs proposal.id db.session.add(proposal) - db.session.commit() + db.session.flush() arbiter = ProposalArbiter(proposal_id=proposal.id) db.session.add(arbiter) diff --git a/backend/grant/utils/pagination.py b/backend/grant/utils/pagination.py index 9d0f6a20..d75c50e8 100644 --- a/backend/grant/utils/pagination.py +++ b/backend/grant/utils/pagination.py @@ -87,7 +87,8 @@ class ProposalPagination(Pagination): if cat_filters: query = query.filter(Proposal.category.in_(cat_filters)) if arbiter_filters: - query = query.filter(ProposalArbiter.status.in_(arbiter_filters)) + query = query.join(Proposal.arbiter) \ + .filter(ProposalArbiter.status.in_(arbiter_filters)) # SORT (see self.SORT_MAP) if sort: