September 06, 2010

shabti_quickwiki – Pylons QuickWiki, using elixir

QuickWiki is the standard introductory Pylons tutorial project. In this template, the Page model is expressed in Elixir.

Note

shabti_quickwiki source code is in the bitbucket code repository

The Page model in vanilla SQLAlchemy

Here is the Page model in vanilla SQLA.

pages_table = Table('pages', metadata,
    Column('title', types.String(40), primary_key=True),
    Column('content', types.String(), default='')
)

class Page(object):
    content = None

    def __str__(self):
        return self.title

    def get_wiki_content(self):
        content = publish_parts(self.content,
                            writer_name="html")["html_body"]
        titles = sets.Set(wikiwords.findall(content))
        for title in titles:
            title_url = h.url(controller='page',
                                  action='index',
                                  title=title)
            content = content.replace(title,
                                h.link_to(title, title_url))
        return content

mapper(Page, pages_table)

The Page model in Elixir

In this template, it is expressed in Elixir DSL:

class Page(Entity):
    title = Field(Unicode, primary_key=True)
    content = Field(Unicode, default='')

    def __str__(self):
        return self.title

    def get_wiki_content(self):
        content = publish_parts(self.content,
                            writer_name="html")["html_body"]
        titles = sets.Set(wikiwords.findall(content))
        for title in titles:
            title_url = h.url(controller='page',
                                  action='index',
                                  title=title)
            content = content.replace(title,
                                h.link_to(title, title_url))
        return content

Using the template

Dependencies for this template are SQLAlchemy>=0.5 and Elixir>=0.6.1.

After successfully installing Shabti, additional paster templates will be available. Simply create a Shabti-configured project by specifying that paster should use the shabti_quickwiki template:

$ paster create -t shabti_quickwiki myproj

These are the option dialogue choices appropriate for the Shabti quickwiki template — which uses mako templates and SQLAlchemy ...

(mako/genshi/jinja/etc: Template language) ['mako']:
(True/False: Include SQLAlchemy 0.4 configuration) [False]: True
(True/False: Setup default appropriate for Google App Engine) [False]:

Once the project has been created, navigate to the project directory and run the (brief) test suite:

$ nosetests

5 tests should executed successfully - 1 error. If the tests succeeded, the next step is to initialise the quickwiki store by running the project setup script:

$ paster setup-app development.ini

Once the store has been inialised, start the Pylons web app with:

$ paster serve --reload development.ini

The Shabti Authkit Demo template’s variant on the standard Pylons welcome screen is browsable at at http://localhost:5000/ ...

Screen shots

Welcome Page

The standard welcome page (myapp/public/index.html)

../_images/shabti_quickwiki_welcome.jpg

Wiki FrontPage

The wiki page FrontPage which was created when paster setup-app development.ini is executed.

../_images/shabti_quickwiki_frontpage.jpg

QuickWiki page list

The drag’n’drop-to-delete List of Titles. The javascript seems to have stopped functioning. The codebase has moved on and it’s something you’d want to do in JQuery these days.

../_images/shabti_quickwiki_titlelist.jpg

Notes on the template

What can you say? It’s the “Hello Wiki” tutorial example spruced up to work with Pylons 0.9.7 and expressed in elixir.

author:Graham Higgins <gjh@bel-epa.com>

September 06, 2010