From 4ac180091eb89682e8ac58db1055c1ab07c658bb Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 8 Mar 2007 17:29:58 +0000 Subject: [PATCH] Cheetah changes: upgrade to Cheetah 2.0 (release candidate 7, looking very stable at this point). This gives us big improvements to template compilation and caching, and thus a nice little speed boost. --- lib/galaxy/config.py | 1 + lib/galaxy/web/__init__.py | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/config.py b/lib/galaxy/config.py index 09efbfffc5a..2116032164a 100644 --- a/lib/galaxy/config.py +++ b/lib/galaxy/config.py @@ -28,6 +28,7 @@ class Configuration( object ): self.test_conf = resolve_path( kwargs.get( "test_conf", "" ), self.root ) self.tool_config = resolve_path( kwargs.get( 'tool_config_file', 'tool_conf.xml' ), self.root ) self.template_path = resolve_path( kwargs.get( "template_path", "templates" ), self.root ) + self.template_cache = resolve_path( kwargs.get( "template_cache_path", "database/compiled_templates" ), self.root ) self.job_queue_workers = int( kwargs.get( "job_queue_workers", "10" ) ) self.admin_pass = kwargs.get('admin_pass',"galaxy") self.sendmail_path = kwargs.get('sendmail_path',"/usr/sbin/sendmail") diff --git a/lib/galaxy/web/__init__.py b/lib/galaxy/web/__init__.py index 1bda3659b04..7ae15eb0375 100644 --- a/lib/galaxy/web/__init__.py +++ b/lib/galaxy/web/__init__.py @@ -263,19 +263,34 @@ class UniverseWebTransaction( framework.DefaultWebTransaction ): form. """ return self.fill_template( "form.tmpl", form=form ) + def compile_and_fill_template( self, source=None, file=None, namespaces=[] ): + """ + Get the template matching `source` or `file` and fill it using + variables from `namespaces`. + """ + tclass = Template.compile( source=source, + file=file, + cacheModuleFilesForTracebacks=True, + cacheDirForModuleFiles=self.app.config.template_cache ) + default_namespace = dict( caller=self, t=self, h=webhelpers, + util=util, request=self.request, + response=self.response, app=self.app ) + template = tclass( namespaces = namespaces + [ default_namespace ] ) + return str( template ) def fill_template(self, file_name, **kwargs): """ - Fill in a template, putting any keyword arguments on the context. + Fill in a template from a file. """ - template = Template( file=os.path.join(self.app.config.template_path, file_name), - searchList=[kwargs, self.template_context, dict(caller=self, t=self, h=webhelpers, util=util, request=self.request, response=self.response, app=self.app)] ) - return str(template) + return self.compile_and_fill_template( + file = os.path.join( self.app.config.template_path, file_name ), + namespaces=[ kwargs, self.template_context ] ) def fill_template_string(self, template_string, context=None, **kwargs): """ - Fill in a template, putting any keyword arguments on the context. + Fill in a template from a string. """ - template = Template( source=template_string, searchList=[context or kwargs, dict(caller=self)] ) - return str(template) + return self.compile_and_fill_template( + source = template_string, + namespaces = [ context or kwargs, dict(caller=self) ] ) class FormBuilder( object ): """