Parent: [718531] (diff)

Child: [457514] (diff)

Download this file

issue.py    172 lines (131 with data), 4.8 kB

  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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from time import sleep
from pylons import c
from pymongo.errors import OperationFailure
from ming import schema
from ming.orm.mapped_class import MappedClass
from ming.orm.property import FieldProperty, ForeignIdProperty, RelationProperty
from datetime import datetime
from pyforge.model import Artifact, VersionedArtifact, Snapshot, Message, project_orm_session
class Globals(MappedClass):
class __mongometa__:
name = 'globals'
session = project_orm_session
type_s = 'Globals'
_id = FieldProperty(schema.ObjectId)
project_id = FieldProperty(str)
last_issue_num = FieldProperty(int)
class IssueHistory(Snapshot):
class __mongometa__:
name = 'issue_history'
def original(self):
return Issue.query.get(_id=self.artifact_id)
def shorthand_id(self):
return '%s#%s' % (self.original().shorthand_id(), self.version)
def url(self):
return self.original().url() + '?version=%d' % self.version
def index(self):
result = Snapshot.index(self)
result.update(
title_s='Version %d of %s' % (
self.version,self.original().title),
type_s='Issue Snapshot',
text=self.data.summary)
return result
class Issue(VersionedArtifact):
class __mongometa__:
name = 'issue'
history_class = IssueHistory
type_s = 'Issue'
_id = FieldProperty(schema.ObjectId)
version = FieldProperty(0)
created_date = FieldProperty(datetime, if_missing=datetime.utcnow)
project_id = FieldProperty(str)
parent_id = FieldProperty(schema.ObjectId, if_missing=None)
issue_num = FieldProperty(int)
summary = FieldProperty(str)
description = FieldProperty(str, if_missing='')
reported_by = FieldProperty(str)
assigned_to = FieldProperty(str, if_missing='')
milestone = FieldProperty(str, if_missing='')
status = FieldProperty(str, if_missing='open')
comments = RelationProperty('Comment')
attachments = RelationProperty('Attachment')
def url(self):
return c.app.script_name + '/' + str(self.issue_num) + '/'
def shorthand_id(self):
return '%s/%s' % (self.type_s, self.issue_num)
def index(self):
result = VersionedArtifact.index(self)
result.update(
title_s='Issue %s' % self.issue_num,
version_i=self.version,
type_s=self.type_s,
text=self.summary)
return result
def root_comments(self):
return Comment.query.find(dict(issue_id=self._id, reply_to=None))
def reply(self):
while True:
try:
c = Comment(issue_id=self._id)
return c
except OperationFailure:
sleep(0.1)
continue
class Comment(Message):
class __mongometa__:
name = 'issue_comment'
type_s = 'Issue Comment'
_id = FieldProperty(schema.ObjectId)
version = FieldProperty(0)
created_date = FieldProperty(datetime, if_missing=datetime.utcnow)
project_id = FieldProperty(str)
issue_id = ForeignIdProperty(Issue)
kind = FieldProperty(str, if_missing='comment')
reply_to_id = FieldProperty(schema.ObjectId, if_missing=None)
text = FieldProperty(str)
issue = RelationProperty('Issue')
def index(self):
result = Message.index(self)
author = self.author()
result.update(
title_s='Comment on %s by %s' % (
self.issue.shorthand_id(),
author.display_name
),
type_s=self.type_s
)
return result
def url(self):
return self.issue.url() + '#comment-' + self._id
def shorthand_id(self):
return '%s-%s' % (self.issue.shorthand_id, self._id)
class Attachment(Artifact):
class __mongometa__:
name = 'issue_attachment'
type_s = 'Issue Attachment'
_id = FieldProperty(schema.ObjectId)
version = FieldProperty(0)
created_date = FieldProperty(datetime, if_missing=datetime.utcnow)
project_id = FieldProperty(str)
issue_id = ForeignIdProperty(Issue)
file_type = FieldProperty(str)
file_name = FieldProperty(str)
data = FieldProperty(str)
issue = RelationProperty('Issue')
def index(self):
result = Message.index(self)
author = self.author()
result.update(
title_s='Attachment on %s by %s' % (
self.issue.shorthand_id(),
author.display_name
),
type_s=self.type_s
)
return result
def url(self):
return self.issue.url() + '#attachment-' + self._id
def shorthand_id(self):
return '%s-%s' % (self.issue.shorthand_id, self._id)
MappedClass.compile_all()