djangosnippets.org: Latest snippets posted by jcrofthttps://djangosnippets.org/users/jcroft/2008-01-11T01:11:18.019675-06:00jcroftPad integers with leading zeros (template filter)
2008-01-11T01:11:18.019675-06:00jcrofthttps://djangosnippets.org/snippets/543/<p>Disclaimer: I'm not the world's greatest programmer, so there may be better ways to do this, but it works for me (feel free to offer your improvements, though!).</p>
<p>Basically, this will pad an integer with leading zeros and return a string representation. User it like this:</p>
<pre><code>{% forloop.counter|leading_zeros:"5" %}
</code></pre>
<p>...where …</p>
Freely redistributableFind all links in a value and display them separatley
2007-02-27T21:49:17.897528-06:00jcrofthttps://djangosnippets.org/snippets/45/<p>This is a simple filter I use to display a list of links from a blog entry off in the sidebar (<a href="http://www2.jeffcroft.com/blog/2007/feb/25/two-new-django-sites-both-source-available/">example</a>).</p>
<p>Requires beautifulsoup. Originally by <a href="http://playgroundblues.com">Nathan Borror</a>, tweaked slightly by me.</p>
Freely redistributableUsing the {% widthratio %} template tag with CSS to create a bar graph
2007-02-27T21:39:23.225490-06:00jcrofthttps://djangosnippets.org/snippets/44/<p>The {% widthratio %} template tag is under appreciated! Here, it's combined with CSS to create a bar graphic for the results of an election (this example comes from <a href="http://flickr.com/photos/postneo/405239750/in/photostream/">this page</a>, but has been modified slightly for simplicity's sake).</p>
<p>The widthratio tag can be used to create all sorts …</p>
Freely redistributableUsing the built-in slugify filter outside a template
2007-02-27T21:13:26.465839-06:00jcrofthttps://djangosnippets.org/snippets/43/<p>This is just a very short (and mostly useless on it's own) example of how the built in slugify filter can be used in a Python script to generate slugs. It was pulled from a script I've written to pull in items from Upcoming.org's API.</p>
<p>I post it because "sunturi" …</p>
Freely redistributableAvoid widows using a template filter
2007-02-25T21:23:27.917368-06:00jcrofthttps://djangosnippets.org/snippets/17/<p><strong>Support good typography! Avoid widows! </strong></p>
<p>"Widows" are single words that end up on their own line, thanks to automatic line-breaks. This is an no-no in graphic design, and is especially unsightly in headers and other short bursts of text. This filter automatically replaces the space before the last word of …</p>
Freely redistributable