Hi, please help me with this, I have no idea which approach will be the best. The basic question is: if I have website, and that website's structure is tree-like, how will be the most proper way to create navigation? I'd like to have links to neighbour pages (pages on the same node), I'd like to be able to get a list of pages on the "above" nodes. As I have seen in t.w.resource.py: def putChild(self, path, child): """Register a static child. """ self.children[path] = child child.server = self.server there is no chance I can get parent of a specific page, to provide navigation. Do you have any methods or solutions for a good, easy woven page navigation model? -- Michal Pasternak :: http://pasternak.w.lub.pl :: http://winsrc.sf.net ::don't use MySQL::details on http://sql-info.de/mysql/gotchas.html::
Christopher Armstrong [Tue, Jan 27, 2004 at 05:39:19PM -0500]:
What kind of storage are you using? If it's a filesystem that mirrors the URL structure, you could just look up a modified request.prepath in your file system and look at sibling pages.
I am not using any filesystem. Whole structure is made up of classess in the code. Currently I have written a custom class, which is a basic of all classess I create: class SitePage(page.Page): def __init__(self, name = "", label = "", browseable = True): page.Page.__init__(self) self.name = name self.label = label self.browseable = browseable self.parent = None self.myChildren = [] def putChild(self, p): page.Page.putChild(self, p.name, p) p.parent = self self.myChildren.append(p) ... and I can achieve both goals with it, but I don't know if it is the best method available.
Michal Pasternak wrote:
The basic question is: if I have website, and that website's structure is tree-like, how will be the most proper way to create navigation?
Do you have any methods or solutions for a good, easy woven page navigation model?
What kind of storage are you using? If it's a filesystem that mirrors the URL structure, you could just look up a modified request.prepath in your file system and look at sibling pages. The moral of the story is that it depends on your storage mechanism. Where is the canonical location of your tree of pages? It's most likely that your data source will somehow be "keyed" by information that's available in request.prepath, whether it's keyed by actual paths or just one of the elements in the prepath, or whatever. -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/
On Jan 27, 2004, at 4:55 PM, Michal Pasternak wrote:
Christopher Armstrong [Tue, Jan 27, 2004 at 05:39:19PM -0500]:
What kind of storage are you using? If it's a filesystem that mirrors the URL structure, you could just look up a modified request.prepath in your file system and look at sibling pages.
I am not using any filesystem. Whole structure is made up of classess in the code. Currently I have written a custom class, which is a basic of all classess I create:
... and I can achieve both goals with it, but I don't know if it is the best method available.
If you use nevow, it does this for you. request.resources is a list containing all the resources called on the way down. So, in getChild, request.resources[-1] is your parent. In render, i believe request.resources[-2] will be your parent. If you're not using nevow, perhaps you should be. :) James
Hi, I have run around the on-line documentation for twisted and couldn't find the relevant docs to help my case. If anyone has pointers on what to read, I would gladly read those documents first. Here is the question: I want to run a xmlrpc server and client together. That is, in the same program, I want to be able to listen from other clients that are calling my xmlrpc methods, and from time to time, I want to call the other clients' xmlrpc methods as well.
From the examples I can find, a server is run by invoking an application's run method, while a client is run by invoking the reactor's run method. How can I "register" my own event loop in addition to the application's already existing xmlrpc server that I have added earlier?
For example, let's say I have two clients that implement the adder xmlrpc method (returns the sum of two numbers). I want the clients to call each other's adder method every two seconds. Below is the server sample code from Victor Ng that I am looking at (I only added some code to read arguments from the command line): from twisted.internet import reactor, defer from twisted.web import xmlrpc, server, resource from twisted.enterprise import adbapi import sys if len (sys.argv) >= 5: player_id = int (sys.argv[1]) port_num = int (sys.argv[2]) num_players = int (sys.argv[3]) start_port_num = int (sys.argv[4]) print "Starting agents.py with player_id: %d, port_num: %d, num_players: %d, start_port_num: %d\n" % (player_id, port_num, num_players, start_port_num) class XMLRPCAdder(xmlrpc.XMLRPC): """ An example object to be published """ def run_add(self, d, a, b): d.callback(a+b) def marshallResult(self, data): return "[%s]" % str(data) def xmlrpc_add(self, a, b): d = defer.Deferred() # setup a callback in 2 seconds that executes the callback on the deferred reactor.callLater(2, self.run_add, d, a, b) return d.addCallback(self.marshallResult) def main(): from twisted.internet.app import Application app = Application("simpleDemoServer") root = resource.Resource() child = XMLRPCAdder() root.putChild('RPC2', child) app.listenTCP(port_num, server.Site(root)) return app application = main() if __name__ == '__main__': application.run(save = 0) Thanks in advance. John Lin
On Tue, Jan 27, 2004 at 10:26:37PM +0100, Michal Pasternak wrote:
The basic question is: if I have website, and that website's structure is tree-like, how will be the most proper way to create navigation?
I'd like to have links to neighbour pages (pages on the same node), I'd like to be able to get a list of pages on the "above" nodes.
Do you have any methods or solutions for a good, easy woven page navigation model?
The basic answer is a combination of wchild_ methods and getDynamicChild() class MyPage(page.Page): def __init__(self, ...): self.someParam = 'bar' self.kids = { 'alice': AlicePage(), 'bob': BobPage() } def wchild_carol(self, request): """Use this style for static structure.""" return CarolPage() def getDynamicChild(self, name, request): """Use this style for dynamic structure. Example: http://mysite/users/<username> """ child = self.kids[name] child.parent = self return child This demonstrates the two major ways in woven to handle site structure. That'd give you a site like: http://root/ http://root/alice, http://root/bob http://root/carol Any Page subclass that you define can do these things, so you can effectively achieve a tree structure, which each Page knowing how to make / get at its child pages. In the example, the 'alice' and 'bob' pages know their parent. 'carol' does not. This is obviously a problem, and a mistake that one might be likely to make when mixing wchild_* and getDynamicChild So, a better way to deal with this might be to override getChild(). You shouldn't unless you know what you are doing, so I'll leave you to read the code to find out how. One benefit would be that you'd have less to worry about. Another would be that you'd just use wchild_*, which is more appropriate for your site, based on the way you've described it. cheers, jml PS. Use Nevow.
participants (5)
-
Christopher Armstrong
-
James Y Knight
-
jml@mumak.net
-
John C Lin
-
Michal Pasternak