From b230d58eaa32a7f115881cffbf5637d98d1e8299 Mon Sep 17 00:00:00 2001 From: sw00 Date: Sun, 25 Oct 2015 18:18:23 -0200 Subject: template user's email address into title this should solve https://github.com/pixelated/pixelated-user-agent/issues/246 needed to inject leap_session into root resource to access user email on request. --- service/pixelated/resources/root_resource.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'service/pixelated/resources') diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py index e6046eae..fd3c4f92 100644 --- a/service/pixelated/resources/root_resource.py +++ b/service/pixelated/resources/root_resource.py @@ -1,5 +1,6 @@ import os import requests +from string import Template from pixelated.resources.attachments_resource import AttachmentsResource from pixelated.resources.contacts_resource import ContactsResource from pixelated.resources.features_resource import FeaturesResource @@ -22,6 +23,7 @@ class RootResource(Resource): Resource.__init__(self) self._startup_assets_folder = self._get_startup_folder() self._static_folder = self._get_static_folder() + self._html_template = open(os.path.join(self._static_folder, 'index.html')).read() self._startup_mode() def _startup_mode(self): @@ -33,7 +35,9 @@ class RootResource(Resource): return self return Resource.getChild(self, path, request) - def initialize(self, keymanager, search_engine, mail_service, draft_service, feedback_service): + def initialize(self, leap_session, keymanager, search_engine, mail_service, draft_service, feedback_service): + self._leap_session = leap_session + self.putChild('assets', File(self._static_folder)) self.putChild('keys', KeysResource(keymanager)) self.putChild('attachment', AttachmentsResource(mail_service)) @@ -67,4 +71,6 @@ class RootResource(Resource): if self._is_starting(): return open(os.path.join(self._startup_assets_folder, 'Interstitial.html')).read() else: - return open(os.path.join(self._static_folder, 'index.html')).read() + email = self._leap_session.account_email() + response = Template(self._html_template).safe_substitute(account_email=email) + return str(response) -- cgit v1.2.3