Added directives and autodocumenters for template tags and filters in a custom extens...
[philo.git] / philo / contrib / penfield / templatetags / penfield.py
1 """
2 Penfield supplies two template filters to handle common use cases for blogs and newsletters.
3
4 """
5 from django import template
6 from django.utils.dates import MONTHS, MONTHS_AP
7
8
9 register = template.Library()
10
11
12 @register.filter
13 def monthname(value):
14         """Returns the name of a month with the supplied numeric value."""
15         try:
16                 value = int(value)
17         except:
18                 pass
19         
20         try:
21                 return MONTHS[value]
22         except KeyError:
23                 return value
24
25
26 @register.filter
27 def apmonthname(value):
28         """Returns the Associated Press abbreviated month name for the supplied numeric value."""
29         try:
30                 value = int(value)
31         except:
32                 pass
33         
34         try:
35                 return MONTHS_AP[value]
36         except KeyError:
37                 return value