djangosnippets.org: Latest snippets posted by fish2000http://djangosnippets.org/users/fish2000/2010-12-15T06:01:18.956213-06:00fish2000JavaScript implementation of Python xrange() builtin
2010-12-15T06:01:18.956213-06:00fish2000http://djangosnippets.org/snippets/2287/<p>I don't like not having the <code>range()/xrange()</code> in JavaScript &mdash; particularly when working with <a href="http://documentcloud.github.com/underscore/">Underscore.js</a> and other such libraries &mdash; so I wrote it.</p>
<p>It's not rocket science, but it might help make the world a slightly less annoying place for a couple of people.</p>
Freely redistributableExport Django data to datestamped tarball -- choose individual models for handy packaging and archiving
2010-09-23T05:52:25.978241-05:00fish2000http://djangosnippets.org/snippets/2203/<p>Just like it says -- set it up and run. Use it for server migrations, for project handoffs, in cron jobs, you name it.
</p>
<p>I have never had problems exporting models to individual fixtures in this way, and only one bout of trouble re-importing them (and that was, like, an …</p>
Freely redistributableISBN model field: displays 10- and 13-digit variants and external links
2010-04-19T03:06:04.716464-05:00fish2000http://djangosnippets.org/snippets/1994/<p>Requires <a href="http://pypi.python.org/pypi/pyisbn/0.5.2">PyISBN</a>. Use like so:</p>
<pre><code>class Book(models.Model):
title = models.TextField()
isbn = ISBNField()
</code></pre>
<p>... the link in the widget can be changed to amazon, borders, you name it.
If the DB version is a 13-digit ISBN, the display box contains the 10-digit,
labeled; and vice-versa.</p>
Freely redistributableEmail queue in DB
2010-04-19T02:33:21.560657-05:00fish2000http://djangosnippets.org/snippets/1993/<p>This is what I use to send simple status emails from my sites. Instead of a django.core.mail.send_mail call, which can take an irrritatingly, nondeterministically long time to return (regardless of error state), you can stow the emails in the database and rely on a separate interpreter process send them off …</p>
Freely redistributableTaggedManager and TaggedQuerySet with chainable tagged() methods implemented with django-tagging
2010-02-25T03:21:06.838058-06:00fish2000http://djangosnippets.org/snippets/1942/<p>The popular <a href="http://code.google.com/p/django-tagging/">django-tagging</a> app has, in its implementation and semantics, a highly usable and transparent elegance -- but then you have to call methods on a Tag instances' items collection. These classes let you inline the tag name in the chain of queryset filter methods instead.</p>
<p>TO USE:</p>
<pre><code>### models.py …</code></pre>
Freely redistributableAmazon product-data interface class for Django-friendly PyAWS queries
2010-01-25T23:28:54.463741-06:00fish2000http://djangosnippets.org/snippets/1889/<p>I am not sure what to say about the state of PyAWS, or its future, what with the multiple forks available and lack of recent updates. The best version I've found is <a href="this one">http://github.com/IanLewis/pyaws</a>, a spiffed-up version of 0.2.2 by Ian Lewis. I wrote this class on top of PyAWS …</p>
Freely redistributabledecorators for creating paramaterized decorators and easy monkeypatching
2010-01-25T22:54:49.070295-06:00fish2000http://djangosnippets.org/snippets/1888/<p>as with all things related to monkeypatching, the caveat is to use things like these for good, and not for evil.</p>
<p>I wrote these decorators because I did not want to rewrite all of <a href="http://github.com/IanLewis/pyaws">PyAWS</a> -- instead I use these to add some standard/useful methods to the Bag collection that …</p>
Freely redistributable