djangosnippets.org: Latest snippets posted by woleverhttps://djangosnippets.org/users/wolever/2011-09-12T11:28:05.139439-05:00woleverServe admin-media from urls.py
2011-09-12T11:28:05.139439-05:00woleverhttps://djangosnippets.org/snippets/2547/<p>By default the <code>runserver</code> command does some magic to automatically serve admin media. This magic doesn't happen when using other servers like gunicorn… But this makes that magic unnecessary by using urls.py to route requests for admin media to the standard static media server.</p>
<p><code>#include <production_disclaimer.h></code></p>
Freely redistributableTemplate tags for localizing UTC times with pytz
2011-08-21T18:03:06.671616-05:00woleverhttps://djangosnippets.org/snippets/2519/<p>For example:</p>
<pre><code>Last modified: {% localdt item.modified_utc %} ({% localtimesince time.modified_utc %})
</code></pre>
<p>Converts the input datetimes to the timezone specified by the localtz context variable (it can also be explicitly specified, and all those other sensible things).</p>
<p>Input UTC datetimes can be specified using either a datetime or a timestamp. …</p>
Freely redistributabledump_app_data: dumps application data to the application's fixtures directory
2011-07-28T13:55:45.105702-05:00woleverhttps://djangosnippets.org/snippets/2497/<p>Dumps DB data for each application to that application's fixtures directory.</p>
<p>For example:</p>
<pre><code>$ ./manage.py dump_app_data
...
$ hg status
M apps/foo/fixtures/dev.json
M apps/bar/fixtures/dev.json
</code></pre>
Freely redistributableOverwriting file storage
2010-08-24T10:22:03.882594-05:00woleverhttps://djangosnippets.org/snippets/2173/<p>The title says it all — a subclass of FileSystemStorage which will overwrite files.</p>
<p>Note that saves which fail part way though will leave the original file intact (see <code>test_upload_fails</code>).</p>
<p>Based roughly on http://djangosnippets.org/snippets/2044/ .</p>
Freely redistributablemkrange - create a range() inside a template
2010-02-14T16:27:59.517376-06:00woleverhttps://djangosnippets.org/snippets/1926/<pre><code>Accepts the same arguments as the 'range' builtin and creates
a list containing the result of 'range'.
Syntax:
{% mkrange [start,] stop[, step] as context_name %}
For example:
{% mkrange 5 10 2 as some_range %}
{% for i in some_range %}
{{ i }}: Something I want to repeat\n …</code></pre>
Freely redistributable