Login

Snippets by marinho

Snippet List

A simple rest template filter

**Attention! This snippet must be ignored**, like [zgoda](http://www.djangosnippets.org/users/zgoda/) pointed with reason: already exists this functionality in `markup` contrib. **Explanations:** This template filter allows you to render easily a reStructuredText to **HTML** or another format it supports. **Setup:** Insert the snippet into an_app/templatetags/restutils.py. **Use in template:** `{% load restutils %}` and use it as following: - `{{ entry.content|rest:"html" }}`

  • rest
  • template-filters
Read More

Template filters utils

**Explanation:** That template filters is util for combine boolean-return conditions using template tag `{% if %}`. **Setup:** Insert the snippet into an_app/templatetags/myutils.py. **Use in template:** {% load myutils %} and use filters as following: - `{% if 10|is_multiple_of:5 %}` - `{% if 10|in_list:a_list_variable %}` - `{% if user.username|is_equal:a_variable %}` - `{% if user.username|is_not_equal:a_variable %}` - `{% if a_variable_|is_lt:5 %}` - `{% if a_variable_|is_lte:5 %}` - `{% if a_variable_|is_gt:5 %}` - `{% if a_variable_|is_gte:5 %}`

  • template-filters
Read More

Date/time util template filters

**Explanations:** - the series "is_*_of" was created 'cos it's easier write: `{% if 10|is_day_of:date and user %}` than write: `{% ifequal date.day 10 %}{% if user %}...` - the series "inc/dec" is not complete, but can the extended to day, hour, minute, etc as you needs. It's util to inc 10 months since 05/31/2006 by example and get a 2007's date :) **Setup:** Insert the snippet into an_app/templatetags/datetimeutils.py. **Use in template:** `{% load datetimeutils %}` and use filters as following: - `{{ 30|is_day_of:a_date_time_variable }}` - `{{ 11|is_month_of:a_date_time_variable }}` - `{{ 2006|is_year_of:a_date_time_variable }}` - `{{ 58|is_minute_of:a_date_time_variable }}` - `{{ 23|is_hour_of:a_date_time_variable }}` - `{{ a_date_time_variable|dec_year:2 }}` - `{{ a_date_time_variable|dec_month:2 }}` - `{{ a_date_time_variable|inc_year:2 }}` - `{{ a_date_time_variable|inc_month:2 }}`

  • date
  • time
  • template-filters
Read More

marinho has posted 33 snippets.