Merge ~ilasc/launchpad:stormify-person-location into launchpad:master

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 3d4ca241fedb4506d7fc2f0ca97ff621e49819fd
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/launchpad:stormify-person-location
Merge into: launchpad:master
Diff against target: 140 lines (+53/-28)
3 files modified
lib/lp/registry/model/person.py (+6/-3)
lib/lp/registry/model/personlocation.py (+45/-22)
lib/lp/registry/stories/webservice/xx-personlocation.txt (+2/-3)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+390093@code.launchpad.net

Commit message

Stormify PersonLocation

Description of the change

Move PersonLocation from SQLObject to Storm.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
2index 5917c6e..e5b66aa 100644
3--- a/lib/lp/registry/model/person.py
4+++ b/lib/lp/registry/model/person.py
5@@ -766,7 +766,10 @@ class Person(
6 @cachedproperty
7 def location(self):
8 """See `IObjectWithLocation`."""
9- return PersonLocation.selectOneBy(person=self)
10+ location = IStore(PersonLocation).find(
11+ PersonLocation,
12+ PersonLocation.person == self).one()
13+ return location
14
15 @property
16 def time_zone(self):
17@@ -785,7 +788,7 @@ class Person(
18 "Cannot set a latitude without longitude (and vice-versa).")
19
20 if self.location is not None:
21- self.location.time_zone = time_zone
22+ self.location.time_zone = six.ensure_text(time_zone)
23 self.location.latitude = latitude
24 self.location.longitude = longitude
25 self.location.last_modified_by = user
26@@ -4097,7 +4100,7 @@ class SSHKey(SQLBase):
27 try:
28 ssh_keytype = getNS(base64.b64decode(self.keytext))[0].decode(
29 'ascii')
30- except Exception as e:
31+ except Exception:
32 # We didn't always validate keys, so there might be some that
33 # can't be loaded this way.
34 if self.keytype == SSHKeyType.RSA:
35diff --git a/lib/lp/registry/model/personlocation.py b/lib/lp/registry/model/personlocation.py
36index 391d430..50b14c4 100644
37--- a/lib/lp/registry/model/personlocation.py
38+++ b/lib/lp/registry/model/personlocation.py
39@@ -14,36 +14,59 @@ __all__ = [
40 'PersonLocation',
41 ]
42
43-from sqlobject import (
44- BoolCol,
45- FloatCol,
46- ForeignKey,
47- StringCol,
48+import pytz
49+import six
50+from storm.locals import (
51+ Bool,
52+ DateTime,
53+ Float,
54+ Int,
55+ Reference,
56+ Unicode,
57 )
58 from zope.interface import implementer
59
60 from lp.registry.interfaces.location import IPersonLocation
61 from lp.registry.interfaces.person import validate_public_person
62 from lp.services.database.constants import UTC_NOW
63-from lp.services.database.datetimecol import UtcDateTimeCol
64-from lp.services.database.sqlbase import SQLBase
65+from lp.services.database.stormbase import StormBase
66
67
68 @implementer(IPersonLocation)
69-class PersonLocation(SQLBase):
70+class PersonLocation(StormBase):
71 """A person's location."""
72+ __storm_table__ = 'PersonLocation'
73
74- _defaultOrder = ['id']
75-
76- date_created = UtcDateTimeCol(notNull=True, default=UTC_NOW)
77- person = ForeignKey(
78- dbName='person', foreignKey='Person',
79- storm_validator=validate_public_person, notNull=True, unique=True)
80- latitude = FloatCol(notNull=False)
81- longitude = FloatCol(notNull=False)
82- time_zone = StringCol(notNull=True)
83- last_modified_by = ForeignKey(
84- dbName='last_modified_by', foreignKey='Person',
85- storm_validator=validate_public_person, notNull=True)
86- date_last_modified = UtcDateTimeCol(notNull=True, default=UTC_NOW)
87- visible = BoolCol(notNull=True, default=True)
88+ __storm_order__ = 'id'
89+ id = Int(primary=True)
90+
91+ date_created = DateTime(
92+ tzinfo=pytz.UTC, name='date_created', allow_none=False,
93+ default=UTC_NOW)
94+
95+ person_id = Int(name='person', allow_none=False)
96+ person = Reference(person_id, 'Person.id')
97+
98+ latitude = Float(allow_none=True)
99+ longitude = Float(allow_none=True)
100+ time_zone = Unicode(allow_none=False)
101+
102+ last_modified_by_id = Int(
103+ name='last_modified_by',
104+ validator=validate_public_person,
105+ allow_none=False)
106+ last_modified_by = Reference(last_modified_by_id, 'Person.id')
107+
108+ date_last_modified = DateTime(
109+ tzinfo=pytz.UTC, name='date_last_modified', allow_none=False,
110+ default=UTC_NOW)
111+
112+ visible = Bool(name='visible', allow_none=False, default=True)
113+
114+ def __init__(self, person, time_zone, latitude,
115+ longitude, last_modified_by):
116+ self.person = person
117+ self.time_zone = six.ensure_text(time_zone)
118+ self.latitude = latitude
119+ self.longitude = longitude
120+ self.last_modified_by = last_modified_by
121diff --git a/lib/lp/registry/stories/webservice/xx-personlocation.txt b/lib/lp/registry/stories/webservice/xx-personlocation.txt
122index e475673..1a6f739 100644
123--- a/lib/lp/registry/stories/webservice/xx-personlocation.txt
124+++ b/lib/lp/registry/stories/webservice/xx-personlocation.txt
125@@ -1,5 +1,3 @@
126-= Person location =
127-
128 The location of a person is readable through the Web Service API, and can
129 be set that way too, but it has been deprecated as we no longer have that
130 information in our database, so the latitude/longitude will always be None.
131@@ -23,7 +21,8 @@ latitude/longitude read via the Web API will still be None.
132 UTC
133 >>> print webservice.named_post(
134 ... '/~jdub', 'setLocation', {},
135- ... latitude='-34.6', longitude='157.0', time_zone='Australia/Sydney')
136+ ... latitude='-34.6', longitude='157.0',
137+ ... time_zone=u'Australia/Sydney')
138 HTTP/1.1 200 Ok
139 ...
140 >>> webservice.get("/~jdub").jsonBody()['time_zone']

Subscribers

People subscribed via source and target branches

to status/vote changes: