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
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index 5917c6e..e5b66aa 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -766,7 +766,10 @@ class Person(
766 @cachedproperty766 @cachedproperty
767 def location(self):767 def location(self):
768 """See `IObjectWithLocation`."""768 """See `IObjectWithLocation`."""
769 return PersonLocation.selectOneBy(person=self)769 location = IStore(PersonLocation).find(
770 PersonLocation,
771 PersonLocation.person == self).one()
772 return location
770773
771 @property774 @property
772 def time_zone(self):775 def time_zone(self):
@@ -785,7 +788,7 @@ class Person(
785 "Cannot set a latitude without longitude (and vice-versa).")788 "Cannot set a latitude without longitude (and vice-versa).")
786789
787 if self.location is not None:790 if self.location is not None:
788 self.location.time_zone = time_zone791 self.location.time_zone = six.ensure_text(time_zone)
789 self.location.latitude = latitude792 self.location.latitude = latitude
790 self.location.longitude = longitude793 self.location.longitude = longitude
791 self.location.last_modified_by = user794 self.location.last_modified_by = user
@@ -4097,7 +4100,7 @@ class SSHKey(SQLBase):
4097 try:4100 try:
4098 ssh_keytype = getNS(base64.b64decode(self.keytext))[0].decode(4101 ssh_keytype = getNS(base64.b64decode(self.keytext))[0].decode(
4099 'ascii')4102 'ascii')
4100 except Exception as e:4103 except Exception:
4101 # We didn't always validate keys, so there might be some that4104 # We didn't always validate keys, so there might be some that
4102 # can't be loaded this way.4105 # can't be loaded this way.
4103 if self.keytype == SSHKeyType.RSA:4106 if self.keytype == SSHKeyType.RSA:
diff --git a/lib/lp/registry/model/personlocation.py b/lib/lp/registry/model/personlocation.py
index 391d430..50b14c4 100644
--- a/lib/lp/registry/model/personlocation.py
+++ b/lib/lp/registry/model/personlocation.py
@@ -14,36 +14,59 @@ __all__ = [
14 'PersonLocation',14 'PersonLocation',
15 ]15 ]
1616
17from sqlobject import (17import pytz
18 BoolCol,18import six
19 FloatCol,19from storm.locals import (
20 ForeignKey,20 Bool,
21 StringCol,21 DateTime,
22 Float,
23 Int,
24 Reference,
25 Unicode,
22 )26 )
23from zope.interface import implementer27from zope.interface import implementer
2428
25from lp.registry.interfaces.location import IPersonLocation29from lp.registry.interfaces.location import IPersonLocation
26from lp.registry.interfaces.person import validate_public_person30from lp.registry.interfaces.person import validate_public_person
27from lp.services.database.constants import UTC_NOW31from lp.services.database.constants import UTC_NOW
28from lp.services.database.datetimecol import UtcDateTimeCol32from lp.services.database.stormbase import StormBase
29from lp.services.database.sqlbase import SQLBase
3033
3134
32@implementer(IPersonLocation)35@implementer(IPersonLocation)
33class PersonLocation(SQLBase):36class PersonLocation(StormBase):
34 """A person's location."""37 """A person's location."""
38 __storm_table__ = 'PersonLocation'
3539
36 _defaultOrder = ['id']40 __storm_order__ = 'id'
3741 id = Int(primary=True)
38 date_created = UtcDateTimeCol(notNull=True, default=UTC_NOW)42
39 person = ForeignKey(43 date_created = DateTime(
40 dbName='person', foreignKey='Person',44 tzinfo=pytz.UTC, name='date_created', allow_none=False,
41 storm_validator=validate_public_person, notNull=True, unique=True)45 default=UTC_NOW)
42 latitude = FloatCol(notNull=False)46
43 longitude = FloatCol(notNull=False)47 person_id = Int(name='person', allow_none=False)
44 time_zone = StringCol(notNull=True)48 person = Reference(person_id, 'Person.id')
45 last_modified_by = ForeignKey(49
46 dbName='last_modified_by', foreignKey='Person',50 latitude = Float(allow_none=True)
47 storm_validator=validate_public_person, notNull=True)51 longitude = Float(allow_none=True)
48 date_last_modified = UtcDateTimeCol(notNull=True, default=UTC_NOW)52 time_zone = Unicode(allow_none=False)
49 visible = BoolCol(notNull=True, default=True)53
54 last_modified_by_id = Int(
55 name='last_modified_by',
56 validator=validate_public_person,
57 allow_none=False)
58 last_modified_by = Reference(last_modified_by_id, 'Person.id')
59
60 date_last_modified = DateTime(
61 tzinfo=pytz.UTC, name='date_last_modified', allow_none=False,
62 default=UTC_NOW)
63
64 visible = Bool(name='visible', allow_none=False, default=True)
65
66 def __init__(self, person, time_zone, latitude,
67 longitude, last_modified_by):
68 self.person = person
69 self.time_zone = six.ensure_text(time_zone)
70 self.latitude = latitude
71 self.longitude = longitude
72 self.last_modified_by = last_modified_by
diff --git a/lib/lp/registry/stories/webservice/xx-personlocation.txt b/lib/lp/registry/stories/webservice/xx-personlocation.txt
index e475673..1a6f739 100644
--- a/lib/lp/registry/stories/webservice/xx-personlocation.txt
+++ b/lib/lp/registry/stories/webservice/xx-personlocation.txt
@@ -1,5 +1,3 @@
1= Person location =
2
3The location of a person is readable through the Web Service API, and can1The location of a person is readable through the Web Service API, and can
4be set that way too, but it has been deprecated as we no longer have that2be set that way too, but it has been deprecated as we no longer have that
5information in our database, so the latitude/longitude will always be None.3information in our database, so the latitude/longitude will always be None.
@@ -23,7 +21,8 @@ latitude/longitude read via the Web API will still be None.
23 UTC21 UTC
24 >>> print webservice.named_post(22 >>> print webservice.named_post(
25 ... '/~jdub', 'setLocation', {},23 ... '/~jdub', 'setLocation', {},
26 ... latitude='-34.6', longitude='157.0', time_zone='Australia/Sydney')24 ... latitude='-34.6', longitude='157.0',
25 ... time_zone=u'Australia/Sydney')
27 HTTP/1.1 200 Ok26 HTTP/1.1 200 Ok
28 ...27 ...
29 >>> webservice.get("/~jdub").jsonBody()['time_zone']28 >>> webservice.get("/~jdub").jsonBody()['time_zone']

Subscribers

People subscribed via source and target branches

to status/vote changes: