From e5127c5710abbd77527d2dfa083a506a68ee23b3 Mon Sep 17 00:00:00 2001 From: NavaL Date: Mon, 18 Jan 2016 17:38:21 +0100 Subject: migrating contact resources to use the services factory Issue #576 --- service/pixelated/resources/__init__.py | 3 +++ service/pixelated/resources/contacts_resource.py | 12 ++++++------ service/pixelated/resources/root_resource.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'service/pixelated') 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 . -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)) -- cgit v1.2.3