Posts for Wednesday, 01 June 2011

Random Library Art

One of the patrons in our library left this drawing up on one of the writable wall space.

From Just Life

It's a great piece really and in particular the proportions are very good on the figure, it manages to convey a sense of perspective for such a simple drawing.

The saddest part of the whole thing though is the red line across the chest.  Seems like this was just a simple sketch of a girl sitting by a tree but someone was so threatened by breasts that they had to erase them and draw that red line across the space.  Perhaps that was part of the original art and a statement but I kind of doubt it. Sad really.

Wordpress to Django: Strategies Dealing with Wordpress Querystring URLs

Stable URLs are the foundation of valuable information on the web.  As Tim Berners-Lee eloquently described it "Cool URIs Don't Change" and I thought I'd address a few strategies and code I'm using in MetaRho for maintaining stable URLs for content migrating from Wordpress.

Wordpress Querystring URLs

By default Wordpress uses querystrings for accessing content, passing the internal ID number of the post through the 'p' attribute like so...

http://<domain name>/index.php?p=<post id>

So for example calling post id 1 on mydomain.com would look like.

http://www.mydomain.com/index.php?p=1

Since best practice for Cool URIs and in Django is to use real URLs instead of Querystrings this presents a small problem.  The easiest solution I found is to simply implement a decorator in Django that I put on the default index view to watch for incoming WordPress querystring URLs and query some extra field on the model for blog posts that holds the original WordPress ID number.  Note I do NOT try to maintain ID numbers between posts as the better practice is to keep these opaque from the user.

I use the common strategy of keeping a one to many Model related to my posts to contain key value pairs for extra data.  In my implementation I call that Model PostMeta and when I import content I just store the original WordPress ID number under a key 'wp_post_id'.

(view code on github)

def wp_post_redirect(view_fn):
    '''
    Checks a request for a querystring item matching a WordPress 
    post request.
    
    This is to enables url redirects for blog migrations from WordPress.
    To use just decorate the view method for your default blog location.
    
    '''
    def decorator(request, *args, **kwargs):
        wp_query = request.GET.get('p', None)
        if wp_query:
            try:
                post = Post.objects ...
(Read More)