Mercurial > p > roundup > code
comparison website/issues/extensions/timezone.py @ 4024:c2d0d3e9099d website
svn repository setup
| author | Stefan Seefeld <stefan@users.sourceforge.net> |
|---|---|
| date | Fri, 06 Feb 2009 13:16:31 +0000 |
| parents | |
| children | 7d8e0dbb0852 |
comparison
equal
deleted
inserted
replaced
| 4023:86c38b5aed66 | 4024:c2d0d3e9099d |
|---|---|
| 1 # Utility for replacing the simple input field for the timezone with | |
| 2 # a select-field that lists the available values. | |
| 3 | |
| 4 import cgi | |
| 5 | |
| 6 try: | |
| 7 import pytz | |
| 8 except ImportError: | |
| 9 pytz = None | |
| 10 | |
| 11 | |
| 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 | |
| 22 | |
| 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() | |
| 35 | |
| 36 def init(instance): | |
| 37 instance.registerUtil('tzfield', tzfield) |
