summaryrefslogtreecommitdiff
path: root/django/contrib
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-05-17 10:16:12 +0000
committerJannis Leidel <jannis@leidel.info>2011-05-17 10:16:12 +0000
commit578a31fea3cb439f6bfeeb7825ac835820a9f58c (patch)
treed900f07487179adabeb43da6a1b5cafdab003685 /django/contrib
parent9ad005ec1c50e254dd61bbb1760c524aa01a79e2 (diff)
downloaddjango-578a31fea3cb439f6bfeeb7825ac835820a9f58c.tar.gz
Fixed #15921 -- Refined naturaltime filter added in r16071 to use timesince and timeuntil filters as fallbacks instead of date filter.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16233 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib')
-rw-r--r--django/contrib/humanize/locale/en/LC_MESSAGES/django.mobin343 -> 343 bytes
-rw-r--r--django/contrib/humanize/locale/en/LC_MESSAGES/django.po95
-rw-r--r--django/contrib/humanize/templatetags/humanize.py85
3 files changed, 126 insertions, 54 deletions
diff --git a/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo b/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo
index a08dc329d0..ba05bc9d70 100644
--- a/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo
+++ b/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo
Binary files differ
diff --git a/django/contrib/humanize/locale/en/LC_MESSAGES/django.po b/django/contrib/humanize/locale/en/LC_MESSAGES/django.po
index 0e7f3f33ed..360bdd94e6 100644
--- a/django/contrib/humanize/locale/en/LC_MESSAGES/django.po
+++ b/django/contrib/humanize/locale/en/LC_MESSAGES/django.po
@@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Django\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-05-07 21:53+0200\n"
+"POT-Creation-Date: 2011-05-16 17:30+0200\n"
"PO-Revision-Date: 2010-05-13 15:35+0200\n"
"Last-Translator: Django team\n"
"Language-Team: English <en@li.org>\n"
@@ -12,133 +12,166 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-#: templatetags/humanize.py:21
+#: templatetags/humanize.py:25
msgid "th"
msgstr ""
-#: templatetags/humanize.py:21
+#: templatetags/humanize.py:25
msgid "st"
msgstr ""
-#: templatetags/humanize.py:21
+#: templatetags/humanize.py:25
msgid "nd"
msgstr ""
-#: templatetags/humanize.py:21
+#: templatetags/humanize.py:25
msgid "rd"
msgstr ""
-#: templatetags/humanize.py:74
+#: templatetags/humanize.py:78
#, python-format
msgid "%(value).1f million"
msgid_plural "%(value).1f million"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:75
+#: templatetags/humanize.py:79
#, python-format
msgid "%(value)s million"
msgid_plural "%(value)s million"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:80
+#: templatetags/humanize.py:84
#, python-format
msgid "%(value).1f billion"
msgid_plural "%(value).1f billion"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:81
+#: templatetags/humanize.py:85
#, python-format
msgid "%(value)s billion"
msgid_plural "%(value)s billion"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:86
+#: templatetags/humanize.py:90
#, python-format
msgid "%(value).1f trillion"
msgid_plural "%(value).1f trillion"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:87
+#: templatetags/humanize.py:91
#, python-format
msgid "%(value)s trillion"
msgid_plural "%(value)s trillion"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "one"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "two"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "three"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "four"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "five"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "six"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "seven"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "eight"
msgstr ""
-#: templatetags/humanize.py:104
+#: templatetags/humanize.py:108
msgid "nine"
msgstr ""
-#: templatetags/humanize.py:127
+#: templatetags/humanize.py:131
msgid "today"
msgstr ""
-#: templatetags/humanize.py:129
+#: templatetags/humanize.py:133
msgid "tomorrow"
msgstr ""
-#: templatetags/humanize.py:131
+#: templatetags/humanize.py:135
msgid "yesterday"
msgstr ""
-#: templatetags/humanize.py:153
+#: templatetags/humanize.py:160
+#, python-format
+msgctxt "naturaltime"
+msgid "%(delta)s ago"
+msgstr ""
+
+#: templatetags/humanize.py:163 templatetags/humanize.py:185
msgid "now"
msgstr ""
-#: templatetags/humanize.py:155
+#: templatetags/humanize.py:166
#, python-format
-msgid "%s seconds ago"
-msgid_plural "%s seconds ago"
+msgid "a second ago"
+msgid_plural "%(count)s seconds ago"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:157
+#: templatetags/humanize.py:171
#, python-format
msgid "a minute ago"
-msgid_plural "%s minutes ago"
+msgid_plural "%(count)s minutes ago"
msgstr[0] ""
msgstr[1] ""
-#: templatetags/humanize.py:159
+#: templatetags/humanize.py:176
#, python-format
msgid "an hour ago"
-msgid_plural "%s hours ago"
+msgid_plural "%(count)s hours ago"
+msgstr[0] ""
+msgstr[1] ""
+
+#: templatetags/humanize.py:182
+#, python-format
+msgctxt "naturaltime"
+msgid "%(delta)s from now"
+msgstr ""
+
+#: templatetags/humanize.py:188
+#, python-format
+msgid "a second from now"
+msgid_plural "%(count)s seconds from now"
+msgstr[0] ""
+msgstr[1] ""
+
+#: templatetags/humanize.py:193
+#, python-format
+msgid "a minute from now"
+msgid_plural "%(count)s minutes from now"
+msgstr[0] ""
+msgstr[1] ""
+
+#: templatetags/humanize.py:198
+#, python-format
+msgid "an hour from now"
+msgid_plural "%(count)s hours from now"
msgstr[0] ""
msgstr[1] ""
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index 560f2a49ec..7a4defd392 100644
--- a/django/contrib/humanize/templatetags/humanize.py
+++ b/django/contrib/humanize/templatetags/humanize.py
@@ -1,11 +1,15 @@
-from django.utils.translation import ungettext, ugettext as _
-from django.utils.encoding import force_unicode
-from django.utils.formats import number_format
+import re
+from datetime import date, datetime, timedelta
+
from django import template
-from django.template import defaultfilters
from django.conf import settings
-from datetime import date, datetime
-import re
+from django.template import defaultfilters
+from django.utils.datetime_safe import datetime, date
+from django.utils.encoding import force_unicode
+from django.utils.formats import number_format
+from django.utils.translation import pgettext, ungettext, ugettext as _
+from django.utils.tzinfo import LocalTimezone
+
register = template.Library()
@@ -132,11 +136,10 @@ def naturalday(value, arg=None):
return defaultfilters.date(value, arg)
@register.filter
-def naturaltime(value, arg=None):
+def naturaltime(value):
"""
- For date and time values shows how many seconds, minutes or hours ago compared to
- current timestamp returns representing string. Otherwise, returns a string
- formatted according to settings.DATE_FORMAT
+ For date and time values shows how many seconds, minutes or hours ago
+ compared to current timestamp returns representing string.
"""
try:
value = datetime(value.year, value.month, value.day, value.hour, value.minute, value.second)
@@ -145,16 +148,52 @@ def naturaltime(value, arg=None):
except ValueError:
return value
- delta = datetime.now() - value
- if delta.days != 0:
- value = date(value.year, value.month, value.day)
- return naturalday(value, arg)
- elif delta.seconds == 0:
- return _(u'now')
- elif delta.seconds < 60:
- return ungettext(u'%s seconds ago', u'%s seconds ago', delta.seconds)
- elif delta.seconds / 60 < 60:
- return ungettext(u'a minute ago', u'%s minutes ago', delta.seconds/60)
- elif delta.seconds / 60 / 60 < 24:
- return ungettext(u'an hour ago', u'%s hours ago', delta.seconds/60/60)
- return naturalday(value, arg)
+ if getattr(value, 'tzinfo', None):
+ now = datetime.now(LocalTimezone(value))
+ else:
+ now = datetime.now()
+ now = now - timedelta(0, 0, now.microsecond)
+ if value < now:
+ delta = now - value
+ if delta.days != 0:
+ return pgettext(
+ 'naturaltime', '%(delta)s ago'
+ ) % {'delta': defaultfilters.timesince(value)}
+ elif delta.seconds == 0:
+ return _(u'now')
+ elif delta.seconds < 60:
+ return ungettext(
+ u'a second ago', u'%(count)s seconds ago', delta.seconds
+ ) % {'count': delta.seconds}
+ elif delta.seconds / 60 < 60:
+ count = delta.seconds / 60
+ return ungettext(
+ u'a minute ago', u'%(count)s minutes ago', count
+ ) % {'count': count}
+ else:
+ count = delta.seconds / 60 / 60
+ return ungettext(
+ u'an hour ago', u'%(count)s hours ago', count
+ ) % {'count': count}
+ else:
+ delta = value - now
+ if delta.days != 0:
+ return pgettext(
+ 'naturaltime', '%(delta)s from now'
+ ) % {'delta': defaultfilters.timeuntil(value)}
+ elif delta.seconds == 0:
+ return _(u'now')
+ elif delta.seconds < 60:
+ return ungettext(
+ u'a second from now', u'%(count)s seconds from now', delta.seconds
+ ) % {'count': delta.seconds}
+ elif delta.seconds / 60 < 60:
+ count = delta.seconds / 60
+ return ungettext(
+ u'a minute from now', u'%(count)s minutes from now', count
+ ) % {'count': count}
+ else:
+ count = delta.seconds / 60 / 60
+ return ungettext(
+ u'an hour from now', u'%(count)s hours from now', count
+ ) % {'count': count}