You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/05/17 00:30:38 UTC
[47/50] [abbrv] git commit: [#6212] use registration date (was stats
start date), and date delta helper
[#6212] use registration date (was stats start date), and date delta helper
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/98341829
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/98341829
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/98341829
Branch: refs/heads/db/6208
Commit: 983418297d860e04a777e29ff1edd3b0919ba77a
Parents: 6c43eac
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed May 15 18:00:55 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed May 15 21:19:58 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/helpers.py | 4 ++--
Allura/allura/tests/test_helpers.py | 6 ++++++
ForgeUserStats/forgeuserstats/templates/index.html | 2 +-
3 files changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/98341829/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 5ac7abb..f2af4a6 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -277,7 +277,7 @@ def cryptographic_nonce(length=40):
hex_format = '%.2x' * length
return hex_format % tuple(map(ord, os.urandom(length)))
-def ago(start_time):
+def ago(start_time, show_date_after=7):
"""
Return time since starting time as a rounded, human readable string.
E.g., "3 hours ago"
@@ -287,7 +287,7 @@ def ago(start_time):
granularities = ['century', 'decade', 'year', 'month', 'day', 'hour',
'minute']
end_time = datetime.utcnow()
- if end_time - start_time > timedelta(days=7):
+ if show_date_after is not None and end_time - start_time > timedelta(days=show_date_after):
return start_time.strftime('%Y-%m-%d')
while True:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/98341829/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 3ed21f4..904d188 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -147,6 +147,12 @@ def test_ago():
assert_equals(h.ago_string('bad format'), 'unknown')
assert_equals(h.ago_string(None), 'unknown')
+ monthish = datetime.utcnow() - timedelta(days=32)
+ assert 'ago' not in h.ago(monthish)
+ assert_equals(h.ago(monthish, show_date_after=90), '1 month ago')
+ assert_equals(h.ago(monthish, show_date_after=None), '1 month ago')
+
+
def test_urlquote_unicode():
# No exceptions please
h.urlquote(u'\u0410')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/98341829/ForgeUserStats/forgeuserstats/templates/index.html
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/templates/index.html b/ForgeUserStats/forgeuserstats/templates/index.html
index 08fd14c..da61f23 100644
--- a/ForgeUserStats/forgeuserstats/templates/index.html
+++ b/ForgeUserStats/forgeuserstats/templates/index.html
@@ -49,7 +49,7 @@
<tr>
<td>Registration date</td>
<td>{{registration_date.strftime("%d %b %Y, %H:%M:%S (UTC)")}}</td>
- <td>{{days}} day{% if days != 1 %}s{% endif %} ago</td>
+ <td>{{h.ago(registration_date, show_date_after=None)}}</td>
</tr>
{% if last_login %}
<tr>