changeset ed166b127e4e in bugs.tryton.org:default
details: https://hg.tryton.org/bugs.tryton.org?cmd=changeset&node=ed166b127e4e
description:
        Use select for timezone
diffstat:

 extensions/time.py      |  10 ++++++++++
 html/user.item.html     |  11 +++++++++++
 html/user.register.html |  11 +++++++++++
 3 files changed, 32 insertions(+), 0 deletions(-)

diffs (58 lines):

diff -r 657b856cb939 -r ed166b127e4e extensions/time.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/time.py        Sun May 16 22:18:40 2021 +0200
@@ -0,0 +1,10 @@
+def get_common_timezones():
+    try:
+        import pytz
+        return pytz.common_timezones
+    except ImportError:
+        return []
+
+
+def init(instance):
+    instance.registerUtil('get_common_timezones', get_common_timezones)
diff -r 657b856cb939 -r ed166b127e4e html/user.item.html
--- a/html/user.item.html       Wed Apr 07 00:41:12 2021 +0200
+++ b/html/user.item.html       Sun May 16 22:18:40 2021 +0200
@@ -88,7 +88,18 @@
         <tr>
           <th>{% trans %}Timezone{% endtrans %}</th>
           <td>
+            {% with timezones = utils.get_common_timezones() %}
+            {% if timezones %}
+            <select class="custom-select" name="timezone">
+                <option value="">- no selection -</option>
+                {% for tz in timezones %}
+                <option value="{{ tz }}" {% if tz == context.timezone 
%}selected{% endif %}>{{ tz|u }}</option>
+                {% endfor %}
+            </select>
+            {% else %}
             <input class="form-control"  type='text' name='timezone' value='{{ 
context.timezone.plain()|u }}'>
+            {% endif %}
+            {% endwith %}
           </td>
         </tr>
         <tr>
diff -r 657b856cb939 -r ed166b127e4e html/user.register.html
--- a/html/user.register.html   Wed Apr 07 00:41:12 2021 +0200
+++ b/html/user.register.html   Sun May 16 22:18:40 2021 +0200
@@ -64,7 +64,18 @@
       <tr>
         <th>{% trans %}Timezone{% endtrans %}</th>
         <td>
+          {% with timezones = utils.get_common_timezones() %}
+          {% if timezones %}
+          <select class="custom-select" name="timezone">
+              <option value="">- no selection -</option>
+              {% for tz in timezones %}
+              <option value="{{ tz }}">{{ tz|u }}</option>
+              {% endfor %}
+          </select>
+          {% else %}
           <input type='text' name='timezone'>
+          {% endif %}
+          {% endwith %}
         </td>
       </tr>
       <tr>

Reply via email to