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
|
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
__all__ = [
'SpecificationMessage',
'SpecificationMessageSet'
]
from email.Utils import make_msgid
from sqlobject import (
BoolCol,
ForeignKey,
)
from zope.interface import implements
from lp.blueprints.interfaces.specificationmessage import (
ISpecificationMessage,
ISpecificationMessageSet,
)
from lp.services.database.sqlbase import SQLBase
from lp.services.messages.model.message import (
Message,
MessageChunk,
)
class SpecificationMessage(SQLBase):
"""A table linking specifictions and messages."""
implements(ISpecificationMessage)
_table = 'SpecificationMessage'
specification = ForeignKey(
dbName='specification', foreignKey='Specification', notNull=True)
message = ForeignKey(dbName='message', foreignKey='Message', notNull=True)
visible = BoolCol(notNull=True, default=True)
class SpecificationMessageSet:
"""See ISpecificationMessageSet."""
implements(ISpecificationMessageSet)
def createMessage(self, subject, spec, owner, content=None):
"""See ISpecificationMessageSet."""
msg = Message(
owner=owner, rfc822msgid=make_msgid('blueprint'), subject=subject)
MessageChunk(message=msg, content=content, sequence=1)
return SpecificationMessage(specification=spec, message=msg)
def get(self, specmessageid):
"""See ISpecificationMessageSet."""
return SpecificationMessage.get(specmessageid)
def getBySpecificationAndMessage(self, spec, message):
"""See ISpecificationMessageSet."""
return SpecificationMessage.selectOneBy(
specification=spec, message=message)
|