Login

Tag "formatting"

Snippet List

spaceless_json

Now you can format and compress json-data in django template

  • django
  • templatetag
  • json
  • spaceless
  • formatting
  • application/id+json
Read More

Prettify HTML body contents in HTTP response

This is an enhancement of snippet [#172](http://djangosnippets.org/snippets/172/). Here I use [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) — far more easier to install through pip in a virtualenv, and possibly a bit more maintained — to format and properly indent the rendered HTML from templates. I also added a check to only tidy contents in a `DEBUG=True` environment, regarding high impact on performance while doing so in production. Last, it's compatible with Django 1.2.x.

  • templates
  • format
  • html
  • tidy
  • syntax
  • output
  • prettify
  • formatting
  • indentation
  • readability
Read More

Currency formatting filter

See the function **docstring** for usage. This template filter has a couple of drawbacks: * Uses **locale.setlocale** which, according to the [Python docs](http://docs.python.org/library/locale.html#locale.setlocale), is not thread safe. I don't know how this may affect Django applications. * Requires Python 2.5+. Updated 2011-03-16.

  • template
  • filter
  • currency
  • formatting
Read More

copyright_since

**Example usage**: {% copyright_since 2008 %}, {% copyright_since 2009 %} **Output**: © 2008—2009, © 2009 Use this templatetag in your footer to achieve proper formatting of copyright notice.

  • datetime
  • date
  • template-tag
  • formatting
  • copyright
  • copyright-formatting
  • copyright-year
Read More

Convert CamelCase to lowercase_with_underscores

Just a simple regex function to convert a camel case string ("ClassName") to a lower case string with underscores ("class_name"). Came across a need for this when I was trying to add properties to a model at runtime using `object.__class__.__name__`. This is a modification of the function "get_verbose_name" found in django.db.models.options.

  • utilities
  • formatting
  • one-liners
Read More

5 snippets posted so far.