I had a need to colorize the nicks for the new DjangoBot Logger. Instead of managing a collection of names and corresponding colors we decided it would be more simple to just “hash” the nickname using a colorize filter. This causes the same nickname to always appear in the color.
from django import template
register = template.Library()
def do_colorize(value):
if not value:
return ''
result = sum([ord(c) for c in value])
return "#%X" % result
register.filter('colorize', do_colorize)
If this was a critical implementation I would probably try to limit the range to make sure we don’t go too white on white. Not likely you’ll have a use for this, but if so, have at it.
One final thing, Brian Rosner has done tremendous work on implementing the DjangoBot and the Logger functionality. We plan to enhance the logger as we go, in true iterative fashion.



Simple. Elegant. Beautiful.
This reminds me a bit of how Dopplr color-codes cities. Not exactly the same, but similar, anyway.
http://blog.dopplr.com/index.php/2007/10/23/in-rainbows/
This might be safer:
”#X” % (hash(value) x%x 0xffffff)
Let’s try that again… ”#%%X” % (hash(value) & 0xffffff)