Announcing Django scaffold

April 20, 2010

I've been working on a new, reuseable Django app calld scaffold. It aims to solve what I see as a common problem: you're building a site that needs sections and subsections. You not only need to be able to manage that hierarchy, but also hang other content off of it. More details on the project page. Suffice to say it builds off of Gustavo Picón's django-treebeard app and has, what I think are some pretty cool features. It's very alpha, but I hope to get a release candidate within a month. (This is also the first time I've worked with git, and I have to say, I'm really loving it.)

Tagged with: , .

Correction re: Django caching

March 2, 2010

OK, so after reading the Django source code a little more closely, I found I was wrong. It absolutely is possible to invalidate the per-view caching. Here's a function I wrote to do it:

def expire_view_cache(view_name, args=[], namespace=None, key_prefix=None):
    """
    This function allows you to invalidate any view-level cache.
        view_name: view function you wish to invalidate or it's named url pattern
        args: any arguments passed to the view function
        namepace: if an application namespace is used, pass that
        key prefix: for the @cache_page decorator for the function (if any)
    """
    from django.core.urlresolvers import reverse
    from django.http import HttpRequest
    from django.utils.cache import get_cache_key
    from django.core.cache import cache
    # create a fake request object
    request = HttpRequest()
    # Loookup the request path:
    if namespace:
        view_name = namespace + ":" + view_name
    request.path = reverse(view_name, args=args)
    # get cache key, expire if the cached item exists:
    key = get_cache_key(request, key_prefix=key_prefix)
    if key:
        if cache.get(key):
            cache.set(key, None, 0)
        return True
    return False    

You can use it like this:

from project_utils import expire_view_cache

def invalidate_blog_index(sender, **kwargs):
    """Invalidate the view-level cache for the blog:index page"""   
    expire_view_cache("index", namespace="blog")   

post_save.connect(invalidate_blog_index, sender=Entry)

The is a pretty naive example, but basically whenever a blog entry is saved, the view-level cache for the blog index page is invalidated. Obviously you could be much more sophisticated with this. Per-view caching aside, I am quite sure that template fragment caching can only be invalidated when the TTL expires. That's a shame, but the per-view caching is far more useful anyway in my opinon.

Tagged with: , .

Don't get me wrong about Django's caching framework...

March 2, 2010

...it's hugely useful. But some of those tools that make life so easy, like per-view caching or template fragement caching are hampered by the fact that they don't offer any way to handle invalidation. The process by which they generate cache keys is not exposed to the user, and if you don't know they key, you can't invalidate the cache. It would be nice to provide some hooks so that a function which recieves a model update signal could expire all instances where that model may have been cached. The only workaround? Roll your own with the low-level framework (which means more LOC in your project) or just don't invalidate and let things expire on their own. Neither approach is optimal.

Tagged with: , .

Cloning and copying Virtualbox machines...

February 9, 2010

...is way harder than it should be.

Music & ritual

February 3, 2010

Robert Ashley, writing in Outside of Time: Ideas about Music:

This is our situation today. And it's not much fun. Because the composer does not have the idea of including the people who come while the music is being enacted. We have lost the idea of the rituals that remind the people who come that what is happening is only a small part, a "surfacing" of the continuing musicality of everyday life.

Actually, those rituals do not exist, except in television and probably in sports events. Everybody plays baseball or football or basketball or soccer or hockey (or wishes they did or thinks they do) so the game is only a "version" of what is part of your life. You are emotionally in it. That is what I mean by ritual. Everybody does not go around singing Mahler or Ives or Feldman or Palestrina. The music is foreign to you. Interesting, maybe, but foreign, like the gamelan. You are not in it. Mostly music students go to recitals. This is true, maybe more so, even if the music is all by living composers. Not that we should expect huge audiences for recitals. But we should expect that the audience is a part of the music, and this is not true, even if the audience is entirely music students. This is the dilemma of contemporary music. The ritual has disappeared. The event is hollow.

