bt.py 894 Bytes
Newer Older
1 2 3 4
from django.template import Library, Variable
from django.conf import settings
from django import template
import random
Okhin's avatar
Okhin committed
5
from ..models import COUNTRIES, STATUS, TYPES, MEDIA
6 7 8

register = Library()

jc's avatar
jc committed
9

10 11
@register.simple_tag
def root_url():
12
    return settings.ROOT_URL
13

jc's avatar
jc committed
14

15 16 17 18
@register.simple_tag
def media_url():
    return settings.MEDIA_URL

jc's avatar
jc committed
19 20 21 22

country_map = dict(COUNTRIES)


23 24 25
@register.filter(name='country')
def country(code):
    return country_map[code]
stef's avatar
stef committed
26

jc's avatar
jc committed
27 28 29 30

status_map = dict(STATUS)


stef's avatar
stef committed
31 32
@register.filter(name='status')
def status(code):
33 34 35 36
    try:
        return status_map[code]
    except:
        return code
37

jc's avatar
jc committed
38 39 40 41

type_map = dict(TYPES)


42 43
@register.filter(name='type')
def type(code):
44 45 46 47
    try:
        return type_map[code]
    except:
        return code
48

jc's avatar
jc committed
49 50 51 52

media_map = dict(MEDIA)


53 54
@register.filter(name='media')
def media(code):
55 56 57 58
    try:
        return media_map[code]
    except:
        return code