~launchpad-pqm/launchpad/devel

14564.2.1 by Jeroen Vermeulen
Lint.
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
9072.2.1 by Andrea Corbellini
Add interface and model classes for specification messages.
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
__metaclass__ = type
5
__all__ = [
6
    'SpecificationMessage',
7
    'SpecificationMessageSet'
8
    ]
9
10
from email.Utils import make_msgid
11
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
12
from sqlobject import (
13
    BoolCol,
14
    ForeignKey,
15
    )
9072.2.1 by Andrea Corbellini
Add interface and model classes for specification messages.
16
from zope.interface import implements
17
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
18
from lp.blueprints.interfaces.specificationmessage import (
19
    ISpecificationMessage,
20
    ISpecificationMessageSet,
21
    )
14606.3.1 by William Grant
Merge canonical.database into lp.services.database.
22
from lp.services.database.sqlbase import SQLBase
12929.9.2 by j.c.sackett
Moved messages from canonical to lp.services
23
from lp.services.messages.model.message import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
24
    Message,
25
    MessageChunk,
26
    )
9072.2.1 by Andrea Corbellini
Add interface and model classes for specification messages.
27
28
29
class SpecificationMessage(SQLBase):
30
    """A table linking specifictions and messages."""
31
32
    implements(ISpecificationMessage)
33
34
    _table = 'SpecificationMessage'
35
36
    specification = ForeignKey(
37
        dbName='specification', foreignKey='Specification', notNull=True)
38
    message = ForeignKey(dbName='message', foreignKey='Message', notNull=True)
39
    visible = BoolCol(notNull=True, default=True)
40
41
42
class SpecificationMessageSet:
43
    """See ISpecificationMessageSet."""
44
45
    implements(ISpecificationMessageSet)
46
47
    def createMessage(self, subject, spec, owner, content=None):
48
        """See ISpecificationMessageSet."""
49
        msg = Message(
9072.2.4 by Andrea Corbellini
Fix model.
50
            owner=owner, rfc822msgid=make_msgid('blueprint'), subject=subject)
14564.2.1 by Jeroen Vermeulen
Lint.
51
        MessageChunk(message=msg, content=content, sequence=1)
52
        return SpecificationMessage(specification=spec, message=msg)
9072.2.1 by Andrea Corbellini
Add interface and model classes for specification messages.
53
54
    def get(self, specmessageid):
55
        """See ISpecificationMessageSet."""
56
        return SpecificationMessage.get(specmessageid)
57
58
    def getBySpecificationAndMessage(self, spec, message):
59
        """See ISpecificationMessageSet."""
60
        return SpecificationMessage.selectOneBy(
61
            specification=spec, message=message)