Revision f60df981 edumanage/templatetags/tolocale.py
b/edumanage/templatetags/tolocale.py | ||
---|---|---|
5 | 5 |
|
6 | 6 |
@register.filter |
7 | 7 |
def do_tolocale(parser, token): |
8 |
print token |
|
9 | 8 |
try: |
10 |
tag_name, inst, format_string = token.split_contents() |
|
11 |
print inst |
|
9 |
tag_name, objtrans, format_string = token.split_contents() |
|
12 | 10 |
except ValueError: |
13 | 11 |
raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0] |
14 |
return CurrentLocaleNode(inst, format_string)
|
|
12 |
return CurrentLocaleNode(objtrans, format_string)
|
|
15 | 13 |
|
16 | 14 |
|
17 | 15 |
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" |
|
16 |
def __init__(self, objtrans, format_string): |
|
17 |
self.format_string = template.Variable(format_string) |
|
18 |
self.objtrans = template.Variable(objtrans) |
|
22 | 19 |
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)) |
|
20 |
objtrans = self.objtrans.resolve(context) |
|
21 |
translang = self.format_string.resolve(context) |
|
22 |
return objtrans.get_name(lang=translang) |
|
25 | 23 |
|
26 | 24 |
register.tag('tolocale', do_tolocale) |
Also available in: Unified diff