(h/t Kyle Gann)

Tagged with: .

The NYT acknowledges reality

January 16, 2010

Looks like the NYT is going to start charging for its content. I'm sure a lot of people are going to criticize them for this, but count me out. If they do this right, I think it could actually work. What not to do:

  • Don't charge the same price for print and digital versions. Record labels tried this, and people saw right through it.
  • Don't charge for content no one wants (e.g. TimesSelect: sorry but I'm really not interested in paying to read the opinions of Maureen Dowd or David Brooks)
  • Don't charge for wire-service type content
  • Don't make it all or nothing the way the WSJ does

Some sort of micropyaments scheme would be fine with me though. I understand that good journalism is not cheap. Just maintaining a foreign bureau is massively expensive (but obviously vital), and I'm glad the Times has realized that the vicious cycle of cost cutting to save money, then losing readers because the quality of their product suffers is unsustainable: it's a race to the bottom. (I'm also glad that they haven't hitched their star to some harebrained scheme to extort money from Google.) If they are the only paper to go this route, it may not work, but if they can get some other major publications on board, we'll see what happens. Either way, it's a hard road ahead for them, and I hope it works.

Tagged with: .

Back to the drawing board, indeed

January 16, 2010

As usual, Roy Edoroso gets it right:

In a way, Obama has no one but himself to blame. He signed on to those stupid bailouts in 2008, and has been fatally hampered by their economically injurious legacy every since. [...] In another way, you can't blame Obama or even the dummies that ran Coakley's campaign. It was almost touching the way he expected people to hold on and continue to trust their 2008 instinct that, now that things were tough, the major surgery they'd been putting off could no longer be avoided. He must be disappointed at how quick they got cold feet. Cynical as I am, I'm amazed; you'd think that, when America ran out of funny-money and banks started to collapse, they'd have been forcefully shaken out of their faith in the fairy story with which Republicans had been swaying them for years -- that they could fix any mess with some tax cuts and magic beans -- and for a good long while. But in little more than a year, a lot of them are going for it all over again.

It's easy to denounce the cowardice and fecklessness of our elected officials, but we elected them, after all. We really do get the government we deserve.

Tagged with: .

Homemade Lumpia

January 16, 2010
Tagged with: .

A new album

January 16, 2010

On Alex Ross' recommendation, I grabbed a copy of Stile Antico's Song of Songs on the Harmonia Mundi label. Not much to say beyond wow. It's a collection of Renaissance-era settings of The Song of Songs by composers including Vivanco, Palestrina, Gombert and others. The singing is gorgeous: perfect intonation, crystal-clear diction; you really get the sense of an ensemble that's completely in sync. These guys are right up here with the Hilliard Ensemble or the Tallis Singers and I look forward to exploring more of their output. Check out a sample track on Alex's site: Clemens non Papa's Ego flos campi.

Tagged with: .

Are there a lot of broken links on this blog?

December 30, 2009

Yes, there are. And they're all ones that link to internal content. When I ported this over, I forgot to update all links from the somewhat eccentric schema used in the previous blog to the new one. I'm getting to them, slowly but surely.

Tagged with: .

Mmm, homeade chicken soup

December 19, 2009

Coming up in, oh, half an hour. Decided to roast the vegetables in the oven wih a little pancetta, then add them to the stock.

Tagged with: .

We're getting a lot of snow here...

December 18, 2009

1.5 feet and counting

Tagged with: , .

This is rather depressing...

December 18, 2009

Was this decade really that bad?

Relaunch'd!

December 17, 2009

Well, I'm two days late for the #sitesprint deadline, but that's not too bad given how busy things are. Expect too see some rough edges here and there (and lots of broken images) which I'll get around to fixing over the next 2 days.

Tagged with: .

Hello World!

December 17, 2009

This site is now being hosted by webfaction.