summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNavaL <mnandri@thoughtworks.com>2016-01-18 17:38:21 +0100
committerNavaL <mnandri@thoughtworks.com>2016-01-18 17:38:21 +0100
commite5127c5710abbd77527d2dfa083a506a68ee23b3 (patch)
tree254ea720d34f74b8a6c7c1f9da740325c2c47441 /service
parentbb9a1c8827c02ac71c16b7d5d0b4c4c18b34f24c (diff)
migrating contact resources to use the services factory
Issue #576
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/resources/__init__.py3
-rw-r--r--service/pixelated/resources/contacts_resource.py12
-rw-r--r--service/pixelated/resources/root_resource.py2
-rw-r--r--service/test/support/integration/app_test_client.py1
4 files changed, 11 insertions, 7 deletions
diff --git a/service/pixelated/resources/__init__.py b/service/pixelated/resources/__init__.py
index cddfff97..023bcd7e 100644
--- a/service/pixelated/resources/__init__.py
+++ b/service/pixelated/resources/__init__.py
@@ -63,3 +63,6 @@ class BaseResource(Resource):
def mail_service(self, request):
return self._service(request, 'mail_service')
+
+ def search_engine(self, request):
+ return self._service(request, 'search_engine')
diff --git a/service/pixelated/resources/contacts_resource.py b/service/pixelated/resources/contacts_resource.py
index 43155774..dc17d1ac 100644
--- a/service/pixelated/resources/contacts_resource.py
+++ b/service/pixelated/resources/contacts_resource.py
@@ -14,23 +14,23 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-from pixelated.resources import respond_json_deferred
+from pixelated.resources import respond_json_deferred, BaseResource
from twisted.internet.threads import deferToThread
from twisted.web import server
from twisted.web.resource import Resource
-class ContactsResource(Resource):
+class ContactsResource(BaseResource):
isLeaf = True
- def __init__(self, search_engine):
- Resource.__init__(self)
- self._search_engine = search_engine
+ def __init__(self, services_factory):
+ BaseResource.__init__(self, services_factory)
def render_GET(self, request):
+ _search_engine = self.search_engine(request)
query = request.args.get('q', [''])[-1]
- d = deferToThread(lambda: self._search_engine.contacts(query))
+ d = deferToThread(lambda: _search_engine.contacts(query))
d.addCallback(lambda tags: respond_json_deferred(tags, request))
def handle_error(error):
diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py
index af3c6c98..40895bff 100644
--- a/service/pixelated/resources/root_resource.py
+++ b/service/pixelated/resources/root_resource.py
@@ -42,7 +42,7 @@ class RootResource(Resource):
self.putChild('assets', File(self._static_folder))
self.putChild('keys', KeysResource(services_factory))
self.putChild(AttachmentsResource.BASE_URL, AttachmentsResource(services_factory))
- self.putChild('contacts', ContactsResource(search_engine))
+ self.putChild('contacts', ContactsResource(services_factory))
self.putChild('features', FeaturesResource())
self.putChild('tags', TagsResource(search_engine))
self.putChild('mails', MailsResource(mail_service, draft_service))
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 6a43ed1a..2fa3a2dd 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -91,6 +91,7 @@ class AppTestClient(object):
services = mock()
services.keymanager = self.keymanager
services.mail_service = self.mail_service
+ services.search_engine = self.search_engine
self.service_factory.add_session('someuserid', services)
self.resource.initialize(