Andy McKay

Apr 08, 2008

Google Web Apps, first look

With some fanfare Google Web Apps have been launched. This is great because its using Python and Django, how much more perfect can it get. This morning I've been having a play and I'm just waiting for my account so I can upload something.

Would be nice to take my (as yet unreleased) Plone to Django conversion script, plonk the result on Google Web Apps and then link up a nice little Adobe Air app. Anyway two things that irked me (of course I'm going to complain): 1) the example Python all has two spaces as the indent and 2) it uses Django templating.

Fortunately it says:

You can bundle a framework of your choosing with your application code by copying its code into your application directory

And looking at later comments, it's not going to block a module like simpletemplates, which I use for templating in Django. So. lets alter a bit (original):

from import DjangoSimpleTAL

And change the MainPage class to read (only changed last two lines):

class MainPage(webapp.RequestHandler):
    def get(self):
        greetings = Greeting.all().order('-date')

        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        template_values = {
          'greetings': greetings,
          'url': url,
          'url_linktext': url_linktext,

        path = os.path.join(os.path.dirname(__file__), 'index.html')  
        template = DjangoSimpleTAL(path)

And finally lets change index.html to read:

        <tal:loop repeat="greeting greetings">
            <tal:block condition="greeting/author|none">
                <b tal:condition="">Author</b> wrote:
            <tal:block condition="not:greeting/author|none">
                An anonymous person wrote:
            <blockquote tal:content="greeting/content">Comment</blockquote>

        <form action="/sign" method="post">
            <div><textarea name="content" rows="3" cols="60"></textarea></div>
            <div><input type="submit" value="Sign Guestbook"></div>

        <a tal:attributes="href url" tal:content="url_linktext">Login</a>

And things seem to work just dandy. For those who do use simpletemplate, the google module isn't in SVN yet, and needs a bit of work, but just a quick refactoring of the simpletemplate code to be friendly with the new imports that the Google app server uses.

Update: by the time my blog post was done, my account was activated. Unfortunately I have to work today though.