Roman Numeral Filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Roman library comes from python-roman package on Debian which apparently comes from \
http://www.diveintopython.org/"""

from roman import toRoman

def romanize_filter(value, args=None):
    """Change int or long into Roman Numeral all other types are passed out
    You can add an argument like this:
        ...
        {{ object.id|romanize:"upper" }}
        ...
    For upper case roman numerals. The tag defaults to lowercase numerals for
    no good reason other than I prefer the look of them."""
    if isinstance(value, int) or isinstance(value, long):
        if args != None:
            if args.lower() == "upper":
                return toRoman(value)
            else:
                return toRoman(value).lower()
        else:
            return toRoman(value).lower()
    else:
        return value
register.filter('romanize', romanize_filter)

More like this

  1. Integer based MoneyField by Jay 2 years, 8 months ago
  2. TinyIntegerField by Lacour 9 months, 1 week ago
  3. django-admin custom filter: IS NULL/IS NOT NULL by Eloff 2 years, 2 months ago
  4. Query lookups using operators by diverman 1 year, 9 months ago
  5. int_to_base36 and base36_to_int by simon 3 years, 10 months ago

Comments

(Forgotten your password?)