Winston WOLFF wrote:
I generally really like Webware and Cheetah--it's simple and fast and easy to work with. But one thing keeps bugging me. I think of my web pages as a bunch of objects which they are--a bunch of servlet objects. So it should be easy to access my web page servlet objects as a graph. I want to be able to traverse from my current page back up to the root object, find this page's siblings, etc. But for some reason I cannot find a simple way of doing this. The main problem is the difficulty of calling methods on servlets. You have to use callMethodOfServlet(), and that does not work with Cheetah templates. I am pursuing that on the Cheetah list separately, but I wonder, would it be possible to eliminate the need for callMethodOfServlet()? CherryPy does a very cool thing where every page is just a class or method that returns a string. The string contains the HTML that becomes the page. Simple yet gets the job done. Could we simplify Webware somehow in that direction?

Well, no, that would change Webware into something different. But you could build what you are looking for ontop of Webware. Maybe like:


class Main(Page):

    def awake(self, trans):
        Page.awake(self, trans)
        path = self.request().extraURLPath()
        self.object = traverse_path(root, path)

    def writeHTML(self):
        self.write(self.object(trans))

import base
root = base.root_object
def traverse_path(object, path):
    if not path:
        return object
    assert path.startswith('/')
    first = path.split('/')[1]
    rest = path.split('/', 2)
    if len(rest) == 3:
        rest = '/' + rest[2]
    else:
        rest = ''
    return traverse_path(get_part(object, first), rest)

def get_part(object, attr):
    # Maybe use getattr or something else
    return object[attr]

--
Ian Bicking  /  [EMAIL PROTECTED]  /  http://blog.ianbicking.org


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
Webware-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to