diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-01-01 18:37:33 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-01-01 18:37:33 +0000 |
| commit | 53aef92bf89f2d655a125d94a0e24203e76af1d6 (patch) | |
| tree | 5aef7fe3213123da0526de9e02cfc0ed1b0dd51c /django | |
| parent | 4596b1bbfdebcc367b51182b4c3e1bbaa6ba5631 (diff) | |
Fixed #1145 -- Added unit tests for default template filters and fixed two bugs in filters. Thanks, Luke Plant
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1811 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/template/defaultfilters.py | 12 | ||||
| -rw-r--r-- | django/utils/timesince.py | 6 |
2 files changed, 14 insertions, 4 deletions
diff --git a/django/core/template/defaultfilters.py b/django/core/template/defaultfilters.py index de6da35cbb..f273fa0726 100644 --- a/django/core/template/defaultfilters.py +++ b/django/core/template/defaultfilters.py @@ -117,7 +117,8 @@ def urlize(value): def urlizetrunc(value, limit): """ - Converts URLs into clickable links, truncating URLs to the given character limit + Converts URLs into clickable links, truncating URLs to the given character limit, + and adding 'rel=nofollow' attribute to discourage spamming. Argument: Length to truncate URLs to. """ @@ -254,7 +255,14 @@ def slice_(value, arg): for an introduction. """ try: - return value[slice(*[x and int(x) or None for x in arg.split(':')])] + bits = [] + for x in arg.split(':'): + if len(x) == 0: + bits.append(None) + else: + bits.append(int(x)) + return value[slice(*bits)] + except (ValueError, TypeError): return value # Fail silently. diff --git a/django/utils/timesince.py b/django/utils/timesince.py index b9edb12554..0d1ab470e5 100644 --- a/django/utils/timesince.py +++ b/django/utils/timesince.py @@ -24,14 +24,16 @@ def timesince(d, now=None): else: tz = None now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz) - delta = now - d + + # ignore microsecond part of 'd' since we removed it from 'now' + delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) since = delta.days * 24 * 60 * 60 + delta.seconds for i, (seconds, name) in enumerate(chunks): count = since / seconds if count != 0: break if count < 0: - return '%d milliseconds' % math.floor(delta.microseconds / 1000) + return '%d milliseconds' % math.floor((now - d).microseconds / 1000) s = '%d %s' % (count, name(count)) if i + 1 < len(chunks): # Now get the second item |
