Statistics
| Branch: | Tag: | Revision:

root / edumanage / templatetags / tolocale.py @ fa8b2f7d

History | View | Annotate | Download (856 Bytes)

1
from django import template
2
from edumanage.models import * 
3

    
4
register = template.Library()
5

    
6
@register.filter
7
def do_tolocale(parser, token):
8
    print token
9
    try:
10
        tag_name, inst, format_string = token.split_contents()
11
        print inst
12
    except ValueError:
13
        raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
14
    return CurrentLocaleNode(inst, format_string)
15

    
16

    
17
class CurrentLocaleNode(template.Node):
18
    def __init__(self, inst, format_string):
19
        self.format_string = format_string
20
        self.inst = template.Variable(inst)
21
        print self.format_string, "STING"
22
    def render(self, context):
23
        inst_pk = self.inst.resolve(context)
24
        return Institution.objects.get(pk=inst_pk).__unicode__(lang=str(self.format_string))
25

    
26
register.tag('tolocale', do_tolocale)