X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/ddec93c912e97f33769cd08a8ed470d3b67162e5..30c59c96869c9996540f1cf844dadd38d00ab8f3:/philo/contrib/penfield/templatetags/penfield.py diff --git a/philo/contrib/penfield/templatetags/penfield.py b/philo/contrib/penfield/templatetags/penfield.py index 99e358c..7b9d946 100644 --- a/philo/contrib/penfield/templatetags/penfield.py +++ b/philo/contrib/penfield/templatetags/penfield.py @@ -1,22 +1,46 @@ +""" +Penfield supplies two template filters: + +.. templatefilter:: monthname + +monthname +--------- +Returns the name of a month with the supplied numeric value. + +.. templatefilter:: apmonthname + +apmonthname +----------- +Returns the Associated Press abbreviated month name for the supplied numeric value. + +""" from django import template from django.utils.dates import MONTHS, MONTHS_AP register = template.Library() def monthname(value): - monthnum = int(value) - if 1 <= monthnum <= 12: - return MONTHS[monthnum] - else: + try: + value = int(value) + except: + pass + + try: + return MONTHS[value] + except KeyError: return value register.filter('monthname', monthname) def apmonthname(value): - monthnum = int(value) - if 1 <= monthnum <= 12: - return MONTHS_AP[monthnum] - else: + try: + value = int(value) + except: + pass + + try: + return MONTHS_AP[value] + except KeyError: return value register.filter('apmonthname', apmonthname)