diff options
author | Jacob Mason <jacoblmason@gmail.com> | 2010-07-11 14:15:30 -0500 |
---|---|---|
committer | Jacob Mason <jacoblmason@gmail.com> | 2010-07-11 14:15:30 -0500 |
commit | a097429ec8d1e8fb8bcdc33653865d3111c1b3fd (patch) | |
tree | f06e5712704e5f09b27fb7bdd9b42f344ca56bd7 | |
parent | d08dae898a9df196bcb02855269263917e3312d0 (diff) | |
download | sphinx-git-a097429ec8d1e8fb8bcdc33653865d3111c1b3fd.tar.gz |
Sortable comments
-rw-r--r-- | sphinx/websupport/comments/__init__.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sphinx/websupport/comments/__init__.py b/sphinx/websupport/comments/__init__.py index 5ca299246..395bde580 100644 --- a/sphinx/websupport/comments/__init__.py +++ b/sphinx/websupport/comments/__init__.py @@ -93,6 +93,8 @@ class SQLAlchemyComments(CommentBackend): self.session.commit() def serializable(self, comment, user_id=None): + delta = datetime.now() - comment.time + time = {'year': comment.time.year, 'month': comment.time.month, 'day': comment.time.day, @@ -100,7 +102,7 @@ class SQLAlchemyComments(CommentBackend): 'minute': comment.time.minute, 'second': comment.time.second, 'iso': comment.time.isoformat(), - 'delta': self.pretty_delta(comment)} + 'delta': self.pretty_delta(delta)} vote = '' if user_id is not None: @@ -114,6 +116,7 @@ class SQLAlchemyComments(CommentBackend): 'username': comment.username or 'Anonymous', 'id': comment.id, 'rating': comment.rating, + 'age': delta.seconds, 'time': time, 'vote': vote or 0, 'node': comment.node.id if comment.node else None, @@ -121,8 +124,7 @@ class SQLAlchemyComments(CommentBackend): 'children': [self.serializable(child, user_id) for child in comment.children]} - def pretty_delta(self, comment): - delta = datetime.now() - comment.time + def pretty_delta(self, delta): days = delta.days seconds = delta.seconds hours = seconds / 3600 |