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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""A comment/message for a difference between two distribution series."""
__metaclass__ = type
__all__ = [
'DistroSeriesDifferenceComment',
]
from email.Utils import make_msgid
from storm.locals import (
Desc,
Int,
Reference,
Storm,
)
from zope.interface import (
classProvides,
implements,
)
from lp.registry.interfaces.distroseriesdifferencecomment import (
IDistroSeriesDifferenceComment,
IDistroSeriesDifferenceCommentSource,
)
from lp.registry.model.sourcepackagename import SourcePackageName
from lp.services.database.lpstorm import (
IMasterStore,
IStore,
)
from lp.services.messages.model.message import (
Message,
MessageChunk,
)
class DistroSeriesDifferenceComment(Storm):
"""See `IDistroSeriesDifferenceComment`."""
implements(IDistroSeriesDifferenceComment)
classProvides(IDistroSeriesDifferenceCommentSource)
__storm_table__ = 'DistroSeriesDifferenceMessage'
id = Int(primary=True)
distro_series_difference_id = Int(name='distro_series_difference',
allow_none=False)
distro_series_difference = Reference(
distro_series_difference_id, 'DistroSeriesDifference.id')
message_id = Int(name="message", allow_none=False)
message = Reference(message_id, 'Message.id')
@property
def comment_author(self):
"""See `IDistroSeriesDifferenceComment`."""
return self.message.owner
@property
def body_text(self):
"""See `IDistroSeriesDifferenceComment`."""
return self.message.text_contents
@property
def comment_date(self):
"""See `IDistroSeriesDifferenceComment`."""
return self.message.datecreated
@property
def source_package_name(self):
"""See `IDistroSeriesDifferenceCommentSource`."""
return self.distro_series_difference.source_package_name.name
@staticmethod
def new(distro_series_difference, owner, comment):
"""See `IDistroSeriesDifferenceCommentSource`."""
msgid = make_msgid('distroseriesdifference')
message = Message(
parent=None, owner=owner, rfc822msgid=msgid,
subject=distro_series_difference.title)
MessageChunk(message=message, content=comment, sequence=1)
store = IMasterStore(DistroSeriesDifferenceComment)
dsd_comment = DistroSeriesDifferenceComment()
dsd_comment.distro_series_difference = distro_series_difference
dsd_comment.message = message
comment = store.add(dsd_comment)
store.flush()
return comment
@staticmethod
def getForDifference(distro_series_difference, id):
"""See `IDistroSeriesDifferenceCommentSource`."""
store = IStore(DistroSeriesDifferenceComment)
DSDComment = DistroSeriesDifferenceComment
return store.find(
DSDComment,
DSDComment.distro_series_difference == distro_series_difference,
DSDComment.id == id).one()
@staticmethod
def getForDistroSeries(distroseries, since=None,
source_package_name=None):
"""See `IDistroSeriesDifferenceCommentSource`."""
# Avoid circular imports.
from lp.registry.model.distroseriesdifference import (
DistroSeriesDifference,
)
store = IStore(DistroSeriesDifferenceComment)
DSD = DistroSeriesDifference
DSDComment = DistroSeriesDifferenceComment
conditions = [
DSDComment.distro_series_difference_id == DSD.id,
DSD.derived_series_id == distroseries.id,
]
if source_package_name is not None:
conditions += [
SourcePackageName.id == DSD.source_package_name_id,
SourcePackageName.name == source_package_name,
]
if since is not None:
older_messages = store.find(
Message.id, Message.datecreated < since).order_by(
Desc(Message.datecreated))
preceding_message = older_messages.first()
if preceding_message is not None:
conditions.append(DSDComment.message_id > preceding_message)
return store.find(DSDComment, *conditions).order_by(
DSDComment.message_id)
|