Archive for May, 2008

A little Django flatpage trick

May 31, 2008

For each general area of my humble little website, I have a base template that takes care of a links bar and breadcrumbs and things. All the individual pages in that area extend that base.html, which in turn extends parent base templates. Nothing unusual there, and all well and good.

Except for flatpages. Flatpages are great, but out of the box they’re a tiny bit rigid. I want a flatpage in a particular area to extend the right base.html, but that’s not quite what the flatpage template setting provides—that’s a whole template, and I just want a base to extend. One could of course have a different flatpage template for each base.html, but that’s gross, and not very DRY.

Maybe there is some simple obvious way to do this built in to Django, but I couldn’t find it. My solution is to extract the appropriate base template from the flatpage itself. I put it in a django comment, which will get stripped out of the content before rendering. So the line

{# Base utilities/base.html #}

goes in the body of the flatpage, and gets extracted with a filter. [It might be better to infer it from the page’s url, if one’s directory structure and url structure always match.] The only problem is that I need the filter loaded before the extends tag, and the extends tag needs to come before anything else. It used to be possible to load before extending, but that was an evil (if useful) loophole, now closed.

Like all problems in computer science, this can be solved with another level of indirection. flatpages/default.html loads the filter and extracts the base template name, and then includes another template to do the actual rendering.

Here’s the code, simple and completely non-robust though it is. In a tempatetags/ or whatever you want to call it:

def stripdjangocomments(text):
    Strip django comments from the text.
    s = re.sub(r'{#.*?#}', '', text)
    return s

def getbase(text, default = "base.html"):
    Look for a string of the form {# Base foo #} and return foo
    m ='{#\s*Base\s*(\S*?)\s*#}', text)
    if m and m.groups()[0]:
        return m.groups()[0]
        return default

In templates/flatpages/default.html

{% load flatpage_utils %}

{% with flatpage.content|getbase as pagebase %}
{% include "flatpages/flatpagebody.html" %}
{% endwith %}

And in templates/flatpages/flatpagebody.html

{% extends pagebase %}
{% load whatever_else %}

{% block title %}
{{ flatpage.title }}
{% endblock %}

{# maybe other stuff #}

{% block content %}
{# add more filters if you like #}
{{ flatpage.content|stripdjangocomments }}
{% endblock %}

And that’s it.


Democrats. Bah.

May 31, 2008

The Democratic Party will be deciding today what to do about those pesky scoffrules in Michigan and Florida and their alleged delegates. They seem to be expending on awful lot of effort on figuring out details that just don’t matter—we all know Obama’s going to win, and the only real question is how quietly will Hillary go, and when. I suppose the theater is all about determining the exact level of respect Hillary and her legions of rabid supporters are entitled to. Sort of like mob boss negotiations in a more boring version of The Sopranos.

Oh, and the Democrats are also trying to un-piss-off the people of Michigan and Florida. To the people of Michigan and Florida I have two things to say: “Blame your idiot legislatures,” and “Oh, come on, your votes don’t count anyway.”

Should the Democratic Party’s motto be “It Seemed Like A Good Idea At The Time”? Regretting old decisions seems to be the party’s normal practice now. Besides the ill-considered proscription of large ornery states, we also have the decision to allocate delegates proportionally rather than winner-take-all, and of course the superdelegates.

And while I’m ranting about wasting time and energy, how about money? Wouldn’t the hundreds of millions spent so far, and yet to be spent, in this election have been better spent feeding the hungry? Sheltering the homeless? Aiding Chinese earthquake victims? Heck, buying every American a nice cup of coffee? If only Obama could use his superhuman fundraising powers for good…

John Hagee

May 29, 2008

It doesn’t particularly bother me that John Hagee thinks that “Hitler was fulfilling God’s Will.” That’s pretty conventional theology, really; if you believe in an omnipotent God, you’re sort of stuck with believing that everything is fulfilling God’s will. What does bother me is Hagee’s smug certainty that he knows what God’s will is.

I would talk about Hagee’s (and Biblical “literalists” in general) appalling Biblical interpretational practices, but I don’t have the heart right now.

Hagee is certainly not an anti-Semite, not in the classic sense of Hitler or Mel Gibson. But were I Jewish I don’t think I’d be too quick to cozy up to him. He is a staunch supporter of Israel, but not because he’s particularly interested in a Jewish homeland per se, or because Israel is a lone beacon of democracy and enlightenment values in an unstable region, or anything like that. He supports Israel because he is a Dispensational Premillennialist, who thinks that the return of the Jews to the promised land is a necessary condition for Armageddon, the Rapture, the Tribulations, and the subsequent thousand-year reign of Christ on Earth.

And as far as Hagee’s attitude towards the Jewish people themselves, well, he certainly doesn’t think that they’re Them As Kilt Our Lord or anything; as far as he’s concerned God’s cool with them. But eventually they’re going to have to accept Jesus as their Personal Lord and Savior if they want to avoid spending eternity in a lake of boiling blood, or whatever God Hagee has in store for the damned.

I suppose I’m pleased that John McCain has repudiated Hagee, although it’s not like he did it for the right reasons. [Well of course he didn’t; as a politician the only reason he does anything of the sort is because of what he thinks it will do to his chances in the election.] But what’s up with Joe Lieberman? People of Connecticut, aren’t you ashamed?

Another reason to despise Hagee—I’m sure there are many—is his association with the televangelical “prosperity gospel“: the doctrine that God wants you, the faithful, to prosper materially, if only you prove your faith by, oh, sending money to John Hagee. How any thinking person can reconcile such an abomination of a doctrine with anything in the New Testament, and with most of the Old, is beyond me.

Important note: throughout this post I’ve been using phrases like “Hagee thinks” in a figurative sense. I do not know what Hagee thinks. I am pretty sure I don’t want to know what Hagee thinks. I do not have any reason to think that he has sufficient integrity for us to assume that what he says to reflect in any meaningful way what he thinks.

Unicode, Browsers, Python, and Kvetching

May 28, 2008

My HTML/unicode character utility is now in a reasonably usable state. I ended up devoting rather more effort to it than I had originally planned, especially given that there are other perfectly useful such things out there. But once you start tweaking, it’s hard to stop. There are now many wonderful subtleties there that no one but me will ever notice.

What gave me the most grief was handling characters outside the Basic Multilingual Plane, i.e. those with codes above 0xFFFF. That’s hardly surprising. And I suppose it shouldn’t be surprising that browsers handle them so inconsistently. All the four major browsers try to display BMP characters using whatever fonts are installed, but not so for the higher ones. In detail:

  • Firefox makes a valiant effort to display them, using whatever installed fonts it can find. It’s fairly inconsistent about which ones it uses, though.
  • IE7 and Opera make no effort to find fonts with the appropriate characters. They do work if you specify an appropriate font.
  • Safari (on Windows) doesn’t display them even if you specify a font. This does not further endear Safari to me.

Oh, and on a couple of XP machines I had to reinstall Cambria Math (really useful for, you know, math) to get the browsers to find it. There must be something odd about how the Office 2007 compatibility pack installed its fonts the first time (I assume that’s how they got there).

On the server side, I knew I would have to do some surrogate-pair processing myself, and that didn’t bother me. Finding character names and the like was more annoying. I was delighted with python’s unicodedata library until I started trying to get the supplementary planes to work. The library restricts itself to the BMP, presumably because python unicode strings have 16-bit characters. The reason for the restriction is somewhat obscure to me—the library’s functions could presumably work either with single characters or surrogate pairs; and I’m pretty sure all the data is actually there (the \N{} for string literals works for supplementary-plane characters, for example).

The whole unicode range ought to work in wide builds of python, but I have no idea if that would work with Django and apache/mod_python and Webfaction, and I’m far too lazy to try. So I processed the raw unicode data into my own half-assed extended unicode library, basically just a ginormous dict with a couple of functions to extract what I want (so far just names, categories and things to come if I ever get around to it).

The Late George Apley

May 26, 2008

I married into a Boston Brahmin family. My parents-in-law and their set have an accent—and a way of life, really—I didn’t know still existed. My wife, although she herself resolutely avoids all Brahmin manners, had for some time been pestering me to read John P. Marquand‘s Pulitzer-Prize-winning satire The Late George Apley, that I might better understand her people, and because she thought I’d like it. As usual I finally gave in to the pestering, and as usual she was right.

The novel is in the form of a biography of George Apley, a recently deceased (recently in 1933), very proper Bostonian. This biography Apley’s son has commissioned Will Willing, an old family friend and distinguished author, to write, based on Apley’s letters and other papers, with special instructions not to produce the usual anodyne eulogy:

How would it be if these letters should tell the truth about him? Not that I insinuate you do not always tell the truth — I mean that on this occasion you may leave matters in the record which your conscience and loyalty might otherwise blot out.

Apley was born in 1867—making him, unbelievably, a contemporary of my grandfather-in-law (they bred very late in that family)—into a family that had made a great deal of money first from clipper ships and then from mills. In a sort of synecdoche for the progression of New England economic life, the family went from daring entrepreneurs to flinty industrialists to—well, not much of anything, really. Apley becomes a lawyer (Harvard-educated, of course) and his father and uncle, finding him too soft for mill management, find him a sinecure at a convenient law firm. Here Apley seems to practice very little actual law, instead leading a life mostly dedicated to fulfilling a myriad of social obligations, attending functions of his many clubs, serving on innumerable committees, and engaging in obscure disputes with family, fellow club members, and in one disastrous case, a wily politician.

The humor—and tragedy—of the novel lies in the fact that Apley really doesn’t want to do anything of the sort. From his youth he finds his family and his society have determined his entire life for him:

He once said of himself: “I am the sort of man I am, because environment prevented my becoming anything else.

After college he travels to Europe and England and finds only Bostonians. Much later he buys a lake island in Maine as a rustic getaway, only to have his wife and sister follow him and establish a set of rules and traditions as ridiculous and annoying as Boston’s social conventions. The only way a proper Bostonian can escape Boston is to leave it physically and never return, and that Apley cannot do.

More seriously Apley is not allowed to marry the only woman he really loves, an Irish—and hence utterly unsuitable—girl he meets at Harvard. Instead he pleases his family by marrying the woman they have long had in mind for him, the daughter of an impeccable (and infuriating) family.

And of course Apley internalizes all of his society’s strictures. In time he becomes one of Boston’s leading men, fighting to preserve the traditions that have so utterly trapped him. He is disappointed in his own son for not having proper respect for Boston society, and for committing the appalling sin of moving to New York.

The novel’s genius lies in the oblique way much of its story is told. Mr. Willing, our narrator, is himself a proper (and pompous) Bostonian, and shares none of Apley’s doubts about society. These he considers deplorable lapses in an otherwise stellar character, and he includes them only reluctantly, at the insistence of Apley’s son. The chapter describing Apley’s college love is subtitled “Dealing with a Subject Which Would Not Ordinarily Be Discussed in a Work of This Nature.” Telling information is revealed only in throwaway sentences. Here is all we ever hear of Catharine Apley’s appearance, in a letter from Apley’s father:

… her position and yours in the scheme of things are such that there will be none of the frictions due to divergent backgrounds, which might occur for instance in a New York and Boston union. You have shown the good sense, too, to realize that beauty is only skin deep and that there are more important elements in the holy bond of matrimony.

The novel paints a vivid portrait of the early twentieth-century Brahmins, living in shabby grandeur, lamenting and resisting progress at every turn, taking highly principled stands based on principles only they understand. They are utterly convinced of their own superiority that they are genuinely confused and offended if accused of snobbery; the other side of that, though, is that they view themselves as enormously responsible to their community. And above all they are bound to rigid standards of behavior. John Apley laments:

Lord knows there are peculiar enough eccentric types but even these conform to a definite pattern of eccentricity.

For those of us who have lived in Boston, it’s also interesting to see an earlier stage in the city’s physical and cultural evolution. During the course of the book the Charles River Basin is created and the T (not yet called that, of course) is built: “eventually Boston would be twelve minutes, instead of an hour’s distance, from Cambridge.” Culturally this was the era when the political power of the Brahmins waned and that of the Irish Bostonians waxed, when the Cabots and Lodges gave way to the Fitzgeralds and Curleys. This Apley cannot completely understand.

I see that the novel was made into a play and then a movie, starring Ronald Colman. The IMDB gives the movies tagline as “Stop apologizing for sex, George Apley…you didn’t invent it!” It would be difficult to imagine a less relevant tagline for the book. It’s far deeper, and funnier, than that.

Ted Kennedy, not yet RIP

May 24, 2008

I know Ted Kennedy’s prognosis doesn’t sound good, but everyone seems to have spent the week talking about him as if he were already dead. Maybe it’s nice that he gets to hear his own eulogies… Actually I thought the Senate leadership in their press conferences looked much deader than he does (the Republicans looked pretty bad too, but I couldn’t find a video of them).

Say it Ain’t So, Alice!

May 24, 2008

From today’s Boston Globe (can’t find a link to the story)—Alice Cooper is a golfer. “I took up golf 26 years ago when I quit drinking…I just traded one addiction for another.” Well, as long as it’s an addiction, I guess it’s OK…

But here is Alice as I prefer to think of him: with Muppets:

Jesus Christ Superstarrr

May 19, 2008

I went to Boston last weekend to see the touring Jesus Christ Superstar. Starring Ted Neeley, who’s been Jesusing for a long time. I fear he is now a tidge too old for the part, but what the hey; for a 64-year-old guy he still has a pretty impressive set of pipes.

The real standout was Corey Glover as Judas. Apparently I would have heard of him and his band Living Colour had I listened to 80’s funk metal, or if I had paid more attention to Guitar Hero 3. Maybe I’ll seek out one of their albums, or at least play GH3 again. What’s up, though, with so many black Judases? Random chance? Subtle racism? The part is just too cool for white guys to play?

The rest of the cast was generally good as well, although much more Broadway than Neeley and especially Glover. Broadway is fine and all, but JCS is among the least Broadwayish of shows—the first recording was after all not staged at all, and had a cast of decidedly non-Broadway (or West End) actors and singers. And really I think Broadway gloss gets in the way of the panic and terror and chaos of the story. These are people who are scared and confused and don’t really know what they’re doing—and it’s hard for me to believe that in someone who has the self-assurance and practiced confidence of a Broadway singer. Give me a cast of strung out hippies and roadies, I say! Well, maybe that’s just me. And in any case Glover’s rock-star affect, and voice, made up for much.

And something else that bothered me (and explains the title of this post): everyone except Glover really seemed to be emphasizing their r’s. They sounded like Brits imitating Americans. What’s up with that? Am I so used to pretentious English choral style that I can’t take good old American singing voices?

Polish and r’s aside, I don’t mean to dis the rest of the cast here, because as I said they really were good. Tiffini Dodson (a Tennessee girl!) as Mary Magdalene and Craig Sculli as Pilate especially so.

I was struck by something that should have been completely unsurprising: how much this production sounded like the show’s various earlier incarnations. Having gone through a bit of Webber/Rice phase (how gay is that? and don’t get me started on Evita), I still pretty much have the whole thing mostly engraved in my brain, and at only one point did I experience even the slightest dissonance between the soundtrack in my head and the one on the stage. The instruments could have been canned, using tracks from the original production, and I’d never have noticed. Neeley was of course in the movie. Even Glover had a bit of a Murray Head thing going, I thought. Only Herod’s song was reworked, with a bit of a Latin beat (and some spoken dialog, the only spoken lines in the show). I’m told that productions often rework Herod a bit; it’s the only bit of levity in the show, and everyone wants to make the most of it.

I went with a largish group, and it was interesting to see various people’s reactions. Several people who didn’t know the show—these including my wife and daughter—hated it. Those of us for whom it loomed large in our formative consciousnesses loved it. One complaint I heard was that people couldn’t understand the words. I didn’t notice that, but then, I knew them all already.

Maybe people were confused by the plot as well. I’ve always thought the central conceit of the show—that Judas betrayed Jesus because he feared that Jesus’s followers were getting too noticeable, and that the Romans would step in and crush them—never made much sense to me. I just never much cared. I figured young Andrew and Tim just needed some Judas story to hang songs on, and settled for the first thing that seemed to work at all.

And one last almost-unrelated note: I see in Tim Rice‘s Wikipedia article that his marriage broke up when he had an affair with Elaine Page. I did not know that!

Oral Cultures and Us

May 17, 2008

On their respective blogs, April DeConick, Mark Goodacre, and Loren Rosson are having a discussion of orality, “secondary orality,” oral and literate cultures, and how our era of chaotic electronic communication might compare to the world that produced the New Testament (the area of study of the aforementioned scholar/bloggers). It’s pretty interesting stuff, so I won’t let my complete ignorance of the subject keep me from making a few random semi-related comments. Please do bear in mind that my only claim to expertise here is that I, you know, read and talk, so I’m pretty sure I’m way out in left field here. Oh, and I think my most interesting point as the last one, so you might just skip to that.

It’s not entirely clear to me that Professors DeConick and Goodacre and Rosson don’t actually more or less agree—Goodacre says so, respecting DeConick’s first post—and that the apparent disagreement is really over terminology and nuance and emphasis. Is that typical of oral or literate cultures? 🙂 . Insofar as I understand the issues here, I’m entirely with April DeConick (always a safe bet, as far as I can tell).

Rossen, citing this, argues “that our hypertext/internet subculture shares remarkable similarities with oral biblical culture.” I don’t buy it. The analogy is certainly interesting, but I don’t think it’s more than, well, an interesting analogy. It would be at the very least misleading to draw conclusions about the culture that produced the New Testament. Maybe when I have more time and energy I’ll respond to all the points there in detail, but for now I’ll just mention two very obvious things:

  1. Our pseudo-oral electronic communication shares one crucial feature with good old books, and not with truly oral culture—you can always look up sources. You can click on those links above and see what I garbled in this post. You should, actually, if you have the slightest interest. Then you can go to a library and read the references they cite. I should do that myself.
  2. As April DeConick comes close to pointing out, people in oral cultures had skills we don’t—our memories suck. We have no need to remember very much; we can look up anything we need, and just haven’t needed to practice memorizing things. The internet has made looking stuff up even easier, come to think of it, moving us still further away from truly oral cultures.

This does have me thinking about “oral transmission” and what it means for various ancient texts. How do the gospels compare in that respect to the Pentateuch, or to the Iliad and the Odyssey?

Homer seems a very different case from the Bible here—the Greek epics were (apparently) pretty direct transcriptions of oral versions of the story. Hence all the mnemonic devices and stock phrases: “strong-greaved Achaeans,” “bright Achilles,” “gray-eyed Athene,” “wine-dark sea.”

The gospels and the Old Testament, at least the part of the OT I find most interesting—the J sections of the Pentateuch and the story of David—also strike me as fundamentally different in origin. The gospels were apparently written down in part to preserve circulating oral tradition, and although (unlike the Homeric epics) they were certainly not mere transcriptions, their authors presumably thought of themselves much more as reporters than as poets or novelists. On the other hand, I tend to think that the Yahwist and the “Court Historian of David,”—who may have been the same personwere essentially novelists. They used oral (and maybe written, for all we know) tradition as source material, but just as modern fabulists and historical novelists do they turned them into new, creative works. I think the Court History of David (including one of its prequels in I Samuel) is in fact best characterized as the first historical novel. Or at least the first one that survives.

Back to the modern world. I think the only example of an actual oral culture that we modern Americans are exposed to is that of elementary-school children. All of you out there sang “Jingle Bells, Batman Smells,” “Heigh-ho, heigh-ho, I bit my teacher’s toe,” and “Mine eyes have seen the glory of the burning of the school,” didn’t you? In the days before Bart Simpson those spread (mostly) orally, all over the country, with all the attendant versions and variations that you’d expect. “I thank thee, O Father, Lord of heaven and earth, because thou hast hid these things from the wise and prudent, and hast revealed them unto babes“—maybe New Testament scholars should consider visiting some elementary schools…

Banal => Brilliant

May 11, 2008

Garfield Minus Garfield. “Friends, meet Jon Arbuckle. Let’s laugh and learn with him on a journey deep into the tortured mind of an isolated young everyman as he fights a losing battle against loneliness in a quiet American suburb.”

I came across it through Language Log, and have to disagree with some of the comments there—I think it’s better leaving out both the thought balloons and the the cat. Everyone talks to their cats. Um, don’t they?