summaryrefslogtreecommitdiff
path: root/meetingtools/extensions
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2011-02-08 20:46:40 +0100
committerLeif Johansson <leifj@sunet.se>2011-02-08 20:46:40 +0100
commit0fb514f0a73aef806b826348d043c68534af2745 (patch)
treebd388ab8e3de4c93a6ba0a5e1b83a4087a14b6e2 /meetingtools/extensions
parenta20ff434501a099b259da903d88b47bb77e07469 (diff)
v1
Diffstat (limited to 'meetingtools/extensions')
-rw-r--r--meetingtools/extensions/templatetags/__init__.py0
-rw-r--r--meetingtools/extensions/templatetags/datehumanize.py35
-rw-r--r--meetingtools/extensions/templatetags/roomurl.py20
3 files changed, 55 insertions, 0 deletions
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..9570612
--- /dev/null
+++ b/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/meetingtools/extensions/templatetags/roomurl.py b/meetingtools/extensions/templatetags/roomurl.py
new file mode 100644
index 0000000..37f1e80
--- /dev/null
+++ b/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