1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=E0211,E0213
"""Location interface.
An object can have a location, which includes geographic coordinates and a
time zone.
"""
__metaclass__ = type
__all__ = [
'IHasLocation',
'ILocationRecord',
'IObjectWithLocation',
'IPersonLocation',
'ISetLocation',
]
from lazr.lifecycle.snapshot import doNotSnapshot
from lazr.restful.declarations import (
call_with,
export_write_operation,
exported,
operation_for_version,
operation_parameters,
REQUEST_USER,
)
from lazr.restful.interface import copy_field
from zope.interface import (
Attribute,
Interface,
)
from zope.schema import (
Bool,
Choice,
Datetime,
Float,
Object,
)
from lp import _
class IHasLocation(Interface):
"""An interface supported by objects with a defined location."""
latitude = exported(doNotSnapshot(
Float(title=_("The latitude of this object."),
required=False, readonly=True)))
longitude = exported(doNotSnapshot(
Float(title=_("The longitude of this object."),
required=False, readonly=True)))
time_zone = exported(doNotSnapshot(
Choice(title=_('The time zone of this object.'),
required=False, readonly=True,
vocabulary='TimezoneName')))
class IObjectWithLocation(Interface):
"""An interface supported by objects with a defined location."""
location = Attribute("An ILocation for this object.")
class ILocationRecord(IHasLocation):
"""A location record, which may be attached to a particular object.
The location record contains additional information such as the date the
location data was recorded, and by whom.
"""
last_modified_by = Attribute(
"The person who last provided this location information.")
date_last_modified = Datetime(
title=_("The date this information was last updated."))
visible = Bool(
title=_("Is this location record visible?"),
required=False, readonly=False, default=True)
class ISetLocation(Interface):
"""An interface for setting the location and time zone of an object."""
@call_with(user=REQUEST_USER)
@operation_parameters(
latitude=copy_field(IHasLocation['latitude'], required=True),
longitude=copy_field(IHasLocation['longitude'], required=True),
time_zone=copy_field(IHasLocation['time_zone'], required=True))
@export_write_operation()
@operation_for_version('beta')
def setLocation(latitude, longitude, time_zone, user):
"""Specify the location and time zone of a person."""
class IPersonLocation(ILocationRecord):
"""A location record for a person."""
# Can't use IPerson as the schema here because of circular dependencies.
person = Object(title=_("Person"), schema=Interface)
|