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







-------------------------------------------------------
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