# HG changeset patch # User Madhusudan.C.S # Date 1253286355 -19800 # Node ID 66fe1a62d4e2327710d31c654ffdcc52bcf85f41 # Parent 435f8701c6bc7468105c9a2b09517d3b6ec0987b Added a templatetag for table field to show date in ordinal fashion. diff -r 435f8701c6bc -r 66fe1a62d4e2 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')