1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import datetime
28 import traceback
29 import logging
30
31 from django.conf import settings
32 from django import template
33
34 register = template.Library()
35
36 logger = logging.getLogger(__name__)
37
38
39 @register.tag
41 try:
42 tag_name, option = token.split_contents()
43 except ValueError:
44 raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents[0]
45 return SettingNode( option )
46
49 self.option = option
50
52
53 try:
54 return str(settings.__getattr__(self.option))
55 except:
56 return ""
57
59 - def __init__(self, quantity, single, plural):
60 self.quantity = template.Variable(quantity)
61 self.single = template.Variable(single)
62 self.plural = template.Variable(plural)
63
65 if self.quantity.resolve(context) == 1:
66 return u'%s' % self.single.resolve(context)
67 else:
68 return u'%s' % self.plural.resolve(context)
69
70 @register.tag(name="plural")
72 """
73 Usage: {% plural quantity name_singular name_plural %}
74
75 This simple version only works with template variable since we will use blocktrans for strings.
76 """
77
78 try:
79
80 tag_name, quantity, single, plural = token.split_contents()
81 except ValueError:
82 raise template.TemplateSyntaxError, "%r tag requires exactly three arguments" % token.contents.split()[0]
83
84 return PluralNode(quantity, single, plural)
85