djangosnippets.org: Latest snippets posted by showellhttps://djangosnippets.org/users/showell/2009-11-27T11:34:18.425976-06:00showellShowell markup--DRY up your templates
2009-11-27T11:34:18.425976-06:00showellhttps://djangosnippets.org/snippets/1819/<p>The code shown implements a preprocessor for Django templates to support indentation-based syntax.<br />
</p>
<p>The pre-markup language is called Showell Markup. It allows you to remove lots of close tags and random punctuation. It also has a syntax for cleaning up individual lines of HTML with a pipe syntax for clearly …</p>
Freely redistributablesafe(r) monkeypatching scheme for django testing
2009-11-24T00:58:13.117011-06:00showellhttps://djangosnippets.org/snippets/1814/<p>In test code, it is sometimes useful to monkeypatch a Django method to have stubbed out behavior, so that you can simplify data setup. Even with decent data setup you might want to avoid execution of Django code that is not the target of your test.</p>
<p>The code snippet shown …</p>
Freely redistributableVariable._resolve_lookup monkeypatch
2009-11-15T20:06:09.200093-06:00showellhttps://djangosnippets.org/snippets/1797/<p>There are times when you want to hook into the Variable class of django.template to get extra debugging, or even to change its behavior. The code shown is working code that does just that. You can monkeypatch template variable resolution by calling patch_resolver(). I recommend using it for automated tests …</p>
Freely redistributablesortby template tag
2009-07-01T11:39:16.787109-05:00showellhttps://djangosnippets.org/snippets/1609/<p>This is a variation on dictsort that assumes objects with attributes, not dictionaries.<br />
</p>
<p>Example usage:</p>
<p>{% for book in author.book_set.all|sortby:'title' %}</p>
Freely redistributableelif for smart if tag
2009-06-17T15:02:27.149707-05:00showellhttps://djangosnippets.org/snippets/1572/<p>The code posted here adds "elif" functionality to the <a href="http://www.djangosnippets.org/snippets/1350/">smart if snippet 1350</a>.</p>
<p>To use the snippet first follow the instructions for installing smart_if, then swap in the method shown on the left for the original smart_if method. You'll need to keep all the supporting classes from the original …</p>
Freely redistributableTemplate Context Debugger with Pydev
2009-06-17T12:53:31.862974-05:00showellhttps://djangosnippets.org/snippets/1571/<p>This snippet is a variation on snippet 1550 that works with the Eclipse pydev plugin.</p>
<p>This allows you to set up a breakpoint anywhere in your template code, by simply writing {% pydev_debug %}. Be sure to launch pydev in debugger mode first.</p>
<p>Once you're in the debugger, you can …</p>
Freely redistributablecompressing polygons for geodjango
2009-06-09T15:34:05.856605-05:00showellhttps://djangosnippets.org/snippets/1559/<p>The code shown allows you, in GeoDjango, to reduce the number of points in your polygons. It helps reduce storage needs and makes queries run faster, at the cost of some precision. It provides a variation on the simplify() method that comes with the GEOS API, allowing you to specify …</p>
Freely redistributablemake templates fail loudly in dev
2009-05-12T14:57:30.056821-05:00showellhttps://djangosnippets.org/snippets/1504/<p>Add the line shown, or something similar, to your settings/dev.py, so that you can more clearly see when django is silently hiding errors in your template tags.</p>
Freely redistributabletestdata tag for templates
2009-05-04T00:06:33.423802-05:00showellhttps://djangosnippets.org/snippets/1482/<p>The "testdata" tag allows you to inline test data into your templates, similar in spirit to Python doctests. There are two sections--the test data and the actual template to be rendered. In non-test mode your template renders normally from whatever views call it, and there is very little overhead to …</p>
Freely redistributableoutliner template tag
2009-04-22T20:20:33.794394-05:00showellhttps://djangosnippets.org/snippets/1460/<p>Let's say you have a dataset and you want to render a page with sections/subsections/subsubsections down to some arbitrary depth and with arbitrary keys. For example, you might want to show cars broken out by year/price_range or price_range/year or price_range/manufacturer/model. The outliner template tag allows you to support multiple breakdowns …</p>
Freely redistributableurl extension mechanism
2009-04-16T13:40:19.600281-05:00showellhttps://djangosnippets.org/snippets/1444/<p>Executive summary: url "include" on steroids--granular extra parms and validate names in passing</p>
<p>We maintain multiple Django applications, and we use the excellent built-in include mechanism to allow one urls.py to borrow from another:</p>
<p>http://docs.djangoproject.com/en/dev/topics/http/urls/</p>
<p>If you scroll down to the section entitled "Passing extra options to include," you will …</p>
Freely redistributable