txt2img tag shows on the web text as images, helping to avoid get indexed email address and some other information you don't want to be on search engines.
Usage:
`{{worker.email|txt2img:18|safe}}`
An "if-style" template tag that checks to see if a user belongs to a one or mores groups (by name).
Usage:
`{% ifusergroup Admins %} ... {% endifusergroup %}
or
{% ifusergroup Admins Clients Programmers Managers %} ... {% else %} ... {% endifusergroup %}`
This is useful if you have a string that is html encoded (i.e. "<p>Hello world!</p>") and you want to do something more complex than just display it as html, such as using the striptags filter.
It was based in:
http://djangosnippets.org/snippets/1586/
Instead of doing this:
'attribute_name = forms.CharField(widget=forms.TextInput(attrs={'class':'special'}))`
You can do this in your template:
{{ form|cssclass:"attribute_name:special_class"|cssclass:"other_attribute:special_class" }}
Renders enclosing contents as it is. Useful to avoid tags conflict with certain javascript libraries (eg. jquery-tmpl.js, mustache.js)
Example usage:
`<script class="content-tmpl" type="text/x-jquery-tmpl">`
`{% alien %}`
`{{ tmpl(results) "#results .item-tmpl" }}`
`{% endalien %}`
`</script>`
This snippet is an improved version of the [ifusergroup](http://djangosnippets.org/snippets/1576/) tag that allows spaces in any of the group names. It also fixes a small bug where if a group didn't exist none of the subsequent groups would be checked.
Django's built-in {% regroup %} template tag is great, but sometimes, you need to pass in the attribute you want to group on instead of declaring the attribute when you define the tag.
{% dynamic_regroup %} is identical in function to {% regroup %}, except that it will attempt to resolve a context variable for the attribute you want to group by.
{% dynamic regroup %} is also backward compatible, so you can also hand in the attribute literal and it will work as expected.
See the end of the code for an example of usage.
I needed to display formset into table and I didn“t like solution I have found. So I have written this simple tag you can use it in templates like this:
`
{% for row in formset|square_it:6 %}
<tr>
<td>
</td>
{% for form in row %}
<td>
{% for field in form %}
{{ field }}
{% endfor %}
</td>
{% endfor %}
`
Get any value from settings.py as a template variable. The variable can then be used in conditional tags.
E.g. to show a link to a help page only if it the help page url is defined in settings.py
{% load get_setting %}
{% get_setting MY_HELP_URL as help_url %}
{% if help_url %}<a href="{% help_url|safe %}">Help</a>{% endif %}
should probably be migrated to an inclusion tag to allow a source timezone that isn't the site specific TIME_ZONE.
This code assumes that your database stores dates according to the django.conf.settings.TIME_ZONE variable.
Yes.. this assumes that dates are stored in the database according to system time. On my systems the system time of a server is always UTC therefore avoiding problems with datetime (no tz info) columns in backend databases having no timezone information and stored according to the database or system timezone information. I find it a good practice to always use UTC for any stored information and always retrieve information as UTC and localize the date during display.
Two template tag filters that can be used to create a table from a sequence.
<table>
{% for row in object_list|groupby_columns:3 %}
<tr>
{% for obj in row %}
<td>{{ obj }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
The example above would create a table where items read from top to bottom, left to right, in 3 columns. "Empty" cells are added to the sequence by the filter so that your rows balance.
**You can save these codes into a templatetag file in your django app. Then use codes like these in your template files:**
****************************************************************************
{% load *yourtags* %}
...
<img src="{% thumb *yourmodel.picturefield* 200 300 0 %}"/>
<img src="{% thumb *yourmodel.picturefield* 500 400 yes %}"/>
...
The parameters are:
imagefield ImageField
width Integer
height Integer
rescale [1, yes, true, 0, no, false]
**Some codes come from <djangosnippets.org>**