Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1432 (closed task: fixed)

Opened 12 years ago

Last modified 12 years ago

Document "lookup" function in 2.0 style Object Dispatch

Reported by: mramm Owned by: anonymous
Priority: normal Milestone: 2.0
Component: TurboGears Version: trunk
Severity: normal Keywords:
Cc:

Description

Here's a description from Rick!

Lookup and default are called in identical situations: when "normal" object traversal is not able to f:nd an exposed method, it begins popping the stack of "not found" handlers. If the handler is a "default" method, then you know what happens. "lookup" methods are a bit different, however, as they are not actual controllers themselves. A lookup method takes as its argument the remaining path elements and returns an object (representing the next step in the traversal) and a (possibly modified) list of remaining path elements. So a blog might have controllers that look something like this:

class BlogController?(Controller):

@expose() def lookup(self, year, month, day, id, *remainder):

dt = date(int(year), int(month), int(day)) return BlogEntryController?(dt, int(id)), remainder

class BlogEntryController?(Controller):

def init(self, dt, id):

self.entry = model.BlogEntry?.get_by(date=dt, id=id)

@expose(...) def index(self):

...

@expose(...) def edit(self):

...

@expose() def update(self):

....

So a URL request to .../2007/6/28/0/edit would map to BlogEntryController?(date(2007,6,28), 0).edit . In other situations, you might have a several-layers-deep "lookup" chain, e.g. for editing hierarchical data (/client/1/project/2/task/3/edit). The benefit over "default" handlers is that you _return_ a controller and continue traversing rather than _being_ a controller and stopping traversal altogether. (Plus, it makes semi-RESTful URLs easy.)

Change History

comment:1 Changed 12 years ago by mramm

  • Status changed from new to closed
  • Resolution set to fixed

Extended documentation added to docstrings

Note: See TracTickets for help on using tickets.