Archive for July, 2008

Django tip: Translating your application names (app_label)

Sunday, July 20th, 2008

This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently a patch has been accepted in the Django dev version, but it’s not yet in the trunk. Here’s what to do: In your applications’ __init__.py files put:

1
2
from django.utils.translation import gettext_noop
gettext_noop("AppName")

When your run manage.py makemessages -a there will be entries for these. Make sure to remove lines saying #, fuzzy. Now all you have to do is to customize the default admin template called index.html so it will actually do the translation of the application names.

18
        <caption>{% trans app.name %}</caption>

Creative Live! Cams on Ubuntu 8.04 using ov51x-jpeg

Wednesday, July 16th, 2008

First of all: It should work fine.. so be optimistic :) But you will need to compile a kernel module (ov51x-jpeg) to get it running. Please have a look at Creative’s list to see if your camera is using this module (it will have have an URL saying something like “Ov51xJpegHackedSource”). This is what you have to do afterwards:

$ sudo apt-get install build-essential module-assistant ov51x-jpeg-source
$ cd /usr/src/
$ sudo tar xvfj ov51x-jpeg-source
$ cd modules/ov51x-jpeg/

Unfortunately the source package for ov51x-jpeg is broken and won’t compile with the current Ubuntu kernel. So you have to download the newest source and unpack it somewhere. Then do the following:

$ sudo cp /path/to/newest/source/*.c /usr/src/modules/ov51x-jpeg/
$ sudo cp /path/to/newest/source/*.h /usr/src/modules/ov51x-jpeg/
$ sudo make
$ sudo module-assistant install ov51x-jpeg

To ensure that things are working please run sudo modprobe ov51x-jpeg, insert your camera and check that it’s listed when running lsusb. This should work pretty painlessly and afterwards you can enjoy new wonderful apps such as Gnome Cheese. Yay!

Resources:

Django auto-translation of field values

Monday, July 14th, 2008

What’s really nice in Django is the gettext implementation and the _ convention. But when running django-admin.py makemessages we’re not generating any translations for dynamic values such as field values. So let’s say that we have a model and we’d like what’s in it to be displayed in a translated manner. In the new Django development version we’re able to create our own special field types. And we can extend the CharField to provide automatic translation:

1
2
3
4
5
6
7
from django.db import models
from django.utils.translation import gettext_lazy as _
 
class AutoTranslateField(models.CharField):
    __metaclass__ = models.SubfieldBase
    def to_python(self, value):
        return str(_(value))

After that we just add whatever translations we know of to our locale/CODE/LC_MESSAGES/django.po file and run compilemessages.

Tip: Extending Django flatpages

Saturday, July 12th, 2008

I did a Google search and since nothing came up, I’m writing this little tip on creating your own CMS by extending Django’s flatpages. What’s good about flatpages is that they’re included in Django and has some basic code to get you started. But clearly they’re not enough if you want other people to administer a site.. you’ll want to add extra fields and special help texts for the admin. But we still don’t want to rewrite those ~150 lines of code, and they can really help you get past all the boring stuff and into the action.

Simply do the following:

cp -R /usr/share/python-support/python-django/django/contrib/flatpages my_project/my_flatpages

views.py

1
from my_project.my_flatpages.models import FlatPage

middleware.py

1
from my_project.my_flatpages.views import flatpage

urls.py

3
4
5
urlpatterns = patterns('my_project.my_flatpages.views',
    (r'^(?P<url>.*)$', 'flatpage'),
)

my_project.my_flatpages.middleware.FlatpageFallbackMiddleware has to be added to your MIDDLEWARE_CLASSES and my_project.my_flatpages to your INSTALLED_APPS and you’ll need to run manage.py syncdb, possibly changing the table name in models.py, so it doesn’t conflict with the old flatpages table. That’s basically it. After that you can work on the templates as described in the other howto’s, but now you have your own model to extend.

Rio Karma, Banshee 1.0 and Ubuntu 8.04

Tuesday, July 8th, 2008

Here’s a little step-by-step guide to getting your Rio Karma running on Ubuntu 8.04 with the new amazing Banshee 1.0. But first a little appetizer:

Thumb: Banshee 1.0 with Rio Karma

What we’ll do is fetch some stuff to get the compilation of Banshee working, patch up the source code, compile it and then as a last step we’ll get the kernel module for Karma up and running. So, here’s what you do:

$ sudo apt-get install libkarma0 libkarma-cil libkarma-dev omfs-source
$ sudo apt-get remove banshee
$ sudo apt-get build-dep banshee

Now we have the software from the Ubuntu repos, we’ve removed the old Banshee and installed the software needed for compiling Banshee. But we still need to get the Banshee source code. I prefer grabbing the latest version from SVN as Banshee is still under heavy development, and a lot of bug fixes will have been contributed as of writing this howto.

$ svn co http://svn.gnome.org/svn/banshee/trunk/banshee
$ cd banshee

And now the cool stuff: The patch that installs the support for Rio Karma which has not yet been committed to the trunk of the project. Bob Copeland is the maintainer so let’s all use this moment to send him our best of thoughts. He’s posted a patch here that you should download (look for the latest one). Save it in the same directory as the one with your banshee/ source dir. Now apply it like this:

$ cd banshee/
$ patch -p1 < karma.patch

After that you can compile banshee with the following commands.

$ ./configure –disable-boo
$ make
$ sudo make install

One thing we still need to do is compile the OMFS module for our Linux kernel. The source package in Ubuntu is broken, and what you basically need to do is to grab the latest version of the OMFS module and then overwrite the files provided by the Ubuntu omfs-source package. And only after that use module-assistant to install the module, otherwise the compile fails because something in the kernel API has changed.

$ sudo bash
# cd /usr/src
# tar xvfj omfs-source.tar.bz2
# tar xvfz omfs-0.8.0.tar.gz
# cp omfs-0.8.0/* modules/omfs
# module-assistant build omfs
# module-assistant install omfs
(plugin your Karma)
# modprobe usb-storage

This isn’t such a beautiful solution, but it ensures that we can still benefit from using module-assistant.

Lastly you should disable the Mass Storage plugin (it makes the Karma show up twice) and you cannot currently attach the Karma while Banshee is running.