From 6515092df466b7720e98f08b34c30ed5b6924c98 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Fri, 15 Apr 2016 11:18:21 -0400 Subject: [PATCH 1/3] Add q filter for the project controller. --- app/controllers/project.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/project.py b/app/controllers/project.py index ed82fb7..878753e 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.""" -- GitLab From fe60a52df662dd7d8901c69f0dd63296f68de60d Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Fri, 15 Apr 2016 16:42:03 -0400 Subject: [PATCH 2/3] Change the default port number. --- run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.py b/run.py index 4b2550f..217555d 100644 --- a/run.py +++ b/run.py @@ -4,4 +4,4 @@ from app.lib.database import db app = create_app('config/development.py') if __name__ == '__main__': - app.run(host='0.0.0.0', port=5310) + app.run(host='0.0.0.0', port=5302) -- GitLab From 0bfa30d0a61eac7db4d08d1e1c4f211659791641 Mon Sep 17 00:00:00 2001 From: astex <0astex@gmail.com> Date: Fri, 15 Apr 2016 18:23:20 -0400 Subject: [PATCH 3/3] Add a test for the q filter on the project index. --- app/tests/test_project.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/tests/test_project.py b/app/tests/test_project.py index b75fb4c..e4462cb 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 -- GitLab