Add UTC offset information to the timezone

In the User Settings, indicate besides the timezone name what the
actual timezone/UTC offset is.

Fixes bug 1103003

Change-Id: I8070df2bc0380da1555c40dc9394895fbfde6848
This commit is contained in:
Julie Pichon 2013-01-22 14:53:15 +00:00
parent b8071bcce7
commit 0d303c8e6d
2 changed files with 47 additions and 1 deletions

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from datetime import datetime
import pytz
from django import shortcuts
@ -38,7 +39,21 @@ class UserSettingsForm(forms.SelfHandlingForm):
self.fields['language'].choices = languages
# Timezones
timezones = [(tz, tz) for tz in pytz.common_timezones]
d = datetime(2011, 1, 1)
timezones = []
for tz in pytz.common_timezones:
try:
utc_offset = pytz.timezone(tz).localize(d).strftime('%z')
utc_offset = " (UTC %s:%s)" % (utc_offset[:3], utc_offset[3:])
except:
utc_offset = ""
if tz != "UTC":
tz_name = "%s%s" % (tz, utc_offset)
else:
tz_name = tz
timezones.append((tz, tz_name))
self.fields['timezone'].choices = timezones
def handle(self, request, data):

View File

@ -0,0 +1,31 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.core.urlresolvers import reverse
from openstack_dashboard.test import helpers as test
INDEX_URL = reverse("horizon:settings:user:index")
class UserSettingsTest(test.TestCase):
def test_timezone_offset_is_displayed(self):
res = self.client.get(INDEX_URL)
self.assertContains(res, "Australia/Melbourne (UTC +11:00)")
self.assertContains(res, "Canada/Newfoundland (UTC -03:30)")