diff options
author | Leif Johansson <leifj@sunet.se> | 2011-02-09 11:08:19 +0100 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-02-09 11:08:19 +0100 |
commit | 18fb871917ea875ed8a66c017947c2678d71f5f1 (patch) | |
tree | 90fd9bbe9d3c6842a27a7dbb4dfb614c1aa9a88b /src/templates/meetingtools/extensions | |
parent | c33af4c971f26fcf3e7eb61a6c3dd8e8af8418a6 (diff) |
restructure 2
Diffstat (limited to 'src/templates/meetingtools/extensions')
5 files changed, 68 insertions, 0 deletions
diff --git a/src/templates/meetingtools/extensions/__init__.py b/src/templates/meetingtools/extensions/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/templates/meetingtools/extensions/__init__.py diff --git a/src/templates/meetingtools/extensions/templatetags/__init__.py b/src/templates/meetingtools/extensions/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/templates/meetingtools/extensions/templatetags/__init__.py diff --git a/src/templates/meetingtools/extensions/templatetags/datehumanize.py b/src/templates/meetingtools/extensions/templatetags/datehumanize.py new file mode 100644 index 0000000..9570612 --- /dev/null +++ b/src/templates/meetingtools/extensions/templatetags/datehumanize.py @@ -0,0 +1,35 @@ +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): + 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/src/templates/meetingtools/extensions/templatetags/prefix.py b/src/templates/meetingtools/extensions/templatetags/prefix.py new file mode 100644 index 0000000..4defd38 --- /dev/null +++ b/src/templates/meetingtools/extensions/templatetags/prefix.py @@ -0,0 +1,13 @@ +''' +Created on Feb 9, 2011 + +@author: leifj +''' + +from django import template +from meetingtools.settings import PREFIX_URL +register = template.Library() + +@register.simple_tag +def prefix(): + return PREFIX_URL
\ No newline at end of file diff --git a/src/templates/meetingtools/extensions/templatetags/roomurl.py b/src/templates/meetingtools/extensions/templatetags/roomurl.py new file mode 100644 index 0000000..37f1e80 --- /dev/null +++ b/src/templates/meetingtools/extensions/templatetags/roomurl.py @@ -0,0 +1,20 @@ +from django import template +from meetingtools.settings import BASE_URL + +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 "%s/go/%s" % (BASE_URL,path) + +roomurl.is_safe = True +register.filter(roomurl)
\ No newline at end of file |