diff --git a/app/controllers/project.py b/app/controllers/project.py index ed82fb70bed53eac1c00c04e5dbffe28ea5a53df..878753e2672827b271efed6969788e59e147e13e 100644 --- a/app/controllers/project.py +++ b/app/controllers/project.py @@ -23,6 +23,12 @@ class ProjectController(RestController): """The project controller.""" Model = Project constant_fields = ['sales_force_id', 'client_id', 'place_id'] + filters = { + 'q': lambda d: and_(*[ + Project.name.like('%{}%'.format(term)) + for term in d['q'].split(' ') + ]) + } def get_form(self, filter_data): """Return the project form.""" diff --git a/app/tests/test_project.py b/app/tests/test_project.py index b75fb4c98738f50b44ea2baf700f61b6e1151a01..e4462cb024cea41e0dc0ae9158e2668d04826a65 100644 --- a/app/tests/test_project.py +++ b/app/tests/test_project.py @@ -23,6 +23,19 @@ class TestProject(RestTestCase): model = self.env.project self._test_index() + def test_index_q(self): + """Tests /project/?q=... GET.""" + # Add a project that should be in the response. + model = self.env.project + # Add a project that should not be in the response. + self.env.add(Project( + client_id=self.env.client.id, + place_id=self.env.place.id, + name='foo')) + response_data = self._test_index({'q': 'test'}) + self.assertEquals(len(response_data), 1) + self.assertEquals(response_data[0]['id'], model.id) + def test_get(self): """Tests /project/ GET.""" model = self.env.project