Are you working on the twenty minute wiki tutorial? I'll assume yes.

"Deleting a wiki page" could mean a few different things.

At the lowest level, a wiki page is stored as a row in a database table
named 'page'. Each database engine will provide utilities for viewing
and manipulating the data it manages. If, for example, you're working
with MySQL, you could use the mysql command line utility. A typical
session would look something like this...

(I'm hoping google groups "Fixed Font" will format this properly)

    $ mysql -u root -p wiki20
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 6 to server version: 4.1.15

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql> select * from page;
    +----+-----------+------+
    | id | pagename  | data |
    +----+-----------+------+
    |  1 | FrontPage |      |
    +----+-----------+------+
    1 row in set (0.00 sec)

    mysql> delete from page where id = 1;   -- Deleting 'FrontPage'
    Query OK, 1 row affected (0.05 sec)


One level up from your database, you'll find your SQLObjects.
TurboGears provides convenient interactive access to your Page
SQLObject by running 'tg-admin shell' at the command line. Running this
command drops you into a python interpreter. If you're new to python,
now would be a great time to take a minute to read
http://diveintopython.org/installing_python/shell.html. If you're new
to SQLObject, http://sqlobject.org/SQLObject.html will give you a lot
of insight on how to use your Page class. If you're new to relational
databases, get your feet wet by reading the first two chapters (at
least) of this manuscript.

Now where was I...Oh, I was telling you to run 'tg-admin shell' at the
command line (and make sure you're in your project's home directory).
Here's a python session equivalent to the mysql session above:

    >>> list(Page.select())
    [<Page 1L pagename='FrontPage' data=''>]
    >>> Page.delete(1)   # deleting 'FrontPage'

Another layer up from SQLObject, you'll find your root controller. You
can easily expose (more on this in a moment) a delete method on your
root controller by adding the following (untested) code.

    @turbogears.expose()
    def delete(self, pagename):
        try:
            Page.byPagename(pagename).destroySelf()
            turbogears.flash('Deleted %s.' % pagename)
            raise cherrypy.HTTPRedirect('/')
        except SQLObjectNotFound:
            raise cherrypy.HTTPRedirect('/notfound?pagename%s' %
pagename)

I didn't test this method, so you'll probably have to correct
something. It's missing imports at the least, and I suspect I have the
capitolization wrong on HTTPRedirect and SQLObjectNotFound. Oh, you'll
also see it's using a different SQLObject method for deleting an object
from the database. Since I don't know the page's id, this is a simpler
(from a coding perspective) mechanism for deleting a page from the
database.

One last note...'expose' has a very precise meaning in TurboGears.
Basically it means, make this method available to web browsers. If this
seems very opaque, read this:
http://www.turbogears.org/about/cherrypy.html. If that doesn't satify
you try reading this: http://www.cherrypy.org/wiki/CherryPyTutorial


Hope you find something in here helpful,
Levi

Reply via email to