One of the fundamental features of a wiki is the ability to edit the page just
by clicking “Edit This Page”. That and the wikispam that follows... hopefully,
spammers won’t find your wiki before we’re done with it!

Now that we have our view, we need to update our controller in order to display
the form and handle the form submission. For displaying the form, we’ll add an
edit method to our controller:

Tip

If you’re copying/pasting the code below, you must ensure that
it goes in the Root class. This means you need to indent it.
Ensure your editor is putting in all spaces for indention rather
than a mix of tabs and spaces. Finally, remember to repeat this
for all the samples, especially if you get a 404 error. There’s
a “watch the indent” as a reminder, but people still get tripped up.

That should do it! Reload the page in your browser, and you’ll see the edit
link. Follow that link, and you’ll get a page that lets you edit. Don’t
click that save button, yet! We still need to write that method.

Unlike the previous methods we’ve made, this one is just @expose()‘d
without any template specified. That’s because we’re only redirecting the
user back to the viewing page.

A transaction is set up for us implicitly, if our database supports
transactions.

You can see for yourself... if you were to add raiseValueError after
page.data is set in that method, you’ll see that the data is not actually
saved in the database. If no exception is raised, the data is committed.

If an exception is raised, the changes are rolled back. The exception to this
rule is with redirects: they short-circuit execution of the method, but they
don’t count as “errors.”

The page.data=data is all it takes to create the appropriate UPDATE SQL
statement.

The turbogears.flash() call is setting a notification message to appear
in the user’s browser on the next screen. You’ll see a reference to the
tg_flash variable in the master.kid template.

Since a redirect is raised as an exception, all other processing is
short circuited. Very handy!

Go ahead and try it out! You can make changes and save the page we were
editing. Pretty wiki-like, no?