Programmatic arguments to an UrlBoundView

Usually, an UrlBoundView gets its arguments from the current URL. These are passed into its assemble() method by the framework. In some cases it is useful to pass arguments directly from your code to assemble().

For example, in the tutorial.parameterised1 example the parameterised EditView is used in AddressBookUI.assemble:

class AddressBookUI(UserInterface):
    def assemble(self):
        home = self.define_view('/', title='Show')
        add = self.define_view('/add', title='Add')
        edit = self.define_view('/edit', view_class=EditView, address_id=IntegerField())

        home.set_slot('main', AddressBookPanel.factory(self))
        add.set_slot('main', AddressForm.factory())

        bookmarks = [f.as_bookmark(self) for f in [home, add]]
        self.define_page(AddressBookPage, bookmarks)

        self.define_transition(Address.events.save, add, home)
        self.define_transition(Address.events.update, edit, home)

        self.edit = edit

    def get_edit_bookmark(self, address, description=None):
        return self.edit.as_bookmark(self, address_id=address.id, description=description)

You might want to include a link on EditView for some or other Bookmark that is created in your code at this point.

If you want to do that, just pass your Bookmark as another keyword argument to enable_refresh(). Keyword arguments of enable_refresh() that are not instances of Field are passed unchanged through to matching keyword arguments to the EditView.assemble.

So, if you did:

edit = self.define_view('/edit', view_class=EditView, address_id=IntegerField(), some_bookmark=a_bookmark)

You can change your assemble() signature like this:

def assemble(self, address_id=None, some_bookmark=None):

… and then your Bookmark will be accessible as some_bookmark.