Login

Tag "humanize"

Snippet List

timeto template filter

This is a more compact version of django's [timeuntil](http://docs.djangoproject.com/en/dev/ref/templates/builtins/#timeuntil) filter that only shows hours & minutes. If used like `{{ dt|timeto }}`, will produce output like "1hr 30min". If you know for sure that the server has the same timezone as the [datetime](http://docs.python.org/library/datetime.html#datetime-objects) value, then you don't need [datetutil.tz](http://labix.org/python-dateutil#head-587bd3efc48f897f55c179abc520a34330ee0a62) for utc time conversion.

  • datetime
  • time
  • humanize
Read More

FuzzyDateTimeField

FuzzyDateTimeField is a drop in replacement for the standard [DateTimeField](http://docs.djangoproject.com/en/dev/ref/forms/fields/#datetimefield) that uses [dateutil.parser](http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c) to clean the value. It has an extra keyword argument `fuzzy=True`, which allows it to be more liberal with the input formats it accepts. Set `fuzzy=False` for more strict validation.

  • datetime
  • humanize
Read More

Fuzzy Date Diff Template Filter

Pass in a date and you get a humanized fuzzy date diff; e.g. "2 weeks ago" or "in 5 months". The date you pass in can be in the past or future (or even the present, for that matter). The result is rounded, so a date 45 days ago will be "2 months ago", and a date 400 days from now will be "in 1 year". Usage: * `{{ my_date|date_diff }}` will give you a date_diff between `my_date` and `datetime.date.today()` * `{{ my_date|date_diff:another_date }}` will give you a date_diff between `my_date` and `another_date` Make sure to install this as a template tag and call `{% load date_diff %}` in your template; see the [custom template tag docs](http://docs.djangoproject.com/en/dev/howto/custom-template-tags/) if you don't know how to do that.

  • template
  • filter
  • date
  • humanize
Read More

(en-US) Humanized Decimal Field

Simple DecimalField class extension that automatically adds formatting and validation for comma-separated "decimals". Works wonderfully for price fields. Could be extended to strip dollar signs or to be locale-agnostic.

  • form
  • humanize
  • field
  • comma
  • decimal
  • thousands
  • separator
  • input
Read More

humanize time difference (how long ago)

If you ever have a need to display something like: "last update 5 days ago" "user logged in 2 mins ago" you can use this script to determine how long ago a timestamp is versus now().

  • time
  • now
  • humanize
Read More

Humanize lists of strings in templates

A simple template filter for taking a list and humanizing it, converting: `["foo", "bar"]` to `"foo and bar"` `["foo", "bar", "baz"]` to `"foo, bar and baz"` `["foo", "bar", "baz", "42"]` to `"foo, bar, baz and 42"`

  • filter
  • lists
  • filters
  • humanize
Read More

Timedelta template tag

This is tag similar to *timesince* and *timeuntil*, which work great until you starting giving timesince dates in the future or timeuntil dates in the past. Timedelta tag will humanize output correctly for both future and past dates using *now* as a default reference date (or a specified reference date as argument) now = Apr 27 2007 futuredate = May 5 2007 pastdate = Jan 5 2007 {{ futuredate|timedelta }} will output "in 1 week, 1 day" {{ pastdate|timedelta }} will output "3 months, 2 weeks ago"

  • template
  • date
  • time
  • humanize
Read More

11 snippets posted so far.