a blog about programming, photography and electronics.

Fix “ValueError: unknown locale: UTF-8″ under Mac OS X 10.7 – Lion

Posted: February 16th, 2012 | Author: | Filed under: Python | 13 Comments »

Today I was trying the new Django 1.4 Beta 1 and when I run the syncdb command I got this error:

(app)patrick@app$ python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Traceback (most recent call last):
File "manage.py", line 9, in
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/sql.py", line 189, in emit_post_sync_signal
interactive=interactive, db=db)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 73, in create_superuser
call_command("createsuperuser", interactive=True)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in handle
default_username = get_default_username()
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 105, in get_default_username
default_username = get_system_username()
File "/Users/patrick/.virtualenvs/app/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 85, in get_system_username
return getpass.getuser().decode(locale.getdefaultlocale()[1])
File "/Users/patrick/.virtualenvs/app/lib/python2.7/locale.py", line 496, in getdefaultlocale
return _parse_localename(localename)
File "/Users/patrick/.virtualenvs/app/lib/python2.7/locale.py", line 428, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

More precisely the error is

ValueError: unknown locale: UTF-8

After doing a little search on Google I found this ticket on the Django bug tracker.

The solution was really simple I just needed to export some variables in my bash enviroment. So I edited my .bash_profile file adding these lines:

export LANG="it_IT.UTF-8"
export LC_COLLATE="it_IT.UTF-8"
export LC_CTYPE="it_IT.UTF-8"
export LC_MESSAGES="it_IT.UTF-8"
export LC_MONETARY="it_IT.UTF-8"
export LC_NUMERIC="it_IT.UTF-8"
export LC_TIME="it_IT.UTF-8"
export LC_ALL=

where it_IT.UTF-8 should be your locale string. To test if it worked for you just reload the console and run this code:

python -c 'import locale; print(locale.getdefaultlocale());'

You should get something like this:

('it_IT', 'UTF8')

[Plugin] jQuery Holed Div

Posted: February 3rd, 2011 | Author: | Filed under: jQuery, WebDevelopment | Tags: , , , , , , | No Comments »

Recently I needed to create a holed div, like this:

I haven’t found any good solution to create a holed div without using images, so I tried to use canvas as a background and it worked nicely.

Anyway I wanted to share my result to everyone, maybe it’ll be useful to someone else :)
So I created a jQuery Plugin called jquery.holedDiv.

Here’s a demo: demo

Download Latest This version may not work, because is used for testing, download the minified version.

Download Minified (0.1)
Download Minified (0.1.1)

Update: code uploaded to bitbucket (see below)


      'padding': 10,
      'radius': 10, //0 if you don't want rounded borders
      'stroke': false, //if you want to add a (black) stroke to the background
      'holeRadius': 20,
      'drawInner': true, //if you want to draw an inner circle, like the demo
      'drawInnerColor': 'black' //the color of the inner circle

Tested On:

  • Chrome 10
  • Firefox 4b10
  • Opera 10
  • IE 9

If you find any bug, or have any question (or feature suggestions) please let me know :)

Update 03/02/2011 20.41

Added version 0.1.1 that supports IE 9.0

Update 04/02/2011 23.50

Version 0.2 is ready, supports IE < 9 using excanvas

You can download it on bitbucket:


Update 08/02/2011

Relased Version 0.3 check it on bitbucket

[Project] Arduino and Canon EOS 400d

Posted: August 16th, 2010 | Author: | Filed under: Arduino, Projects | Tags: , , , , , | No Comments »

This is my last project, an intervalometer for my Canon EOS 400d created with arduino.

I created it because i need to create some time lapse video for the coming soon bisaccia.info‘s web tv.
Here are two videos:

The “Backstage”:

A sample time lapse:

I’ll upload the code and the schematic soon when I create a better version, currently you can’t change the delay between every shoots, also you can’t stop it.
A better time lapse video is also coming but I should buy a battery grip for my canon, currently my battery last only 5 hours.

Tip – Dynamic Path For FileField

Posted: June 15th, 2010 | Author: | Filed under: django, tips | Tags: , , | No Comments »

In a recent project I needed to save a file to a dynamic directory.

My model was something like this:

from django.db import models
class MyDoc(models.Model):
    name = models.CharField()
    document = models.FileField(upload_to='uploads/documents')

with this code each document will be uploaded to MEDIA_ROOT/uploads/documents.
In order to upload the file to a dynamic dir like this: MEDIA_ROOT/uploads/documents/id/ I used this code:

from django.db import models
class MyDoc(models.Model):
    upload_to = 'uploads/documents/%d/%s'
    def _get_upload_to(self, filename):
        return self.upload_to % (self.pk, filename)
    name = models.CharField()
    document = models.FileField(upload_to=_get_upload_to)

That’s all (Thats’s Django!), now this code will upload each document into a separated dir for each object.

The code I posted before doesn’t work properly in fact the first time we save the model the pk is None so this code can’t get the correct path.

If you have any question, please feel free to ask.

Adding additional views to django admin

Posted: May 17th, 2010 | Author: | Filed under: django | Tags: , | 5 Comments »

Today I wanna show you a simple way to add an additional view to the admin site.
Imagine that you want to create a view to review a model, something like send an email to the site owner with your thoughs (or your changes) about an entry.

First we need to define a simple model (of course you can use your existing model):

from django.db import models
class MyEntry(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()
    def __unicode__(self):
        return self.title
    class Meta(object):
        verbose_name = 'My Entry'
        verbose_name_plural = 'My Entries'

Read the rest of this entry »