On Thu, Apr 25, 2002 at 11:42:39AM -0400, Aaron Held wrote:
> I know with cheetah you can pull the text from any source and
> compile it into a template via
> 
> tempDef = functionToPullTemplateStringFromDatabase
>  t = Template(tempDef,[orderData])

That's
        t = Template(templateDef, searchList=[orderData])
to you, buddy.  :)

It's prob'ly possible with some work to store the precompiled
template module in the database and then exec it into a private
dictionary when you need it, but it's prob'ly easier to just
store the template definition in the databse and let it be
recompiled each time.

If you're using inheritance, you need to store the base template
modules in the filesystem.  Trying to extract those from the
database would be a lot of work since you'd have to override parts
of Python's import mechanism.

> Another trick I like is to precompile the template and then use
> it normally.
> 
> self.compTemplate = Template(tempDef)
> self.compPrintTemplate = Template(printTempDef)
> 
> Where tempDef if the teplate for a normal page and printTempDef
> is the template for a "priter friendly page"
> 
> and then use something like:
> if (self._printThis==0):
>    t = self.compTemplate
>    print "in normal template"
>   else:
>    t = self.compPrintTemplate
>    print "in Print template"
>  t.pagedata = pagedata
> self.writeln(t)
> 
> but you would need some mechanism to see when the template
> changes, and if you have lots of templates then this will cause
> some memory overhead.  (# of templates * # of pages * number of
> threads)  So in my little example I have up to 200 templates
> classes for two different views of one page.
> 
> But it is fast, and memory is cheap.

At most sites, "printable page" just means omit drawing the table cells
and decorations arount the content, and perhaps substitute a few minimal
decorations instead.  This can be handled by a couple #if stanzas in the
base template (if using inheritance), along with a 'print' variable in
the searchList.  Then you'd only need one template for each page rather
than a pair of templates.

-- 
-Mike (Iron) Orr, [EMAIL PROTECTED]  (if mail problems: [EMAIL PROTECTED])
   http://iron.cx/     English * Esperanto * Russkiy * Deutsch * Espan~ol

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to