Web/URLTraversal

Not logged in - Log In / Register

Revision 1 as of 2009-05-14 19:56:16

Clear message

URL Traversal

Launchpad does two forms of traversal

  1. from a URL to a view
  2. from an Interface to a URL

These are not symmetrical (you don't go from a view to a URL or from a URL to an Interface).

Interface to URL

This is provided via the canonical.launchpad.webapp.canonical_url function.

It is configured via ZCML directives. For example:

    <browser:url
        for="canonical.launchpad.interfaces.ICodeReviewMessage"
        attribute_to_parent="branch_merge_proposal"
        path_expression="string:comments/${id}"
        rootsite="code" />

This specifies:

  1. We are defining a url for the ICodeReviewMessage interface

  2. attribute_to_parent defines the attribute of this interface that refers to the parent interface. Remember, we are starting from a leaf, and working back to the root URL.
  3. We are adding comments/${id} to the path of the parent Interface. Where id is the id field of the instance.

  4. rootsite is the subdomain this URL should be rooted at

Test cases for each URL type should be added to lib/canonical/launchpad/doc/canonical_url_examples.txt

URL to View

The parent interface should have a Navigation subclass.

For example:

class BranchMergeProposalNavigation(Navigation):

    usedfor = IBranchMergeProposal

    @stepthrough('comments')
    def traverse_comment(self, id):
        try:
            id = int(id)
        except ValueError:
            return None
        return self.context.getMessage(id)

This specifies

  1. This Navigation subclass is for the IBranchMergeProposal interface.

  2. It provides one set of sub-urls: 'comments/id', where id is used to retrieve the actual content object that will be viewed.

The Navigation must be registered:

  <browser:navigation
      module="canonical.launchpad.browser"
      classes="BranchMergeProposalNavigation" />

A view object must be provided for the view.

    class CodeReviewMessageView(LaunchpadView):
        pass

It should derive from either LaunchpadView or LaunchpadFormView

The view object must be registered for the appropriate interface:

    <browser:defaultView
        for="canonical.launchpad.interfaces.ICodeReviewMessage"
        name="+index" />
    <browser:page
        name="+index"
        facet="branches"
        for="canonical.launchpad.interfaces.ICodeReviewMessage"
        class="canonical.launchpad.browser.CodeReviewMessageView"
        permission="zope.Public"
        template="../templates/codereviewmessage-index.pt"
        />

This specifies that

  1. The default view for canonical.launchpad.interfaces.ICodeReviewMessage is named +index

  2. The pages we're configuring are for canonical.launchpad.interfaces.ICodeReviewMessage

  3. The pages we're configuring use canonical.launchpad.browser.CodeReviewMessageView

  4. The branches facet should be used. This controls certain aspects of display.

  5. The launchpad.View permission is required to view the view

  6. The +index view name is associated with the template ../templates/codereviewmessage-index.pt