Embedded webapp mini profiler

If your’re ASP.NET MVC developer you should already know about MVC Mini Profiler released by Stack Overflow, if you don’t, go get it now.

Google App Engine developers have the appstats, a tool that does similar things but requires you to explicitly look for profiling info.

Now GAE has mini-profiler to — this is old news apparently 😉 — an appstats wrapper mini app that you can embed in your web app, check out Google App Engine Mini Profiler and have stats in your face, all the time.

JSON serialization of Google App Engine models

For some AJAX requests you’ll need an rpc urls returning a serialized objects. In principle its simple just use JSON serialization build in in Django or simplejson module itself. Here are sample view methods:

def entity_list(request, entity_key=None):
    user = users.get_current_user().email().lower();
    col = models.Entity.gql('WHERE user=:1',user).fetch(300, 0)

    json = serializers.serialize("json", col)
    return HttpResponse(json, content_type='application/json; charset=%s' % settings.DEFAULT_CHARSET)

def entity_autocomplete(request):
    user = users.get_current_user().email().lower();
    col = models.Entity.gql('WHERE user=:1',user).fetch(300, 0)

    json = simplejson.dumps(col)
    return HttpResponse(json, content_type='application/json; charset=%s' % settings.DEFAULT_CHARSET)

But there’s a catch. Django will only serialize properties no other fields (eg. computed fields or properties) will be serialized, and simplejson will complain that your Entity is not serializable. Continue reading “JSON serialization of Google App Engine models”