﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
1140	[patch] using another type of template (zpt) with render_to_response / render_to_string	bas@…	Adrian Holovaty	"Hi!

for some of my sites i use zpt (ZopePageTemplates).
when making login/logout pages with django.views.auth.login i found that
i could not use zpt because the pages where automaticly send
to render_to_response and required django templates.

for this i made a small patch to loader.py to allow setting an arbirary
prefered templating system. (such as django.contrib.pagetemplate.pagetemplate.get_template)

the patch is far from perfect (but it works :)). it's missing a change to conf.global_settings.py
so the TEMPLATE_SYSTEM_PREFERED configuration is not mandatory. (should be set default to """")
also the code and naming could be better and more consistent i guess.

it would be nice to have something like a list for TEMPLATING SYSTEMS much like TEMPLATE_LOADERS.
so one could specify with templating systems are in use and have the templating system search all
of those. (as far as zpt goes this is perfect cause they both work with a template instance and
a context to render a page, so there is not much difference between calling zpt or djangotemplates)

= settings.py =
{{{
# For no other prefered templating system
# TEMPLATE_SYSTEM_PREFERED = """"

# For zpt/tal templates
TEMPLATE_SYSTEM_PREFERED = ""django.contrib.pagetemplate.pagetemplate.get_template""
}}}

= patch =
{{{
--- loader.py.bak       2005-12-23 00:26:59.000000000 +0100
+++ loader.py   2005-12-29 23:44:20.000000000 +0100
@@ -22,7 +22,19 @@

 from django.core.exceptions import ImproperlyConfigured
 from django.core.template import Origin, StringOrigin, Template, Context, TemplateDoesNotExist, add_to_builtins
-from django.conf.settings import TEMPLATE_LOADERS, TEMPLATE_DEBUG
+from django.conf.settings import TEMPLATE_LOADERS, TEMPLATE_DEBUG, TEMPLATE_SYSTEM_PREFERED
+
+if TEMPLATE_SYSTEM_PREFERED:
+    i = TEMPLATE_SYSTEM_PREFERED.rfind('.')
+    module, attr = TEMPLATE_SYSTEM_PREFERED[:i], TEMPLATE_SYSTEM_PREFERED[i+1:]
+    try:
+       CustomTemplateModule = __import__(module, globals(), locals(), [attr])
+    except ImportError, e:
+        raise ImproperlyConfigured, 'Error importing template system %s: ""%s""' % (module, e)
+    try:
+        CustomTemplate = getattr(CustomTemplateModule, attr)
+    except AttributeError:
+        raise ImproperlyConfigured, 'Module ""%s"" does not define a ""%s"" callable Template System' % (module, attr)

 template_source_loaders = []
 for path in TEMPLATE_LOADERS:
@@ -87,10 +99,27 @@
     the templates in the list. Returns a string.
     """"""
     dictionary = dictionary or {}
-    if isinstance(template_name, (list, tuple)):
-        t = select_template(template_name)
+
+    def get_django_template(template_name):
+       if isinstance(template_name, (list, tuple)):
+           t = select_template(template_name)
+       else:
+           t = get_template(template_name)
+       return t
+
+    def get_custom_template(template_name):
+       try:
+           t = CustomTemplate(template_name)
+       except TemplateDoesNotExist, e:
+           # Fall back on Django Style Templates
+           t = get_django_template(template_name)
+       return t
+
+    if TEMPLATE_SYSTEM_PREFERED:
+       t = get_custom_template(template_name)
     else:
-        t = get_template(template_name)
+       t = get_django_template(template_name)
+
     if context_instance:
         context_instance.update(dictionary)
     else:
}}}"	enhancement	closed	Template system	0.90	normal	wontfix	templates, zpt, pagetemplates		Unreviewed	1	0	0	0	0	0
