--- a/HelloForge/helloforge/model/wiki.py
+++ b/HelloForge/helloforge/model/wiki.py
@@ -1,4 +1,5 @@
from time import sleep
+from datetime import datetime
from pylons import g #g is a namespace for globally accessable app helpers
from pylons import c as context
@@ -147,6 +148,22 @@
"""The page this comment connects too"""
return Page.query.get(_id=self.page_id)
+ @property
+ def posted_ago(self):
+ comment_td = (datetime.utcnow() - self.timestamp)
+ if comment_td.seconds < 3600 and comment_td.days < 1:
+ return "%s minutes ago" % (comment_td.seconds / 60)
+ elif comment_td.seconds >= 3600 and comment_td.days < 1:
+ return "%s hours ago" % (comment_td.seconds / 3600)
+ elif comment_td.days >= 1 and comment_td.days < 7:
+ return "%s days ago" % comment_td.days
+ elif comment_td.days >= 7 and comment_td.days < 30:
+ return "%s weeks ago" % (comment_td.days / 7)
+ elif comment_td.days >= 30 and comment_td.days < 365:
+ return "%s months ago" % (comment_td.days / 30)
+ else:
+ return "%s years ago" % (comment_td.days / 365)
+
def url(self):
"""The URL for this specific comment"""
return self.page.url() + '#comment-' + self._id