From 51a39b5c9b78f9c7eb34fd48eb3030194445614e Mon Sep 17 00:00:00 2001 From: Vallari Agrawal Date: Thu, 19 Sep 2024 12:30:38 +0530 Subject: [PATCH] Add controller to filter runs by user Signed-off-by: Vallari Agrawal --- paddles/controllers/runs.py | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/paddles/controllers/runs.py b/paddles/controllers/runs.py index 067ceb2..3e57c3d 100644 --- a/paddles/controllers/runs.py +++ b/paddles/controllers/runs.py @@ -143,6 +143,14 @@ def get_lookup_controller(self): return SuiteController +class UsersController(RunFilterIndexController): + def get_subquery(self, query): + return query.values(Run.user) + + def get_lookup_controller(self): + return UserController + + class StatusesController(RunFilterIndexController): def get_subquery(self, query): return query.values(Run.status) @@ -187,6 +195,8 @@ def get_lookup_controller(self, field): return StatusesController() if field == 'suite': return SuitesController() + if field == 'user': + return UsersController() class DateController(RunFilterController): @@ -213,6 +223,8 @@ def get_lookup_controller(self, field): return Sha1sController() if field == 'suite': return SuitesController() + if field == 'user': + return UsersController() class MachineTypeController(RunFilterController): @@ -230,6 +242,8 @@ def get_lookup_controller(self, field): return Sha1sController() if field == 'suite': return SuitesController() + if field == 'user': + return UsersController() class StatusController(RunFilterController): @@ -247,6 +261,8 @@ def get_lookup_controller(self, field): return Sha1sController() if field == 'suite': return SuitesController() + if field == 'user': + return UsersController() class SuiteController(RunFilterController): @@ -264,6 +280,27 @@ def get_lookup_controller(self, field): return Sha1sController() if field == 'status': return StatusesController() + if field == 'user': + return UsersController() + + +class UserController(RunFilterController): + def get_subquery(self, query): + return query.filter(Run.user == self.value) + + def get_lookup_controller(self, field): + if field == 'branch': + return BranchesController() + if field == 'date': + return DatesController() + if field == 'machine_type': + return MachineTypesController() + if field == 'sha1': + return Sha1sController() + if field == 'status': + return StatusesController() + if field == 'suite': + return SuitesController() class DateRangeController(object): @@ -316,6 +353,8 @@ def get_lookup_controller(self, field): return StatusesController() if field == 'suite': return SuitesController() + if field == 'user': + return UsersController() @@ -361,6 +400,8 @@ def _create_run(cls, name): sha1 = Sha1sController() + user = UsersController() + @expose('json') def _lookup(self, name, *remainder): return RunController(name), remainder