11 Django gotchas

Posted by Jim DeLaHunt on 31 Aug 2010 | Tagged as: Python, Unicode, robobait, software engineering, web technology

This post has been a long time in the making. A year ago, I started work on my Twanguages code. This was code to analyse a corpus of Twitter messages, and try to discern patterns about language use, geography, and character encoding.  I decided to use the Django web framework and the Python language for the Twanguages analysis code.  I know Python, but I was learning Django for the first time.

Django is really, really marvellous.  When I tried this expression, and got the Python array of records I was expecting,

q2 = TwUser.objects.annotate(ntweets=Count('twstatus')).filter(ntweets__gt=1)

I wrote in my log, “I think I just fell in love. Power and concision in a tool, awesome.”

But Django gave me fits.  It has its share of quirks to trap the unwary novice. Eventually I began writing notes about “Django gotchas” in my log.  Some of them are Django being difficult, or inadequate. Some are me being a clueless novice, and Django not rescuing me from my folly. But all of them were obstacles.  I share them in the hopes of helping another Django novice.

Here are my Django gotchas.  They are ranked from the most distressing to most benign. They apply to Django 1.1, the current version at the time. (As of August 2010, the current version is 1.2.1.) A couple of gotchas were addressed by Django 1.2, so I moved them down to a section of their own. The rest presumably still apply to Django 1.2, but I haven’t gone back to check.

  1. API fails unhelpfully. I wrote a simple query expression like:
    S2 = models.TwStatus.objects.get( key )

    I got a lot of weird errors, e.g. “ValueError: too many values to unpack” (where key is string) and “TypeError: ‘long’ object is not iterable” (where key is long). I had made a mistake, of course; the call to get() should have a keyword argument of “id__exact” or the like, not a positional argument. The correct spelling is this:

    S2 = models.TwStatus.objects.get( id__exact=key )

    The gotcha is that Django’s .get() isn’t written defensively. It isn’t very robust to programmer errors. Instead of checking parameters and giving clear error messages, it lets bad parameters through, only to have them fail obscurely deep in the framework. If defensive programming of the Django API would slow it down too much in production, I’d love to have a debug mode I could invoke during development. Continue Reading »

Mobile tech transforms travelling

Posted by Jim DeLaHunt on 31 Jul 2010 | Tagged as: travel

An unexpected insight from  our recently-completed Turkey vacation was the way mobile devices and wifi networks simplified and improved our travel experience. It was a qualitative change in our travel experience, affecting how we spent our time and our money, and what we packed.

The crucial change was that I carried a borrowed Android smartphone, in place of my 2005-vintage Treo 650. The phone spoke Turkey’s GSM frequencies and was unlocked, ready to accept a local GSM chip. It could use wi-fi and 3G networking, and had a built-in camera. Ducky carried her iPhone, which she didn’t have for last summer’s Botswana trip. Though locked out of Turkish voice and data service, it still could use wi-fi networks and take pictures. We were travelling in parts of Turkey with good mobile voice and data coverage, and where we could easily steer to hotels with wi-fi service.

Let us count the ways this transformed our travel experience.

Continue Reading »

How about an IMLIG (Internationalisation, Multilingual, Localisation Interest Group) for Vancouver?

Posted by Jim DeLaHunt on 27 Jun 2010 | Tagged as: Unicode, Vancouver, i18n, language, meetings and conferences, multilingual, web technology

There is a lot of international, multilingual, and multicultural activity in Vancouver. Also, there’s a thriving tech scene. But there’s no place for the people in the intersection of those two circles — those interested in and working on the internationalisation, localisation, and multilingual aspects of technology projects — to get together and share ideas. I think there ought to be.

And I’ll even propose a name: IMLIG1604, the I18n L10n M11l I6t G3p (Internationalisation, Localisation, and Multilingual Interest Group) for North America’s 604 area code. If you can decipher the title, you’re in the club!

Continue Reading »

Why the PostScript language is Turing-complete

