Merge lp:~cjwatson/launchpad/new-person-edit-timezone into lp:launchpad

Proposed by Colin Watson on 2016-04-28
Status: Merged
Merged at revision: 18126
Proposed branch: lp:~cjwatson/launchpad/new-person-edit-timezone
Merge into: lp:launchpad
Diff against target: 221 lines (+26/-29)
10 files modified
lib/lp/app/browser/tales.py (+2/-4)
lib/lp/app/doc/tales.txt (+4/-1)
lib/lp/app/widgets/date.py (+3/-4)
lib/lp/registry/browser/person.py (+4/-9)
lib/lp/registry/model/person.py (+2/-2)
lib/lp/registry/stories/location/personlocation-edit.txt (+4/-2)
lib/lp/registry/stories/webservice/xx-person.txt (+2/-2)
lib/lp/registry/stories/webservice/xx-personlocation.txt (+2/-2)
lib/lp/registry/templates/person-portlet-contact-details.pt (+1/-1)
lib/lp/services/webapp/launchbag.py (+2/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/new-person-edit-timezone
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve on 2016-07-11
Launchpad code reviewers 2016-04-28 Pending
Review via email: mp+293188@code.launchpad.net

Commit message

Make Person.time_zone always be non-None, allowing us to easily show the edit widget even for users who have never set their time zone.

Description of the change

Make Person.time_zone always be non-None, allowing us to easily show the edit widget even for users who have never set their time zone.

Fixing bug 933699 would also be a valid approach to this, but that's rather more work, and I think it makes sense in any event for the Person.time_zone property to deal with picking a reasonable default rather than callers having to do so.

To post a comment you must log in.
Thomi Richards (thomir) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/app/browser/tales.py'
--- lib/lp/app/browser/tales.py 2016-05-12 14:08:38 +0000
+++ lib/lp/app/browser/tales.py 2016-07-12 13:41:10 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2015 Canonical Ltd. This software is licensed under the1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Implementation of the lp: htmlform: fmt: namespaces in TALES."""4"""Implementation of the lp: htmlform: fmt: namespaces in TALES."""
@@ -1199,9 +1199,7 @@
11991199
1200 def local_time(self):1200 def local_time(self):
1201 """Return the local time for this person."""1201 """Return the local time for this person."""
1202 time_zone = 'UTC'1202 time_zone = self._context.time_zone
1203 if self._context.time_zone is not None:
1204 time_zone = self._context.time_zone
1205 return datetime.now(pytz.timezone(time_zone)).strftime('%T %Z')1203 return datetime.now(pytz.timezone(time_zone)).strftime('%T %Z')
12061204
1207 def url(self, view_name=None, rootsite='mainsite'):1205 def url(self, view_name=None, rootsite='mainsite'):
12081206
=== modified file 'lib/lp/app/doc/tales.txt'
--- lib/lp/app/doc/tales.txt 2016-02-06 01:41:00 +0000
+++ lib/lp/app/doc/tales.txt 2016-07-12 13:41:10 +0000
@@ -487,8 +487,11 @@
487 >>> test_tales("person/fmt:local-time", person=sample_person)487 >>> test_tales("person/fmt:local-time", person=sample_person)
488 '... AWST'488 '... AWST'
489489
490 >>> print mark.time_zone490 >>> from zope.security.proxy import removeSecurityProxy
491 >>> print removeSecurityProxy(mark).location
491 None492 None
493 >>> mark.time_zone
494 u'UTC'
492495
493 >>> test_tales("person/fmt:local-time", person=mark)496 >>> test_tales("person/fmt:local-time", person=mark)
494 '... UTC'497 '... UTC'
495498
=== modified file 'lib/lp/app/widgets/date.py'
--- lib/lp/app/widgets/date.py 2013-04-10 08:05:17 +0000
+++ lib/lp/app/widgets/date.py 2016-07-12 13:41:10 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""These widgets use the a YUI2 calendar widget to allow for4"""These widgets use the a YUI2 calendar widget to allow for
@@ -178,9 +178,8 @@
178178
179 The widget "system time zone" is generally UTC. It is the logged in179 The widget "system time zone" is generally UTC. It is the logged in
180 users time zone, with a fallback to UTC if there is no logged in180 users time zone, with a fallback to UTC if there is no logged in
181 user, or if the logged in user has not given us a time zone.181 user. Although this isn't used directly, it influences the outcome
182 Although this isn't used directly, it influences the outcome of182 of widget.time_zone.
183 widget.time_zone.
184183
185 >>> print widget.system_time_zone184 >>> print widget.system_time_zone
186 UTC185 UTC
187186
=== modified file 'lib/lp/registry/browser/person.py'
--- lib/lp/registry/browser/person.py 2016-06-13 03:15:44 +0000
+++ lib/lp/registry/browser/person.py 2016-07-12 13:41:10 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2015 Canonical Ltd. This software is licensed under the1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Person-related view classes."""4"""Person-related view classes."""
@@ -210,10 +210,8 @@
210from lp.services.gpg.interfaces import (210from lp.services.gpg.interfaces import (
211 GPG_DATABASE_READONLY_FEATURE_FLAG,211 GPG_DATABASE_READONLY_FEATURE_FLAG,
212 GPG_HIDE_PERSON_KEY_LISTING,212 GPG_HIDE_PERSON_KEY_LISTING,
213 GPG_WRITE_TO_GPGSERVICE_FEATURE_FLAG,
214 GPGKeyNotFoundError,213 GPGKeyNotFoundError,
215 GPGReadOnly,214 GPGReadOnly,
216 IGPGClient,
217 IGPGHandler,215 IGPGHandler,
218 )216 )
219from lp.services.identity.interfaces.account import (217from lp.services.identity.interfaces.account import (
@@ -2561,8 +2559,8 @@
2561 self.key_already_imported = True2559 self.key_already_imported = True
2562 return2560 return
25632561
2564 # Launchpad talks to the keyserver directly to check if the key has been2562 # Launchpad talks to the keyserver directly to check if the key has
2565 # uploaded to the key server.2563 # been uploaded to the key server.
2566 try:2564 try:
2567 key = gpghandler.retrieveKey(self.fingerprint)2565 key = gpghandler.retrieveKey(self.fingerprint)
2568 except GPGKeyNotFoundError:2566 except GPGKeyNotFoundError:
@@ -4006,10 +4004,7 @@
40064004
4007 @property4005 @property
4008 def initial_values(self):4006 def initial_values(self):
4009 if self.context.time_zone is None:4007 return {'time_zone': self.context.time_zone}
4010 return {}
4011 else:
4012 return dict(time_zone=self.context.time_zone)
40134008
4014 @property4009 @property
4015 def next_url(self):4010 def next_url(self):
40164011
=== modified file 'lib/lp/registry/model/person.py'
--- lib/lp/registry/model/person.py 2016-06-02 04:39:33 +0000
+++ lib/lp/registry/model/person.py 2016-07-12 13:41:10 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2015 Canonical Ltd. This software is licensed under the1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Implementation classes for a Person."""4"""Implementation classes for a Person."""
@@ -773,7 +773,7 @@
773 def time_zone(self):773 def time_zone(self):
774 """See `IHasLocation`."""774 """See `IHasLocation`."""
775 if self.location is None:775 if self.location is None:
776 return None776 return u'UTC'
777 # Wrap the location with a security proxy to make sure the user has777 # Wrap the location with a security proxy to make sure the user has
778 # enough rights to see it.778 # enough rights to see it.
779 return ProxyFactory(self.location).time_zone779 return ProxyFactory(self.location).time_zone
780780
=== modified file 'lib/lp/registry/stories/location/personlocation-edit.txt'
--- lib/lp/registry/stories/location/personlocation-edit.txt 2016-01-26 15:47:37 +0000
+++ lib/lp/registry/stories/location/personlocation-edit.txt 2016-07-12 13:41:10 +0000
@@ -20,7 +20,8 @@
20A user can set their own time zone:20A user can set their own time zone:
2121
22 >>> self_browser = setupBrowser(auth="Basic zzz@foo.com:test")22 >>> self_browser = setupBrowser(auth="Basic zzz@foo.com:test")
23 >>> self_browser.open('http://launchpad.dev/~zzz/+editlocation')23 >>> self_browser.open('http://launchpad.dev/~zzz')
24 >>> self_browser.getLink('Set location and time zone').click()
24 >>> self_browser.getControl(name='field.time_zone').value = [25 >>> self_browser.getControl(name='field.time_zone').value = [
25 ... 'Europe/Madrid']26 ... 'Europe/Madrid']
26 >>> self_browser.getControl('Update').click()27 >>> self_browser.getControl('Update').click()
@@ -33,6 +34,7 @@
33And when they come back to change it later, they'll see it there as the34And when they come back to change it later, they'll see it there as the
34selected value.35selected value.
3536
36 >>> self_browser.open('http://launchpad.dev/~zzz/+editlocation')37 >>> self_browser.open('http://launchpad.dev/~zzz')
38 >>> self_browser.getLink('Set location and time zone').click()
37 >>> print self_browser.getControl(name='field.time_zone').value39 >>> print self_browser.getControl(name='field.time_zone').value
38 ['Europe/Madrid']40 ['Europe/Madrid']
3941
=== modified file 'lib/lp/registry/stories/webservice/xx-person.txt'
--- lib/lp/registry/stories/webservice/xx-person.txt 2016-04-12 10:50:30 +0000
+++ lib/lp/registry/stories/webservice/xx-person.txt 2016-07-12 13:41:10 +0000
@@ -58,7 +58,7 @@
58 sub_teams_collection_link: u'http://.../~salgado/sub_teams'58 sub_teams_collection_link: u'http://.../~salgado/sub_teams'
59 super_teams_collection_link: u'http://.../~salgado/super_teams'59 super_teams_collection_link: u'http://.../~salgado/super_teams'
60 team_owner_link: None60 team_owner_link: None
61 time_zone: None61 time_zone: u'UTC'
62 visibility: u'Public'62 visibility: u'Public'
63 web_link: u'http://launchpad.../~salgado'63 web_link: u'http://launchpad.../~salgado'
64 wiki_names_collection_link: u'http://.../~salgado/wiki_names'64 wiki_names_collection_link: u'http://.../~salgado/wiki_names'
@@ -124,7 +124,7 @@
124 super_teams_collection_link: u'http://.../~ubuntu-team/super_teams'124 super_teams_collection_link: u'http://.../~ubuntu-team/super_teams'
125 team_description: u'This Team is responsible for the Ubuntu Distribution'125 team_description: u'This Team is responsible for the Ubuntu Distribution'
126 team_owner_link: u'http://.../~mark'126 team_owner_link: u'http://.../~mark'
127 time_zone: None127 time_zone: u'UTC'
128 visibility: u'Public'128 visibility: u'Public'
129 web_link: u'http://launchpad.../~ubuntu-team'129 web_link: u'http://launchpad.../~ubuntu-team'
130 wiki_names_collection_link: u'http://.../~ubuntu-team/wiki_names'130 wiki_names_collection_link: u'http://.../~ubuntu-team/wiki_names'
131131
=== modified file 'lib/lp/registry/stories/webservice/xx-personlocation.txt'
--- lib/lp/registry/stories/webservice/xx-personlocation.txt 2012-02-16 20:37:55 +0000
+++ lib/lp/registry/stories/webservice/xx-personlocation.txt 2016-07-12 13:41:10 +0000
@@ -10,7 +10,7 @@
1010
11 >>> jdub = webservice.get("/~jdub").jsonBody()11 >>> jdub = webservice.get("/~jdub").jsonBody()
12 >>> print jdub['time_zone']12 >>> print jdub['time_zone']
13 None13 UTC
14 >>> print jdub['latitude']14 >>> print jdub['latitude']
15 None15 None
16 >>> print jdub['longitude']16 >>> print jdub['longitude']
@@ -20,7 +20,7 @@
20latitude/longitude read via the Web API will still be None.20latitude/longitude read via the Web API will still be None.
2121
22 >>> print webservice.get("/~jdub").jsonBody()['time_zone']22 >>> print webservice.get("/~jdub").jsonBody()['time_zone']
23 None23 UTC
24 >>> print webservice.named_post(24 >>> print webservice.named_post(
25 ... '/~jdub', 'setLocation', {},25 ... '/~jdub', 'setLocation', {},
26 ... latitude='-34.6', longitude='157.0', time_zone='Australia/Sydney')26 ... latitude='-34.6', longitude='157.0', time_zone='Australia/Sydney')
2727
=== modified file 'lib/lp/registry/templates/person-portlet-contact-details.pt'
--- lib/lp/registry/templates/person-portlet-contact-details.pt 2015-02-27 01:11:06 +0000
+++ lib/lp/registry/templates/person-portlet-contact-details.pt 2016-07-12 13:41:10 +0000
@@ -177,7 +177,7 @@
177 </dd>177 </dd>
178 </dl>178 </dl>
179179
180 <dl id="timezone" tal:condition="context/time_zone">180 <dl id="timezone">
181 <dt>Time zone:181 <dt>Time zone:
182 <a tal:replace="structure overview_menu/editlocation/fmt:icon" />182 <a tal:replace="structure overview_menu/editlocation/fmt:icon" />
183 </dt>183 </dt>
184184
=== modified file 'lib/lp/services/webapp/launchbag.py'
--- lib/lp/services/webapp/launchbag.py 2015-07-08 16:05:11 +0000
+++ lib/lp/services/webapp/launchbag.py 2016-07-12 13:41:10 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""4"""
@@ -151,7 +151,7 @@
151 @property151 @property
152 def time_zone(self):152 def time_zone(self):
153 if getattr(self._store, "time_zone", None) is None:153 if getattr(self._store, "time_zone", None) is None:
154 if self.user and self.user.time_zone:154 if self.user:
155 self._store.time_zone = pytz.timezone(self.user.time_zone)155 self._store.time_zone = pytz.timezone(self.user.time_zone)
156 else:156 else:
157 # fall back to UTC157 # fall back to UTC