Nullable Object must have a value

I’ve been coding a lot of ASP.NET lately using the whole Microsoft portfolio of dev tools, and I’m in total shock. I had expected to hate it, but not from rational reasoning, but rather because they made it. I thought it was sleek enterprise level stuff. But I was wrong… here are some obvious rational reasons to hate it:

  • Runtime error messages are cryptic and un-helpful (see the title of this post). Often they’re just summarized into texts like “error in database constraint… could be null, foreign-key, primary key… please check all the code you’ve ever written”.
  • System.Collections don’t support basic stuff like tuples and sets.
  • DataTables can’t handle null values. I mean: They call this DRO!?
  • I tried to edit some SQL in a Table Adapter. It suddenly switched the parameters for the auto-generated method without warning me – silently breaking the application and giving me hours of debugging.
  • The design view for aspx files in Visual Studio is useless since it always requires manual editing afterwards
  • I wanted to copy a database. Since the copy-function was broken in Enterprise Manager (You get an error message and using the “copy error message” function renders an “error copying error message”) I made a backup and wanted to restore it in a new database. The dialog for this operation silently switched the target for the restore several times – even the database files: to overwrite the production database. Pretty lucky to notice this, since it was hidden in another tab.
  • Visual Sourcesafe isn’t a proper versioning system. You might as well just use a network share and depend on ntfs file locking. Where’s the collaboration!?
  • There’s only a very limited amount of free or open applications available for it. And especially Umbraco which is the flagship of .NET CMS systems is full of errors and tells you to pay up as soon as you’d like the pro stuff – like say a proper development/deployment system.
  • Umbraco crashed our IIS – all we did was use the copy-content function!? How exactly is it that a webpage is allowed to take down a whole server?

I could probably ramble on about this. The bottom line is simply: I would never choose their technology over stuff like Subversion, Apache, Java or Python. And the whole ASP.NET framework is far from Ruby and Django – but of course it’s a lot older… it’s so 2003. I would have filed a few bug reports, but I guess these guys don’t have a bugzilla. Too bad.. I’ll just have to leave my feedback on this public blog.

Posted in Computers, Debate | Tagged , , , | Leave a comment

Django tip: Translating your application names (app_label)

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>
Posted in Django | Tagged , , , | 2 Comments

Creative Live! Cams on Ubuntu 8.04 using ov51x-jpeg

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:

Posted in Computers | Tagged , , , , , | 2 Comments

Django auto-translation of field values

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.

Posted in Django | Tagged , , | 2 Comments

Tip: Extending Django flatpages

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.

Posted in Computers, Django, Web | Tagged , | 4 Comments