Posts

Showing posts with the label Python

Tagging with Appengine DataStore

I've been looking into how to implement a tagging mechanism with Appengine (Python). By using a StringListProperty, you can associate a list of tags with an entity. The model would look something like this: from google.appengine.ext import db class Sample(db.Model): name = db.StringProperty(required=True) tags = db.StringListProperty() Now, assuming we want to find the entities tagged with a given word, we can use a query like this: q = db.GqlQuery("SELECT * FROM Sample where tags = :1",'z') If we want to find all entities that have ANY of these tags (OR) we can query with GqlQuery or filter: q = db.GqlQuery("SELECT * FROM Sample where tags in :1",['a','z']) q = domain.Sample.all() q.filter("tags in ", ['b','d']) When we want to find entities with ALL of the given tags: q = db.GqlQuery("SELECT * FROM Sample where tags = :1 and tags = :2",'b','c') q = domain.Sample.all() q.filter(...

No module named _multiprocessing

I'm getting back into appengine at the moment, and I came across this error: No module named _multiprocessing A google search turned up this error report: http://code.google.com/p/googleappengine/issues/detail?id=1504 which lead to this post: http://code.google.com/p/soc/wiki/GettingStarted The problem was of-course, that I was using Python 2.6 instead of 2.5. I love Linux, the solution is trivial: The workaround for this is to install Python 2.5 on your machine. It will be then be accessible by using python2.5 on the command line. Then open thirdparty/google_appengine/dev_appserver.py in your favorite text editor and replace the first line, #!/usr/bin/env python with #!/usr/bin/env python2.5 Note, I already had Python 2.5 installed via: sudo apt-get install python2.5 Now, I'll promptly get back to figuring out how best to use DataStore to implement my solution!

MyOnlineProfile.net launches

MyOnlineProfile.net  has launched - as a Google  AppEngine  application. MyOnlineProfile lets you catalog your public online profiles in one place - leaving you with just one link to give your friends and one link in your email signature. I first wrote MyOnlineProfile as a  Grails  application - its a small application at the moment, so it didn't take long. However I did over-engineer it. I made the classic mistake of trying to solve the wrong problems and over-optimising. Luckily with being a small application and written with such a productive framework, I'm only talking about wasting hours rather than months. I deployed it to my Linux VPS, but unfortunately,  Java  based applications take up quite a bit of resources just starting up and memory on a VPS costs money (recurring money). So there just wasn't room for it. Hence re-writing it in  Python  for AppEngine. Being exposed to Python has been good for me - and relatively easy sin...

Prototype, JSON and Appengine

I am using prototype in a Google Appengine project, and while it worked on my development machine, after deploying it onto the Google infrastructure prototype wasn't parsing the JSON responses anymore. In my code, I was returning the JSON in the response text (as opposed to using X-JSON response header). The Content-Type response header was set as application/json and my javascript code used Ajax.Request() with the parameter evalJSON:true so as to parse the response text. Running locally with the dev_appserver.py everything worked okay. However when running the deployed app, the Content-Type header was no longer being set - meaning that prototype would never parse the response text. I'm not sure why Content-Type doesn't get set when running on the Google infrastructure yet it works on the development server. But, luckily when using Ajax.Request, you can specify evalJSON:'force' so that prototype parses the response regardless of the content-type. Server ajax respons...