So the problem is that you are trying to
#include templateName
where templateName is a runtime variable.

This is only a guess, use cheetah-compile to verify:

The template is compiled in awake.
The included code gets compiled into the cheetah template instance.
By default the cheetah template instance only changes if you edit a template file and the template recompiles.
chaging the value of T.body changes the instance variable of the current template, BUT THE TEMPLATE ITSELF is still the original include.


dynamic #includes are a PHP type hack. Cheetah provides templates as classes so you should do something like

siteMain.template
<head>...
#block body
I am a default page - listing
#end block

moduser.template

#from siteMain import siteMain
#extends siteMain
#implements body


Template inheritence or nested templates are the way to go for your issue.


-Aaron

ps: I could be wrong so I am cc'ing the Cheetah Template list, since this is a Cheetah issues, not Webware.

"Webware is not responsible for this issue, you need to contact the Cheetah vendor for support, If then can't help then just reformat and try again"


Leith Parkin wrote:


Hi Aaron,

The base template contains a stanza #include $body to determine the body of the page. I do this because i would like to keep the amount of code in the template defininations as minimal as possible, limited to simple #if's and #for's.

The page's are rendering correctly - to a point. The problem is that when serverlet.process() is called, logging the values in self.transaction() shows that process() is being called correctly, and following the desired code path, however the output appears to be cached.

In the code below, calling the servlet "view" without any GET parameters results in T.body using the template templates/users/list.template, which is correct. Click a link generated by that page, of the form view?uid=username should then use T.body as templates/users/moduser.template. The code path followed is correct, but VivaSite.respond() rendering gives the same output as if uid= was never passed (eg renders list.template).

Leaving the webpage alone for roughly 5 minutes and hitting refresh results in the correct template being rendered. I assume this correlates roughly to VivaSite.awake() being called (which is really Page.awake() in this case). Is there some kind of behind the scenes cheetah caching going on?

Sorry if this all sounds a bit confusing. The current system's templates all work in this manner, but it is all cgi based, and i am trying to unify it into some kind of application.

Thanks

Leith Parkin

Aaron Held wrote:

I am not sure what should be happening when at the line:

self.T.body = 'templates/users/moduser.template'

if you have something like
$body
in your cheetah template then this will just expand to that string, not the contents of the template moduser.templet.


check the source of the generated HTML.

You may need to either build the moduser.template in your servlet and assing the rendered version to T.body
or let moduser.template inherit from basetemplate.
Templates are full object, and moduser.template should inherit from site.template
( http://cheetahtemplate.org/docs/users_guide_html_multipage/howWorks.objoriented.html )
This is what got me into Cheetah to begin with (and the fact that I was using java velocity at the time)
In theory its great, but in use I got tired of manually recompiling my templates and restarting webware every time I made a change to a base template.


Another approach I use it the assing the results of a function to a template variable.
T.contentBox = self.pageContents()


Then each sub-servlet can just override pageContents.

-Aaron

Leith Parkin wrote:

Hi Aaron,

Thanks for the great tips and urls. Im pretty much on my way now, however i am getting some strange? behavior, is this the correct behaviour?

i have a "site" class parent defined as

--- code ---
from pyPgSQL import PgSQL
from mx.DateTime.Parser import DateTimeFromString
from Viva.User import User
from Viva.DBCache import DBCache
from MiscUtils.DBPool import DBPool



# global datapool
datapool = DBPool(PgSQL, 5, database='proptrak', user='leith')


class VivaSite(Page): def __init__(self): Page.__init__(self) self.T = Template(file='templates/base.template') self.DBCache = DBCache(self.getDBConn()) def respond(self, transaction): user = User(self.request().remoteUser()) self.T.user = user self.process(self.request(), self.transaction()) self.write(str(self.T))

   #overridden by subclasses
   def process(trans):
       pass

     def getDBConn(self):
       return datapool.getConnection()
-- end code --

Then in a servlet i have

-- code --
from VivaSite import VivaSite
from Viva.User import User

class view(VivaSite):
   def __init__(self):
       VivaSite.__init__(self)

   def process(self, request, transaction):
       self.T.title = "Viewing users"
       self.T.menu = True
       # check passwords match
       f = request.fieldStorage()

       if f.has_key('uid'):
           self.T.mod = User(f['uid'].value)
           self.T.body = 'templates/users/moduser.template'
           self.T.roles = self.DBCache['all_roles']
           print f['uid'].value

       else:
           db = self.getDBConn()
           sql  = db.cursor()
           sql.execute('SELECT * FROM users ORDER BY username ASC')
           self.T.body = 'templates/users/list.template'
           self.T.results = sql.fetchall()      -- end code --

Obviously there is a sitewide template called base.template, which has a couple of hooks in for pages, such as $body, $title and $menu to define page rendering. Each servlet sets these vars on self.T.varname = "value". This has worked flawlessly when the site was first designed using straight cgi files for each "servlet".

When i call http://server/users/view I get the output generated of the list.template, even when i call as http://server/users/view?uid=username. Is this some kind of caching behaviour? a log call in the view class shows that the transaction has the properties i would expect. Please let me know if I am approaching this all from the wrong angle.

Thanks

Leith


Aaron Held wrote:


Anything that the Browser sends comes in via the Request object.
You can access this from a servlet via self.request()
If you check the limited docs ( http://webware.sourceforge.net/Webware-0.8.1/WebKit/Docs/Source/Summaries/HTTPRequest.py.html


)
you will see a method called field.
so to get the value of page out of ShowPage?page=somefile.template
you would have some code like

def writeContent(self):
templateName = self.request().field('page','default.template')
templateFile=os.path.join(os.path.dirname(os.path.dirname(self.serverSidePath()))


,r'templates',templateName')
#templates are in AppWorkDir\templates
t = Template(file=templateFile, searchList=[self.getPageData()])
self.write(t)


By the same token anything that you would like to send back to the browser is in the Response object.
http://webware.sourceforge.net/Webware-0.8.1/WebKit/Docs/Source/Summaries/HTTPResponse.py.html



Calling self.write(t)
causes python to evaluate t as a string, and then pass that string to the write method and send
it to the browser


A nice Cheetah trick it to pass the servlets Response object to the cheetah templates respond method.
t.respond(trans=self.transaction())
This causes the results to be sent diretly from the template to the browser, rather then buffering it up in ram.



-Aaron



Read:
http://webware.sourceforge.net/Papers/Python10.pdf
http://webware.colorstudy.com/twiki/bin/view/Webware/TransactionAnatomy


http://webware.sourceforge.net/Papers/IntroToWebware.html


Leith Parkin wrote:


G'day all,

Ive recently installed webware and have been having a play with it. I have managed to create a very very simple app that uses Cheetah templates to produce a static output. I would really love to extend this futher to handle forms and query string parameters. Reading the docs that come with the 0.8.1 (basically the class list) i am a little confused. Once i get a good handle on webware i intend to replace a intranet system at my workplace which currently runs as a lot of cgi scripts into some sort of unified application.

I dont have a overly strong grasp on pythons OO, and am quite new to this idea of application servers, so am i little confused as to what methods one needs to override to provide functionality for say a servelet that is called as ShowPage?page=somefile.template . A quick search on google has given a few pages, but they seem to jump over what seems to me a pretty basic concept?

Could someone please point me to a beginners guide that explains simple concepts like this?

Thanks

Leith



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss












-- -Aaron http://www.MetroNY.com/ "I don't know what's wrong with my television set. I was getting C-Span and the Home Shopping Network on the same station. I actually bought a congressman." - Bruce Baum





-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to