lck.django 0.8.5 documentation

This Page

lck.django.filters

A set of common independent filters usable directly in Python code.

Functions

nbsp(obj)

Converts spaces to nbsp entities.

Template tag available in common app’s strings library.

nullify(obj)

Converts any falsy value to None.

Template tag available in common app’s converters library.

numberify(obj, default=0)

Converts any type to int or returns a fallback number for falsy values. Except for falsy values, throws traditional ValueError if the input is uncovertable to int.

Template tag available in common app’s converters library.

Parameters:
  • obj – the object to convert
  • default – a fallback int for falsy objects
slugify(text, fallback=u'untitled-0')

A version of the builtin django.template.defaultfilters which doesn’t let empty strings as outcomes.

Template tag available in common app’s strings library.

Parameters:
  • text – the text to slugify
  • fallback – the text to return in case the builtin slugify returns an empty value
strike_empty(obj)

Converts any falsy value to u"---".

Template tag available in common app’s strings library.

thumbnail(image, size)

For a given image constructs a thumbnail using the rule specified in the size param.

Supported types of image:

  • any object with the width, height, file and url attributes (such as a Django ImageField)
  • any object with an image attribute pointing to an object of the other kind

If an incompatible object is passed, None is returned.

Possible values for size:

  • h{height} - scale to match the height given. Example: “h100” scales to

    100px in height. Width is scaled proportionally, may exceed 100px.

  • w{width} - scale to match the width given. Example: “w312” scales to

    312px in width. Height is scaled proportionally, may exceed 312px.

  • m{max_size} - scale to match the greater dimension to the value given.

    Example: “m50” would scale an 80x50 image to 50x31, and an 40x120 image to 17x50.

  • s{max_size} - cuts a square from the image and scales it to the value

    given. Example: “s48” would scale a 50x80 image to 48x48 based on the top 50x50 square.

The thumbnails are kept next to the original images with a _{size} suffix added to the name. If a thumbnail exists and is newer than the original image, it is reused on subsequent calls.

timediff(timestamp, language=u'pl')

Returns a string representing a fuzzy time difference between now() and the input timestamp.

The output rounds up to a single most significant value: years, months, weeks, days, hours or minutes.

title(text)

Like built-in |title filter but leaves existing caps alone, eg. 'I work for the FBI' -> 'I Work For The FBI'.

Template tag available in common app’s strings library.

transliterate(text, country_code, text_lang=u'')

If the country with the specified code is using Cyrillic alphabet, transliterates Latin strings using lck.i18n.translit.

Template tag available in common app’s strings library.