diff options
author | Leif Johansson <leifj@sunet.se> | 2012-10-04 15:39:08 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2012-10-04 15:39:08 +0200 |
commit | 2bdad0ae7a3a6e4ec5116becd39910388b679ed2 (patch) | |
tree | 5afdfba0a93c1af50d53bdc245d57cc4053e109a /meetingtools/extensions | |
parent | 873e7823970352d591deee5f67f47c5436ee0e84 (diff) |
restructure
Diffstat (limited to 'meetingtools/extensions')
-rw-r--r-- | meetingtools/extensions/__init__.py | 0 | ||||
-rw-r--r-- | meetingtools/extensions/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | meetingtools/extensions/templatetags/datehumanize.py | 36 | ||||
-rw-r--r-- | meetingtools/extensions/templatetags/roomurl.py | 19 |
4 files changed, 55 insertions, 0 deletions
diff --git a/meetingtools/extensions/__init__.py b/meetingtools/extensions/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/meetingtools/extensions/__init__.py diff --git a/meetingtools/extensions/templatetags/__init__.py b/meetingtools/extensions/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/meetingtools/extensions/templatetags/__init__.py diff --git a/meetingtools/extensions/templatetags/datehumanize.py b/meetingtools/extensions/templatetags/datehumanize.py new file mode 100644 index 0000000..9b75cae --- /dev/null +++ b/meetingtools/extensions/templatetags/datehumanize.py @@ -0,0 +1,36 @@ +from django import template +from django.template import defaultfilters + +register = template.Library() + +MOMENT = 120 # duration in seconds within which the time difference + # will be rendered as 'a moment ago' + +def datehumanize(value): + """ + Finds the difference between the datetime value given and now() + and returns appropriate humanize form + """ + + from datetime import datetime + + if isinstance(value, datetime): + value = value.replace(tzinfo=None) + delta = datetime.now() - value + if delta.days > 6: + return value.strftime("on %b %d") # May 15 + if delta.days > 1: + return value.strftime("on %A") # Wednesday + elif delta.days == 1: + return 'yesterday' # yesterday + elif delta.seconds > 3600: + return str(delta.seconds / 3600 ) + ' hours ago' # 3 hours ago + elif delta.seconds > MOMENT: + return str(delta.seconds/60) + ' minutes ago' # 29 minutes ago + else: + return 'a moment ago' # a moment ago + return defaultfilters.date(value) + else: + return str(value) +datehumanize.is_safe = True +register.filter(datehumanize)
\ No newline at end of file diff --git a/meetingtools/extensions/templatetags/roomurl.py b/meetingtools/extensions/templatetags/roomurl.py new file mode 100644 index 0000000..e5abe57 --- /dev/null +++ b/meetingtools/extensions/templatetags/roomurl.py @@ -0,0 +1,19 @@ +from django import template + +register = template.Library() + +MOMENT = 120 # duration in seconds within which the time difference + # will be rendered as 'a moment ago' + +def roomurl(room): + """ + Display the public 'go' URL of a meetingroom + """ + path = room.id + if room.urlpath: + path = room.urlpath + + return "/go/%s" % path + +roomurl.is_safe = True +register.filter(roomurl)
\ No newline at end of file |