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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=E0211,E0213
"""Interfaces for things which have Specifications."""
__metaclass__ = type
__all__ = [
'IHasSpecifications',
'ISpecificationTarget',
'ISpecificationGoal',
]
from lazr.lifecycle.snapshot import doNotSnapshot
from lazr.restful.declarations import (
export_as_webservice_entry,
export_read_operation,
exported,
operation_for_version,
operation_parameters,
operation_returns_entry,
)
from lazr.restful.fields import (
CollectionField,
Reference,
)
from zope.interface import (
Attribute,
Interface,
)
from zope.schema import TextLine
from lp import _
class IHasSpecifications(Interface):
"""An object that has specifications attached to it.
For example, people, products and distributions have specifications
associated with them, and you can use this interface to query those.
"""
all_specifications = exported(doNotSnapshot(
CollectionField(
title=_("All specifications"),
value_type=Reference(schema=Interface), # ISpecification, really.
readonly=True,
description=_(
'A list of all specifications, regardless of status or '
'approval or completion, for this object.'))),
as_of="devel")
has_any_specifications = Attribute(
'A true or false indicator of whether or not this object has any '
'specifications associated with it, regardless of their status.')
valid_specifications = exported(doNotSnapshot(
CollectionField(
title=_("Valid specifications"),
value_type=Reference(schema=Interface), # ISpecification, really.
readonly=True,
description=_(
'All specifications that are not obsolete. When called from '
'an ISpecificationGoal it will also exclude the ones that '
'have not been accepted for that goal'))),
as_of="devel")
latest_specifications = Attribute(
"The latest 5 specifications registered for this context.")
latest_completed_specifications = Attribute(
"The 5 specifications most recently completed for this context.")
def specifications(quantity=None, sort=None, filter=None,
prejoin_people=True):
"""Specifications for this target.
The sort is a dbschema which indicates the preferred sort order. The
filter is an indicator of the kinds of specs to be returned, and
appropriate filters depend on the kind of object this method is on.
If there is a quantity, then limit the result to that number.
In the case where the filter is [] or None, the content class will
decide what its own appropriate "default" filter is. In some cases,
it will show all specs, in others, all approved specs, and in
others, all incomplete specs.
If prejoin_people=False is specified, then the assignee, drafter
and approver will not be prejoined. This can be used in
situations in which these are not rendered.
"""
class ISpecificationTarget(IHasSpecifications):
"""An interface for the objects which actually have unique
specifications directly attached to them.
"""
export_as_webservice_entry(as_of="devel")
@operation_parameters(
name=TextLine(title=_('The name of the specification')))
@operation_returns_entry(Interface) # really ISpecification
@export_read_operation()
@operation_for_version('devel')
def getSpecification(name):
"""Returns the specification with the given name, for this target,
or None.
"""
class ISpecificationGoal(ISpecificationTarget):
"""An interface for those things which can have specifications proposed
as goals for them.
"""
|