[Python-checkins] r57507 - in tracker/instances/python-dev: extensions/timezone.py html/user.item.html

erik.forsberg python-checkins at python.org
Sun Aug 26 19:08:32 CEST 2007


Author: erik.forsberg
Date: Sun Aug 26 19:08:32 2007
New Revision: 57507

Added:
   tracker/instances/python-dev/extensions/timezone.py
Modified:
   tracker/instances/python-dev/html/user.item.html
Log:

Allow user to select timezone by name, not by offset. Resolves
http://psf.upfronthosting.co.za/roundup/meta/issue139.


Added: tracker/instances/python-dev/extensions/timezone.py
==============================================================================
--- (empty file)
+++ tracker/instances/python-dev/extensions/timezone.py	Sun Aug 26 19:08:32 2007
@@ -0,0 +1,37 @@
+# Utility for replacing the simple input field for the timezone with
+# a select-field that lists the available values.
+
+import cgi
+
+try:
+    import pytz
+except ImportError:
+    pytz = None
+
+
+def tzfield(prop, name, default):
+    if pytz:
+        value = prop.plain()        
+        if '' == value:
+            value = default
+        else:
+            try:
+                value = "Etc/GMT%+d" % int(value)
+            except ValueError:
+                pass
+
+        l = ['<select name="%s"' % name]
+        for zone in pytz.all_timezones:
+            s = ' '
+            if zone == value:
+                s = 'selected=selected '
+            z = cgi.escape(zone)
+            l.append('<option %svalue="%s">%s</option>' % (s, z, z))
+        l.append('</select>')
+        return '\n'.join(l)
+        
+    else:
+        return prop.field()
+
+def init(instance):
+    instance.registerUtil('tzfield', tzfield)

Modified: tracker/instances/python-dev/html/user.item.html
==============================================================================
--- tracker/instances/python-dev/html/user.item.html	(original)
+++ tracker/instances/python-dev/html/user.item.html	Sun Aug 26 19:08:32 2007
@@ -102,10 +102,8 @@
  <tr tal:condition="python:edit_ok or context.timezone"
      tal:define="name string:timezone; label string:Timezone; value context/timezone">
   <th metal:use-macro="th_label">Timezone</th>
-  <td><input name="timezone" metal:use-macro="normal_input">
-   <tal:block tal:condition="edit_ok" i18n:translate="">(this is a numeric hour offset, the default is
-    <span tal:replace="db/config/DEFAULT_TIMEZONE" i18n:name="zone"
-    />)</tal:block>
+  <td><input tal:replace="structure python:
+       utils.tzfield(context.timezone, 'timezone', db.config.DEFAULT_TIMEZONE)"/>
   </td>
  </tr>
 


More information about the Python-checkins mailing list