djangosnippets.org: Latest snippets posted by acdhahttps://djangosnippets.org/users/acdha/2010-01-26T12:18:07.174469-06:00acdhaReliably create a Django File using the contents of a URL
2010-01-26T12:18:07.174469-06:00acdhahttps://djangosnippets.org/snippets/1890/<p>There's no direct way to save the contents of a URL to a Django File field: you're required to use a File instance but those can only safely wrap normal files, not the file-like object returned by urllib2.urlopen. Several examples online use urllib.urlretrieve() which creates a temporary file but performs …</p>
Freely redistributableEncoding datetime for JSON consumers like YUI
2009-12-22T13:06:36.235193-06:00acdhahttps://djangosnippets.org/snippets/1841/<p>Passing datetimes from Python to a <a href="http://developer.yahoo.com/yui/datatable/">YUI DataTable</a> via JSON served by <a href="http://bitbucket.org/jespern/django-piston/">django-piston</a> turned out to be surprisingly rocky. This code actually works with <code>YAHOO.lang.JSON.stringToDate</code> (<em>not</em> <code>YAHOO.util.DataSource.parseDate</code>) which cannot handle time zone specifiers other than "Z" or dates without timezones.</p>
<p>The YUI <a href="http://developer.yahoo.com/yui/datasource/">DataSource</a> which uses this looks something …</p>
Freely redistributablePrivate Context Decorator
2009-08-16T17:07:21.976476-05:00acdhahttps://djangosnippets.org/snippets/1687/<p>Django's standard inclusion_tag doesn't include context variables by default.
When you add takes_context you are required to manually merge the context
variables into the dict which your tag returns, which tends to result in
wasteful code or [possibly accidentally] leaking variables into the global
context (<code>context.update({…})</code>).</p>
<p>This decorator …</p>
Freely redistributable