Posted by Jim DeLaHunt on 30 Apr 2010 | Tagged as: software engineering

A couple of weeks ago on the XML-dev mailing list, there was a discussion comparing declarative and procedural computer languages. Someone wondered why the PostScript language, though used mostly for declarative purposes like describing pages, was still a Turing-complete programming language. That’s actually a topic I know something about, so I contributed the following answer. I’m posting it here, lightly edited, because I thought it might be of wider interest. —JDLH

A good place to go for a discussion of why it is Turing-complete, despite being intended to describe page appearance, is in the Introduction (Chapter 1) of the PostScript Language Reference Manual.

In particular, it says, “The extensive graphics capabilities of the PostScript language are embedded in the framework of a general-purpose programming language. The language includes a conventional set of data types, such as numbers, arrays, and strings; control primitives, such as conditionals, loops, and procedures; and some unusual features, such as dictionaries. These features enable application programmers to define higher-level operations that closely match the needs of the application and then to generate commands that invoke those higher-level operations. Such a description is more compact and easier to generate than one written entirely in terms of a fixed set of basic operations.” Continue Reading »

Tools for setting classical music and opera scores free

Posted by Jim DeLaHunt on 31 Mar 2010 | Tagged as: culture

I’m an amateur opera and symphonic chorus singer. Most of the classical music and opera I perform is old. Not just pre-iPhone old, but usually well over a hundred years old. These works have outlived even the outrageously long copyright terms imposed on our culture by greedy commercial interests. They are clearly in the public domain; they have returned to the shared culture from which they grew.

But when I want to learn a new work, like Verdi’s opera Macbeth or Mozart’s Requiem, why do I find myself paying $24-$40 for a music score which probably cost $5 to print? Why does the book contain stern warnings not to photocopy the contents, even it is little more than a facsimile of a previous edition, which itself is in public domain?  It is because these music score products still cling to a pre-internet business model, based on selling “molecules” (the physical artifact of the book) for a price based on the value of the “bits” (the information or arrangement of notes we call the musical composition, plus the value of the editing, plus the value of the typesetting), and the costs of distributing and warehousing those molecules.

This shouldn’t be. The music itself — the bits, the abstract genius which is Beethoven’s or Mahler’s, not the later editorial changes, or the molecules on which the bits are printed — is in the public domain, so its cost is zero. Volunteers are willing to scan or transcribe old musical scores for free. So a digital file with a score ought to be accessible for the marginal cost of storage, duplication and delivery.  And in an era of cheap disks and high-speed internet, that marginal cost is zero.

Many classical music and opera scores are indeed available, free for the downloading. Below are links to some useful sites for the classical or opera musician to find them. But there’s more. In the digital world, scores should get better, too: more correct, easier to use, more customised. If a fraction of every chorus and orchestra pitched in to ratchet forward the quality of the free scores for music they perform, we could make a huge difference.

Continue Reading »

Birdwatching the 2010 Olympics police

Posted by Jim DeLaHunt on 28 Feb 2010 | Tagged as: Canada, Vancouver, meetings and conferences

Mémphramagog Police shoulder flashAs the cheers still resound outside my apartment, from the street party below, let me report on my own Olympic sport: police-spotting. It’s like bird watching, but for police agencies.

Some 118 different police agencies from across Canada came to the Vancouver area as part of the $900 million 2010 Olympics security effort.  The RCMP sent over 4000 officers from provinces across Canada; various municipal police departments sent some 1700 more.  (20% of Canada’s policing power was at the Olympics.) I figured it would be fun to say hello to a constable from every one of those agencies. I didn’t get to them all, but it was fun trying.

Continue Reading »

How to resolve issue: NSLU2 Samba server doesn’t respect file modification times

Posted by Jim DeLaHunt on 28 Dec 2009 | Tagged as: robobait

I just resolved a problem which has been an annoyance for two years. I’m posting the details as robobait in the hopes it will help others.

