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
1=== modified file 'lib/lp/app/browser/tales.py'
2--- lib/lp/app/browser/tales.py 2016-05-12 14:08:38 +0000
3+++ lib/lp/app/browser/tales.py 2016-07-12 13:41:10 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Implementation of the lp: htmlform: fmt: namespaces in TALES."""
10@@ -1199,9 +1199,7 @@
11
12 def local_time(self):
13 """Return the local time for this person."""
14- time_zone = 'UTC'
15- if self._context.time_zone is not None:
16- time_zone = self._context.time_zone
17+ time_zone = self._context.time_zone
18 return datetime.now(pytz.timezone(time_zone)).strftime('%T %Z')
19
20 def url(self, view_name=None, rootsite='mainsite'):
21
22=== modified file 'lib/lp/app/doc/tales.txt'
23--- lib/lp/app/doc/tales.txt 2016-02-06 01:41:00 +0000
24+++ lib/lp/app/doc/tales.txt 2016-07-12 13:41:10 +0000
25@@ -487,8 +487,11 @@
26 >>> test_tales("person/fmt:local-time", person=sample_person)
27 '... AWST'
28
29- >>> print mark.time_zone
30+ >>> from zope.security.proxy import removeSecurityProxy
31+ >>> print removeSecurityProxy(mark).location
32 None
33+ >>> mark.time_zone
34+ u'UTC'
35
36 >>> test_tales("person/fmt:local-time", person=mark)
37 '... UTC'
38
39=== modified file 'lib/lp/app/widgets/date.py'
40--- lib/lp/app/widgets/date.py 2013-04-10 08:05:17 +0000
41+++ lib/lp/app/widgets/date.py 2016-07-12 13:41:10 +0000
42@@ -1,4 +1,4 @@
43-# Copyright 2009 Canonical Ltd. This software is licensed under the
44+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
45 # GNU Affero General Public License version 3 (see the file LICENSE).
46
47 """These widgets use the a YUI2 calendar widget to allow for
48@@ -178,9 +178,8 @@
49
50 The widget "system time zone" is generally UTC. It is the logged in
51 users time zone, with a fallback to UTC if there is no logged in
52- user, or if the logged in user has not given us a time zone.
53- Although this isn't used directly, it influences the outcome of
54- widget.time_zone.
55+ user. Although this isn't used directly, it influences the outcome
56+ of widget.time_zone.
57
58 >>> print widget.system_time_zone
59 UTC
60
61=== modified file 'lib/lp/registry/browser/person.py'
62--- lib/lp/registry/browser/person.py 2016-06-13 03:15:44 +0000
63+++ lib/lp/registry/browser/person.py 2016-07-12 13:41:10 +0000
64@@ -1,4 +1,4 @@
65-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
66+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
67 # GNU Affero General Public License version 3 (see the file LICENSE).
68
69 """Person-related view classes."""
70@@ -210,10 +210,8 @@
71 from lp.services.gpg.interfaces import (
72 GPG_DATABASE_READONLY_FEATURE_FLAG,
73 GPG_HIDE_PERSON_KEY_LISTING,
74- GPG_WRITE_TO_GPGSERVICE_FEATURE_FLAG,
75 GPGKeyNotFoundError,
76 GPGReadOnly,
77- IGPGClient,
78 IGPGHandler,
79 )
80 from lp.services.identity.interfaces.account import (
81@@ -2561,8 +2559,8 @@
82 self.key_already_imported = True
83 return
84
85- # Launchpad talks to the keyserver directly to check if the key has been
86- # uploaded to the key server.
87+ # Launchpad talks to the keyserver directly to check if the key has
88+ # been uploaded to the key server.
89 try:
90 key = gpghandler.retrieveKey(self.fingerprint)
91 except GPGKeyNotFoundError:
92@@ -4006,10 +4004,7 @@
93
94 @property
95 def initial_values(self):
96- if self.context.time_zone is None:
97- return {}
98- else:
99- return dict(time_zone=self.context.time_zone)
100+ return {'time_zone': self.context.time_zone}
101
102 @property
103 def next_url(self):
104
105=== modified file 'lib/lp/registry/model/person.py'
106--- lib/lp/registry/model/person.py 2016-06-02 04:39:33 +0000
107+++ lib/lp/registry/model/person.py 2016-07-12 13:41:10 +0000
108@@ -1,4 +1,4 @@
109-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
110+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
111 # GNU Affero General Public License version 3 (see the file LICENSE).
112
113 """Implementation classes for a Person."""
114@@ -773,7 +773,7 @@
115 def time_zone(self):
116 """See `IHasLocation`."""
117 if self.location is None:
118- return None
119+ return u'UTC'
120 # Wrap the location with a security proxy to make sure the user has
121 # enough rights to see it.
122 return ProxyFactory(self.location).time_zone
123
124=== modified file 'lib/lp/registry/stories/location/personlocation-edit.txt'
125--- lib/lp/registry/stories/location/personlocation-edit.txt 2016-01-26 15:47:37 +0000
126+++ lib/lp/registry/stories/location/personlocation-edit.txt 2016-07-12 13:41:10 +0000
127@@ -20,7 +20,8 @@
128 A user can set their own time zone:
129
130 >>> self_browser = setupBrowser(auth="Basic zzz@foo.com:test")
131- >>> self_browser.open('http://launchpad.dev/~zzz/+editlocation')
132+ >>> self_browser.open('http://launchpad.dev/~zzz')
133+ >>> self_browser.getLink('Set location and time zone').click()
134 >>> self_browser.getControl(name='field.time_zone').value = [
135 ... 'Europe/Madrid']
136 >>> self_browser.getControl('Update').click()
137@@ -33,6 +34,7 @@
138 And when they come back to change it later, they'll see it there as the
139 selected value.
140
141- >>> self_browser.open('http://launchpad.dev/~zzz/+editlocation')
142+ >>> self_browser.open('http://launchpad.dev/~zzz')
143+ >>> self_browser.getLink('Set location and time zone').click()
144 >>> print self_browser.getControl(name='field.time_zone').value
145 ['Europe/Madrid']
146
147=== modified file 'lib/lp/registry/stories/webservice/xx-person.txt'
148--- lib/lp/registry/stories/webservice/xx-person.txt 2016-04-12 10:50:30 +0000
149+++ lib/lp/registry/stories/webservice/xx-person.txt 2016-07-12 13:41:10 +0000
150@@ -58,7 +58,7 @@
151 sub_teams_collection_link: u'http://.../~salgado/sub_teams'
152 super_teams_collection_link: u'http://.../~salgado/super_teams'
153 team_owner_link: None
154- time_zone: None
155+ time_zone: u'UTC'
156 visibility: u'Public'
157 web_link: u'http://launchpad.../~salgado'
158 wiki_names_collection_link: u'http://.../~salgado/wiki_names'
159@@ -124,7 +124,7 @@
160 super_teams_collection_link: u'http://.../~ubuntu-team/super_teams'
161 team_description: u'This Team is responsible for the Ubuntu Distribution'
162 team_owner_link: u'http://.../~mark'
163- time_zone: None
164+ time_zone: u'UTC'
165 visibility: u'Public'
166 web_link: u'http://launchpad.../~ubuntu-team'
167 wiki_names_collection_link: u'http://.../~ubuntu-team/wiki_names'
168
169=== modified file 'lib/lp/registry/stories/webservice/xx-personlocation.txt'
170--- lib/lp/registry/stories/webservice/xx-personlocation.txt 2012-02-16 20:37:55 +0000
171+++ lib/lp/registry/stories/webservice/xx-personlocation.txt 2016-07-12 13:41:10 +0000
172@@ -10,7 +10,7 @@
173
174 >>> jdub = webservice.get("/~jdub").jsonBody()
175 >>> print jdub['time_zone']
176- None
177+ UTC
178 >>> print jdub['latitude']
179 None
180 >>> print jdub['longitude']
181@@ -20,7 +20,7 @@
182 latitude/longitude read via the Web API will still be None.
183
184 >>> print webservice.get("/~jdub").jsonBody()['time_zone']
185- None
186+ UTC
187 >>> print webservice.named_post(
188 ... '/~jdub', 'setLocation', {},
189 ... latitude='-34.6', longitude='157.0', time_zone='Australia/Sydney')
190
191=== modified file 'lib/lp/registry/templates/person-portlet-contact-details.pt'
192--- lib/lp/registry/templates/person-portlet-contact-details.pt 2015-02-27 01:11:06 +0000
193+++ lib/lp/registry/templates/person-portlet-contact-details.pt 2016-07-12 13:41:10 +0000
194@@ -177,7 +177,7 @@
195 </dd>
196 </dl>
197
198- <dl id="timezone" tal:condition="context/time_zone">
199+ <dl id="timezone">
200 <dt>Time zone:
201 <a tal:replace="structure overview_menu/editlocation/fmt:icon" />
202 </dt>
203
204=== modified file 'lib/lp/services/webapp/launchbag.py'
205--- lib/lp/services/webapp/launchbag.py 2015-07-08 16:05:11 +0000
206+++ lib/lp/services/webapp/launchbag.py 2016-07-12 13:41:10 +0000
207@@ -1,4 +1,4 @@
208-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
209+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
210 # GNU Affero General Public License version 3 (see the file LICENSE).
211
212 """
213@@ -151,7 +151,7 @@
214 @property
215 def time_zone(self):
216 if getattr(self._store, "time_zone", None) is None:
217- if self.user and self.user.time_zone:
218+ if self.user:
219 self._store.time_zone = pytz.timezone(self.user.time_zone)
220 else:
221 # fall back to UTC