Code

2a994c84279d5733a448116417aa93719e326828
[roundup.git] / share / roundup / templates / devel / extensions / timezone.py
1 # Utility for replacing the simple input field for the timezone with
2 # a select-field that lists the available values.
4 import cgi
6 try:
7     import pytz
8 except ImportError:
9     pytz = None
12 def tzfield(prop, name, default):
13     if pytz:
14         value = prop.plain()        
15         if '' == value:
16             value = default
17         else:
18             try:
19                 value = "Etc/GMT%+d" % int(value)
20             except ValueError:
21                 pass
23         l = ['<select name="%s"' % name]
24         for zone in pytz.all_timezones:
25             s = ' '
26             if zone == value:
27                 s = 'selected=selected '
28             z = cgi.escape(zone)
29             l.append('<option %svalue="%s">%s</option>' % (s, z, z))
30         l.append('</select>')
31         return '\n'.join(l)
32         
33     else:
34         return prop.field()
36 def init(instance):
37     instance.registerUtil('tzfield', tzfield)