Hi Mark,

That is a nice example of TG2.  This is the first chance I've had to  
play with TG2, and had to make a few modifications to the A2python  
controller to get it to work.  Patch as well as updated controllers/ 
root.py attached.  I'm using latest svn trunk of tg and pylons as of  
this morning (Py 2.5).

Cheers,
Chris Miles


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: A2python_controller.patch
Description: Binary data

from tg import expose, validate, TurboGearsController
from pylons.helpers import redirect_to
from a2python.models import Page
from docutils.core import publish_parts
import re
from sqlobject import SQLObjectNotFound

wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)")
        
class RootController(TurboGearsController):
    @expose("kid:a2python.templates.page")
    def index(self, pagename="FrontPage"):
        try:
            page = Page.byPagename(pagename)
        except SQLObjectNotFound:
            redirect_to("notfound/%s" %str(pagename))
        content = publish_parts(page.data,
                                writer_name="html")['html_body']
        content = wikiwords.sub(r'<a href="%s\1">\1</a>' % '/', content)
        return dict(data=content, page=page)

    @expose("kid:a2python.templates.edit")
    def notfound(self, pagename):
        page = Page(pagename=pagename, data="")
        return dict(page=page)

    @expose(template="kid:a2python.templates.edit")
    def edit(self, pagename):
        page = Page.byPagename(pagename)
        return dict(page=page)

    @expose("kid:a2python.templates.pagelist")
    @expose("json")
    def pagelist(self):
        pages = [page.pagename for page in Page.select(orderBy=Page.q.pagename)]
        return dict(pages=pages)

    @expose()
    def save(self, pagename, data, submit):
        page = Page.byPagename(pagename)
        page.data = data
        redirect_to("/%s" % str(pagename))

    @expose("kid:a2python.templates.page")
    def default(self, pagename):
        return self.index(pagename)
    
    @expose()
    def createtables(self):
        Page.createTable()
        return"tables created"    
On 9 Jul 2007, at 04:03, Mark Ramm wrote:

> Attached is a 20 min wiki port to TG2 I did this week for a talk at
> the Ann Arbor Python Users Group.
>
> I'd call it the 2 min wiki, but that's just for fun.   I copied
> quickstarted a new tg2 project, copied model.py content over, and
> updated it to use the SQLObject PackageHub from Pylons (which is just
> like the old TG).  copied my controllers content into my new
> controllers.py, removed turbogears imports and replaced them with the
> right thing,   I updated my package name everywhere (I could have
> skipped this step if I'd named the new package the same as the old
> one).   And finally I replaced  redirection by exception (raise
> redirect) with the new tg2 style redirect_to() function.
>
> I also found a bug in template inheritance, which I haven't tracked
> down, so I removed references to master.kid from my templates, but
> otherwise left them unchanged.
>
> The whole process was pretty quick and painless.
>
> We've got a ways to go with tg2, but I think we're on the right track.
>    Backwards compatibility won't be 100% but porting applications
> should be remarkably simple.
>
> -- 
> Mark Ramm-Christensen
> email: mark at compoundthinking dot com
> blog: www.compoundthinking.com/blog
>
> <A2python.zip>

Reply via email to