Added a templatetag for table field to show date in ordinal fashion.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Fri, 18 Sep 2009 20:35:55 +0530
changeset 2948 66fe1a62d4e2
parent 2947 435f8701c6bc
child 2949 22ec1c2e6621
Added a templatetag for table field to show date in ordinal fashion.
app/soc/views/helper/templatetags/forms_helpers.py
--- a/app/soc/views/helper/templatetags/forms_helpers.py	Thu Sep 17 23:37:55 2009 +0200
+++ b/app/soc/views/helper/templatetags/forms_helpers.py	Fri Sep 18 20:35:55 2009 +0530
@@ -133,6 +133,28 @@
   return {'field_label': label,
           'field_value': value}
 
+@register.inclusion_tag('soc/templatetags/_readonly_field_as_table_row.html')
+def readonly_date_field_as_table_row(label, value):
+  """Prints a field value formatted as the given format string.
+
+  """
+
+  import datetime
+  if isinstance(value, datetime.datetime):
+    if value.day % 10 == 1 and value.day != 11:
+      ord_suf = 'st'
+    elif value.day % 10 == 2 and value.day != 12:
+      ord_suf = 'nd'
+    elif value.day % 10 == 3 and value.day != 13:
+      ord_suf = 'rd'
+    else:
+      ord_suf = 'th'
+
+    fmt = "%d" + ord_suf + " %B %Y, %H:%M"
+    value = value.strftime(fmt)
+
+  return {'field_label': label,
+          'field_value': value}
 
 @register.inclusion_tag(
     'soc/templatetags/_readonly_url_field_as_table_row.html')