Ian Lewis Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development.
About Me...

python-openvcdiff and Cython

I started a project today to implement an interface for the open-vcdiff using Cython. I'm not a C++ master and the Python C libraries are pretty new to me but I managed to expose and implement a few methods of the VCDiffEncoder class. The hardest part so far has been trying to figure out how to use the C++ standard library types like std::string. I'm also not sure how I can interface with pyt[...]

Parsing email with attachments in python

Recently I needed to be able to parse out attachments and body from multipart emails and use the resulting data to post to a service. So I wrote the code below to parse out text and html portions of the email and also parse out attachments. The code below is the result. I used a StringIO object from the python StringIO module to hold attachment data because the PIL module seemed to not be ab[...]

Transactions on Appengine

The way to store data on Appengine is with Google's BigTable Datastore which has support for transactions. However, the transactions are quite limited in that, 1. You can only execute callables inside transactions. Which means you basically call run_in_transaction() on a function. This can sometimes be a pain but can generally be worked around with decorators and the like. def my_update_[...]

Werkzeug and reverse urls

I wanted to impove a Google Appengine application that a friend of mine created (ほぼ汎用イベント管理ツール(jp)) and noticed that he was redirecting directly to urls. He is using Werkzeug to handle url routing so I wondered if there was a method for generating urls from a name like you can in Django. It turns out you can but you give it an endpoint name rather than a url name. urls.py from werkzeug.rou[...]

Field/column Queries in Django

One of the neat things making it's way into Django 1.1 is F object queries. The F object is kind of like the Q object as it can be used it queries but it represents a database field on the right hand side of an equality/inequality. For the example I'll use the example models from the "Making Queries" section of the Django Documentation. class Blog(models.Model): name = models.CharField[...]

Python date range iterator

I couldn't find something that gave me quite what I wanted so I created a simple Python generator to give me the dates between two datetimes. def datetimeIterator(from_date, to_date): from datetime import timedelta if from_date > to_date: return else: while from_date <= to_date: yield from_date from_date[...]

Introduction to Algorithms

Today my copy of Introduction to Algorithms came in the mail (a gift from the family). I've decided, mostly inspired by Peteris Krumins to revisit classic algorithms as it's been a while since I've taken a look at them. I have decided to also take a look at the MIT Intro to Algorithms course in order to revisit algorithms and concepts. I won't provide any lecture notes or anything since Pete[...]

Django Sitemap Framework

Using the Django sitemap framework is so easy it's almost no work at all. Just make a sitemap object and add it to the sitemap in urls.py. The sitemap framework calls items() in your Sitemap to get the list of objects to put in the sitemap and then calls get_absolute_url() on each object. #### models.py from django.db import models ... class Entry(models.Model): ... @permalink [...]

Django admin inline forms

For my new project dlife (Update: Now django-lifestream), I went about implementing a simple comments interface that would allow users to make comments on imported feed items. I wanted to support this in the admin in the typical manner such that when you click on an item in the admin, you can see all the comments and edit them from the item's page. I found that you can use inline forms in th[...]

Feedparser and Django

Over the weekend at Python Onsen I worked on a lifestream web application using Django and feedparser. I was really impressed with how simple feedparser is to use and how easy it is to get unified results from atom or rss feeds. You simply import feedparser and call feedparser.parse to parse a feed from a url. feeds.py ... def update_feeds(): feeds = Feed.objects.filter(feed_deleted=Fal[...]