def render(self, context): """Renders the page using the specified context. The page is rendered using the template specified in self.templatePath() and is written to the response object. The context object is extended with the following values: app_version: the current version of the application, used e.g. in URL patterns to avoid JS caching issues. is_local: Whether the application is running locally. posted: Whether render is called after a POST is request. xsrf_token: The xsrf token for the current user. Args: context: the context that should be used """ context['app_version'] = os.environ.get('CURRENT_VERSION_ID', '').split('.')[0] context['is_local'] = system.isLocal() context['posted'] = self.posted xsrf_secret_key = site.getXsrfSecretKey(self.data.site) context['xsrf_token'] = xsrfutil.getGeneratedTokenForCurrentUser(xsrf_secret_key) context['ga_tracking_num'] = self.data.site.ga_tracking_num if system.isSecondaryHostname(self.request): context['google_api_key'] = self.data.site.secondary_google_api_key else: context['google_api_key'] = self.data.site.google_api_key rendered = loader.render_to_string(self.templatePath(), dictionary=context) self.response.write(rendered)
def _getSecretKey(self, request): """Gets the XSRF secret key from the request context.""" return site_logic.getXsrfSecretKey(site_logic.getSingleton())