X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/fb8a270fa22abc217efc471d860c76d5a2352c61..0959d38b27c03863ec376839dcc6d896d04e36ea:/philo/contrib/penfield/templatetags/penfield.py diff --git a/philo/contrib/penfield/templatetags/penfield.py b/philo/contrib/penfield/templatetags/penfield.py index 99e358c..b263a2b 100644 --- a/philo/contrib/penfield/templatetags/penfield.py +++ b/philo/contrib/penfield/templatetags/penfield.py @@ -1,22 +1,37 @@ +""" +Penfield supplies two template filters to handle common use cases for blogs and newsletters. + +""" from django import template from django.utils.dates import MONTHS, MONTHS_AP + register = template.Library() + +@register.filter def monthname(value): - monthnum = int(value) - if 1 <= monthnum <= 12: - return MONTHS[monthnum] - else: + """Returns the name of a month with the supplied numeric value.""" + try: + value = int(value) + except: + pass + + try: + return MONTHS[value] + except KeyError: return value -register.filter('monthname', monthname) +@register.filter def apmonthname(value): - monthnum = int(value) - if 1 <= monthnum <= 12: - return MONTHS_AP[monthnum] - else: - return value - -register.filter('apmonthname', apmonthname) + """Returns the Associated Press abbreviated month name for the supplied numeric value.""" + try: + value = int(value) + except: + pass + + try: + return MONTHS_AP[value] + except KeyError: + return value \ No newline at end of file