custom template filter to check if list contains any non-empty element
in template: {% if not list|seeany %} list empty {% else %}
- list
- custom-template-tag
- custom-filters
in template: {% if not list|seeany %} list empty {% else %}
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)
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. The **field label** and the **error** will be listed. e.g. > * Name: This field is required > * Email: Please enter a valid email
Gets the list element at the given index **Example** {% for item1 in list1 %} <p>List1 element: {{ item1 }}</p> <p>List2 element: {{ list2|get_at_index:forloop.counter0 }} {% endfor %}
Template filter that divides a list into an exact number of columns. The number of columns is guaranteed. Example (list == [1,2,3,4,5,6,7,8,9,10]): {% for column in list|columns:3 %} <ul> {% for item in column %} <li>{{ item }}</li> {% endfor %} </ul> {% endfor %} Result: <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> <ul> <li>5</li> <li>6</li> <li>7</li> </ul> <ul> <li>8</li> <li>9</li> <li>10</li> </ul> By Davide Muzzarelli
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 a single view (as it's usually done with the generic views for creating and updating model instances). It also supports pagination and provides hooks for subclassing and customizing the rendered fields, column titles and list order. Basic example: `class Account(Model):` `name = models.CharField(max_length=MAX_LENGTH)` `responsible = models.CharField(max_length=MAX_LENGTH)` `email = models.EmailField()` `class AccountModelList(ModelList):` `class Meta:` `model = Account` `fields = ['name', 'responsible'] #email won't get a column` The model list would be instantiated with something like: `model_list = AccountModelList(instances=account_queryset)` Then a table header can be rendered with model_list.as_table_header(), while the table rows can be rendered calling as_table() on each model_list.items element.
Three step list comprehension for getting a set of categories existing in a group of objects
Clear list from unwanted elements, within django template.
I don't like not having the `range()/xrange()` in JavaScript — particularly when working with [Underscore.js](http://documentcloud.github.com/underscore/) and other such libraries — so I wrote it. It's not rocket science, but it might help make the world a slightly less annoying place for a couple of people.
Field which accepts list of e-mail addresses separated by any character, except those which valid e-mail address can contain.
Various list utilities.
I wanted a way to make columns but have them in floated uls...
Groups an arbitrary number of variables into a list. `{% group "foo", 2, "bar" as my_list %}`
**Adapted from** [CountryField](http://www.djangosnippets.org/snippets/494/) - **Initial thanks to marinho** 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. Just place anywhere you like and import CountryField to use. `country = CountryField(verbose_name="Country", help_text="The registrant's country of residence.")`
this avoids checking if POST contains data for forms. see source for usage example
23 snippets posted so far.