Our family network includes a Samba file server hosted on an NSLU2 server appliance by Linksys (now a part of Cisco). A long time ago we changed to the Unslung open firmware for the NSLU2 (or “Slug”, as we call it).    It’s a wonderful combination, powered by a rich assortment of free software created by many volunteers. I appreciate their efforts.

But two years ago, I moved my personal computing from a laptop running Mac OS X 10.3 to one running Mac OS X 10.5. On the new 10.5 laptop, I noticed that the NSLU2 failed to respect file modification times. That is, if I had a file created on Dec 1, 2007 on my laptop, and I dragged it to a Samba volume hosted on the NSLU2, then the time stamp on the copied file was changed to the present time. The Dec 1, 2007 modtime was lost. Similarly, if I used touch -t from the Mac OS X command line to change the timestamp on a file hosted on the NSLU2 Samba volume, the operation failed. If I tried  sudo touch -t, that succeeded, just until another client viewed the file — at which point the timestamp snapped to the present again. However, if I copied a file resident on the NSLU2 Samba volume to another location on the volume, the timestamp was preserved.

Continue Reading »

How to plug in to the Vancouver Social Media scene

Posted by Jim DeLaHunt on 14 Dec 2009 | Tagged as: Vancouver, meetings and conferences

A colleague from Green College, UBC, freshly graduated with an MFA in Poetry, but also with work experience in editing and publishing, is looking for a job in the Lower Mainland. At a party yesterday, we talked about the Vancouver (British Columbia) social media scene, and how she can get plugged in to it, and make it part of her job search. I’ve posted my ideas below. Do you have other leads for newcomers to plug into the local social media scene?  Please post them in the comments. Maybe, together, we can build a useful resource for other seekers.

Urban British Columbia in general, and the Vancouver metro area in particular, has thriving technology and social media communities.  (There’s industry in there somewhere, also.) This community exists in part through face-to-face relationships, and in part on-line. Through this community, you can meet interesting people, learn what is happening in the industry, network for job leads, and of course have a good time.

There’s nothing terribly unusual about the techniques for plugging into this community as opposed to any other. But here is my advice for specific starting points.

Basic Identity and Persona

The first thing to have is an identity, a way for people to refer to you and link to you. From this identity you will grow an online persona.

Continue Reading »

“Getting in touch with your Joomla’s inner database”

Posted by Jim DeLaHunt on 30 Nov 2009 | Tagged as: Joomla, Vancouver, meetings and conferences, web technology

I’m giving another talk at the Vancouver Joomla User Group started up recently. This group started this summer, and is now attracting a steady level of participation. It’s great to see a Joomla! community developing. Here’s the coordinates:

Getting in touch with your Joomla’s inner database

Monday, 30. November 2009, 18:30-20:30h. At The Network Hub, 422 Richards Street, 3rd floor, Vancouver, BC V6B 2Z3. tel +1 604 767 8778.

A monthly meeting of the Vancouver Joomla User Group. Admission free. All people interested in learning more about the Joomla! content management system, and helping others learn more, are welcome.

Agenda

  • Introductions.
  • Featured topic: Getting in touch with your Joomla’s inner database, by Jim DeLaHunt.
  • Q&A.
  • Door prize drawing.
  • Networking.

Continue Reading »

Copyright, Competition, and Investment

Posted by Jim DeLaHunt on 30 Nov 2009 | Tagged as: Canada, culture, politics

During July-Sept 2009, the Government of Canada held public copyright consultations, with an eye to writing new copyright law. They asked for submissions addressing five topics.  Here’s one of my submissions, on “Competition and Investment“. It’s hard to tell what will become of these consultations. My submission did eventually show up on the official submissions page, but I still want to publish it for the record on my own blog.  I have two more submissions, “Copyright and you (me)” and “Copyright and the test of time“, which I published in recent weeks.

Q: What sorts of copyright changes do you believe would best foster competition and investment in Canada?

A: Three changes:

  1. relinquish Crown Copyright
  2. create legal structures for free culture, and industries based on it
  3. don’t take on the job of defending obsolete business models

Continue Reading »

Next »