djangosnippets.org: Latest snippets posted by dchttps://djangosnippets.org/users/dc/2009-01-17T07:38:09.541368-06:00dcLoad Windows ICO files
2009-01-17T07:38:09.541368-06:00dchttps://djangosnippets.org/snippets/1287/<p>PIL IcoImagePlugin is twelve year old and it can't handle recent Windows ICO files. Here is a function that handles all ICO versions and preserve transparency.</p>
<p>Usage:</p>
<pre><code># Load biggest icon from file
image = load_icon('icon.ico')
# Save third icon as PNG
load_icon('icon.ico', 2).save('icon.png')
</code></pre>
Freely redistributableChoices class
2008-11-10T13:46:14.131755-06:00dchttps://djangosnippets.org/snippets/1178/<p>Yet another class to simplify field choices creation. Keeps order, allows i18n.</p>
<p>Before:</p>
<pre><code>ONLINE = 0
OFFLINE = 1
STATES = (
(ONLINE, _('online')),
(OFFLINE, _('offline'))
)
state = models.IntegerField(choices=STATES, default=OFFLINE)
</code></pre>
<p>After:</p>
<pre><code>STATES = Choices(
('ONLINE', _('online')),
('OFFLINE', _('offline'))
)
state = models.IntegerField(choices=STATES, default=STATES.OFFLINE)
</code></pre>
Freely redistributable