[Twisted-web] Page navigation: a cry for help

Jonathan M. Lange twisted-web@twistedmatrix.com
Sat, 31 Jan 2004 00:21:07 +1100


--vkogqOf2sHV7VnPd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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 l=
ike
> 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 navigati=
on
> model?
=20

The basic answer is a combination of wchild_ methods and getDynamicChild()

class MyPage(page.Page):
  def __init__(self, ...):
    self.someParam =3D 'bar'
    self.kids =3D { '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 =3D self.kids[name]
    child.parent =3D self
    return child

This demonstrates the two major ways in woven to handle site structure.=20
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 effective=
ly
achieve a tree structure, which each Page knowing how to make / get at its=
=20
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.=20

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.


--vkogqOf2sHV7VnPd
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAGlpDOp5n04HhSp8RAiL5AJ9uE1hlb3CpIfm3womk2CXVQyGgmgCfek9K
H9ntuqozlWypkS2DAX9P5R8=
=5hEp
-----END PGP SIGNATURE-----

--vkogqOf2sHV7VnPd--