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 helloworld.py a bit (original):

from simpletemplate.google 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'
        else:
            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)
        self.response.out.write(template.render(template_values)

And finally lets change index.html to read:

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

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

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

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.