durusmail: quixote-users: Proposed change to _q_getname() interface
Proposed change to _q_getname() interface
2002-05-23
2002-05-23
2002-05-23
2002-05-23
2002-05-23
2002-05-23
Proposed change to _q_getname() interface
Greg Ward
2002-05-23
I could have sworn I brought this up on the list a few months ago, but
couldn't find it in the archive.  The only vaguely relevant thread was
when David Ascher was a bit confused by _q_getname() back in January:

  http://mail.mems-exchange.org/pipermail/quixote-users/2002-January/000222.html

Currently, _q_getname() must return a callable, which is fine for
publishing fairly complex objects.  Our usual idiom for object
publishing is to handle the URL "/foo/37/" by defining a module foo.ptl
in the root namespace which looks like:

  def _q_getname (request, name):
      return FooUI(request, name)

  class FooUI:
      _q_exports = ['details', 'history']

      def __init__ (self, request, name):
          self.foo = get_foo(name)    # get_foo() looks up Foo objects

      template _q_index (self, request):
          # generate a summary overview of this Foo object

      template details (self, request):
          # generate a detailed view of this Foo object

      template history (self, request):
          # generate a page showing the history of this Foo object

This is cool because /foo/37/ becomes a namespace of its own, and we can
also have pages /foo/37/details and /foo/37/history to look at different
views of this Foo object.  Very handy if Foo objects are large and
complex beasts.

However, for simple objects, having _q_getname() return a callable that
is then called by the publisher is overkill.  Quite often it's sufficient
for _q_getname() to generate a page that says everything there is to say
about your object.  Say you want "/person/bob" to be everything about
the person "bob" in your database -- ie. there's no need for "bob" to be
a namespace like "/foo/37/" was.  Right now, you have to do something
like this (ignoring error-handling):

  def _q_getname (request, name):
      person = get_person(name)
      return lambda request: format_person_page(person)

which is kind of clunky.  I'd like to simplify that to this:

  def _q_getname (request, name):
      person = get_person(name)
      return format_person_page(person)

In fact, I have a patch that does just this, which I'll attach.  The
catch is that the patch is not specific to the output of _q_getname():
it applies to any object found while traversing a URL.  That is,
anywhere that Quixote currently requires a callable, it will (with this
patch) accept either a callable or a string.  The string simply
substitutes for the return value of the callable that isn't there.  This
is a subtle generalization of the publishing algorithm that makes it a
little more powerful and little harder to explain.

Anyways, please take a look at the current patch.  It's relative to the
current CVS trunk, so I'm not sure if it will apply to either the 0.4.7
release or my snapshot release of the other day (which is from a CVS
branch that I haven't merged into the trunk yet).  Give it a shot
anyways.  Let me know what you think...

        Greg
reply