Add function to render a template to a string
authorMagnus Hagander <magnus@hagander.net>
Mon, 11 Jan 2010 14:25:04 +0000 (15:25 +0100)
committerMagnus Hagander <magnus@hagander.net>
Mon, 11 Jan 2010 14:25:04 +0000 (15:25 +0100)
pgweb/util/helpers.py

index 668176921b2add524a61f2cd70f8b262ccf48363..5be8a1aafe6f9564dced2ef66427b8b24dafbd91 100644 (file)
@@ -1,6 +1,8 @@
 from django.shortcuts import render_to_response, get_object_or_404
 from pgweb.util.contexts import NavContext
 from django.http import HttpResponseRedirect
+from django.template import Context
+from django.template.loader import get_template
 
 def simple_form(instancetype, itemid, request, formclass, formtemplate='base/form.html', redirect='/account/', navsection='account'):
        if itemid == 'new':
@@ -41,6 +43,9 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
                'form_intro': hasattr(form, 'form_intro') and form.form_intro or None,
        }, NavContext(request, navsection))
 
+def template_to_string(templatename, attrs = {}):
+       return get_template(templatename).render(Context(attrs))
+
 def add_xml_element(xml, name, value):
        xml.startElement(name, {})
        xml.characters(value)