Skip to content

Commit

Permalink
Merge pull request #131 from VallariAg/jobs-filter-improve
Browse files Browse the repository at this point in the history
paddles/controllers/jobs.py: Add filters to JobsListController
  • Loading branch information
zmc authored Feb 26, 2025
2 parents 84cbf01 + e0c8503 commit 8d1e8c8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions paddles/controllers/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,37 @@ def _lookup(self, job_id, *remainder):

class JobsListController(object):
@expose('json')
def index(self, description='', status='', count=10, page=1):
def index(self, description='', status='', sha1='', branch='', user='', posted_after='', posted_before='', count=10, page=1):
"""
List latest jobs.
Filter by description and status.
Filter by sha1, branch, username, posted date (range:- posted_before:posted_after), description, and status.
"""
job_query = Job.query.order_by(desc(Job.posted))

if description:
job_query = job_query.filter(Job.description == description)
job_query = job_query.filter(Job.description.contains(description))

if status:
job_query = job_query.filter_by(status=status)

if sha1:
job_query = job_query.filter_by(sha1=sha1)
elif branch:
job_query = job_query.filter_by(branch=branch)

if user:
job_query = job_query.filter_by(user=user)

if posted_after:
posted_after = paddles.controllers.runs.date_from_string(posted_after)[1]
job_query = job_query.filter(Job.posted > posted_after)

if posted_before:
posted_before = paddles.controllers.runs.date_from_string(posted_before)[1]
job_query = job_query.filter(Job.posted < posted_before)

job_query = offset_query(job_query, page_size=count, page=page)
jobs = job_query.all()

return jobs

0 comments on commit 8d1e8c8

Please # to comment.