djangosnippets.org: Latest snippets tagged with 'list'http://djangosnippets.org/tags/list/2014-09-04T14:28:40.711402-05:00custom template filter to check if list contains any non-empty element
2014-09-04T14:28:40.711402-05:00doniyorhttp://djangosnippets.org/snippets/3092/<p>in template: </p>
<p>{% if not list|seeany %}
list empty
{% else %}</p>
Freely redistributableMultiple emails form field
2013-12-17T14:48:42.881052-06:00matrixhttp://djangosnippets.org/snippets/3012/<p>Validate form field that include email or emails separated by 'token' kwargs, by default ',' a comma. Return a list [] of email(s). Check validity of the email(s) from django EmailField regex (tested with 1.3, but normally will also work with 1.5)</p>
Freely redistributableList all errors in a form +bootstrap highlighting
2012-09-21T09:06:57.894399-05:00ibrahimlawalhttp://djangosnippets.org/snippets/2823/<p>Use this snippet to list all errors in a form. The message will be shown in a boostrap-type alert which can be 'closed' using a dismiss button.</p>
<p>The <strong>field label</strong> and the <strong>error</strong> will be listed.</p>
<p>e.g.</p>
<blockquote>
<ul>
<li>Name: This field is required</li>
<li>Email: Please enter a valid email</li>
</ul>
</blockquote>
Freely redistributableTemplate filter to get a list element by its index
2012-05-03T10:05:31.043625-05:00abidibohttp://djangosnippets.org/snippets/2740/<p>Gets the list element at the given index</p>
<p><strong>Example</strong></p>
<pre><code>{% for item1 in list1 %}
<p>List1 element: {{ item1 }}</p>
<p>List2 element: {{ list2|get_at_index:forloop.counter0 }}
{% endfor %}
</code></pre>
Freely redistributableTemplate filter that divides a list into exact columns
2012-01-20T04:44:48.460251-06:00davmuzhttp://djangosnippets.org/snippets/2652/<p>Template filter that divides a list into an exact number of columns.
The number of columns is guaranteed.</p>
<p>Example (list == [1,2,3,4,5,6,7,8,9,10]):</p>
<pre><code>{% for column in list|columns:3 %}
<ul>
{% for item in column %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endfor %}
</code></pre>
<p>Result:</p>
<pre><code><ul>
<li>1</li>
<li>2</li>
<li>3</li> …</code></pre>
Freely redistributableModelList class
2011-03-02T15:35:34.207725-06:00facundo_olanohttp://djangosnippets.org/snippets/2374/<p>This class makes easier the job of rendering lists of model instances in django templates. It's intended to mimic the behavior of the Model Forms in that it contains the code needed to render it as an HTML table and makes it easy to handle all the model lists from …</p>
Freely redistributableHat-trick for getting categories related to an object group
2011-01-30T12:53:05.503627-06:00pablo_PXLhttp://djangosnippets.org/snippets/2341/<p>Three step list comprehension for getting a set of categories existing in a group of objects
</p>
Freely redistributablecleat_list
2010-12-23T08:31:36.065957-06:00Tomekhttp://djangosnippets.org/snippets/2298/<p>Clear list from unwanted elements, within django template.
</p>
Freely redistributableJavaScript 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 redistributableMultiple emails form field
2010-03-15T12:47:40.771983-05:00virhilohttp://djangosnippets.org/snippets/1958/<p>Field which accepts list of e-mail addresses separated by any character, except those which valid e-mail address can contain.</p>
Freely redistributablelistutils.py
2010-01-18T14:55:44.666806-06:00staticohttp://djangosnippets.org/snippets/1874/<p>Various list utilities.</p>
Freely redistributableList divide columns across
2009-05-17T23:50:51.430306-05:00Leonhttp://djangosnippets.org/snippets/1511/<p>I wanted a way to make columns but have them in floated uls...</p>
Freely redistributableTemplate tag: Group variables into list
2009-03-13T14:14:00.795410-05:00Killarnyhttp://djangosnippets.org/snippets/1369/<p>Groups an arbitrary number of variables into a list.</p>
<p><code>{% group "foo", 2, "bar" as my_list %}</code></p>
Freely redistributableCountryField (UN Country List, 3 Char Codes)
2009-01-12T08:11:07.686291-06:00djmhttp://djangosnippets.org/snippets/1281/<p><strong>Adapted from</strong> <a href="http://www.djangosnippets.org/snippets/494/">CountryField</a> - <strong>Initial thanks to marinho</strong></p>
<p>Uses the UN country list listed in the source - this provides the 3 character ISO country code.
Ordered by display value and not country code.</p>
<p>Just place anywhere you like and import CountryField to use.</p>
<p><code>country = CountryField(verbose_name="Country", help_text="The registrant's country …</code></p>
Freely redistributablenone if empty list decorator
2008-08-27T15:08:33.615287-05:00laxuhttp://djangosnippets.org/snippets/1005/<p>this avoids checking if POST contains data for forms. see source for usage example</p>
Freely redistributable