~ubuntu-branches/ubuntu/trusty/horizon/trusty-proposed

« back to all changes in this revision

Viewing changes to horizon/utils/filters.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-12-05 14:39:15 UTC
  • mto: This revision was merged to the branch mainline in revision 61.
  • Revision ID: package-import@ubuntu.com-20131205143915-5u8q3kdxdw8e7maz
Tags: upstream-2014.1~b1
ImportĀ upstreamĀ versionĀ 2014.1~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import iso8601
18
18
 
19
19
from django.template.defaultfilters import register  # noqa
 
20
from django.template.defaultfilters import timesince  # noqa
 
21
from django.utils.safestring import mark_safe  # noqa
 
22
from django.utils import timezone
20
23
 
21
24
 
22
25
@register.filter
26
29
 
27
30
@register.filter
28
31
def parse_isotime(timestr):
29
 
    """
30
 
    This duplicates oslo timeutils parse_isotime but with a
 
32
    """This duplicates oslo timeutils parse_isotime but with a
31
33
    @register.filter annotation.
32
34
    """
33
35
    try:
36
38
        raise ValueError(e.message)
37
39
    except TypeError as e:
38
40
        raise ValueError(e.message)
 
41
 
 
42
 
 
43
@register.filter
 
44
def timesince_sortable(dt):
 
45
    delta = timezone.now() - dt
 
46
    # timedelta.total_seconds() not supported on python < 2.7
 
47
    seconds = delta.seconds + (delta.days * 24 * 3600)
 
48
    return mark_safe("<span data-seconds=\"%d\">%s</span>" %
 
49
                     (seconds, timesince(dt)))