Login

Make Proper Nouns Posessive

Author:
skarphace
Posted:
June 5, 2013
Language:
Python
Version:
1.5
Tags:
template filter
Score:
0 (after 0 ratings)

A template filter to make proper nouns posessive. If context_var was 'skarphace':

{{ context_var|s }}

Would be:

skarphace's
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import re
from django import template
register = template.Library()

@register.filter
def s(value):
    """
    Add an "'s" or "'" where appropriate on proper nouns to to make them posessive
    """
    if re.search(r's$', value):
        return value + "'"
    else:
        return value + "'s"

More like this

  1. split filter by Ciantic 8 years, 4 months ago
  2. HTTPS redirections middleware with updated URL template tag by xlq 2 years, 10 months ago
  3. template filter to include protocol and domain in absolute urls by czer 3 years, 1 month ago
  4. simple string formatting filter by gsf0 8 years ago
  5. Filter by first letter inclusion tag by slafs 5 years, 3 months ago

Comments

Please login first before commenting.