Parent: [1105b2] (diff)

Child: [e59c8a] (diff)

Download this file

issue.py    139 lines (101 with data), 3.5 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
from time import sleep
from pylons import c
from pymongo.errors import OperationFailure
from ming.datastore import DataStore
from ming import Document, Field, schema
from datetime import datetime
from pyforge.model import Message
class Issue0(Document):
class __mongometa__:
name = 'issue'
type_s = 'Issue'
_id = Field(schema.ObjectId)
version = Field(0)
created_date = Field(datetime, if_missing=datetime.utcnow)
parent_id = Field(schema.ObjectId, if_missing=None)
summary = Field(str)
description = Field(str, if_missing='')
reported_by = Field(str)
assigned_to = Field(str, if_missing='')
milestone = Field(str, if_missing='')
status = Field(str, if_missing='open')
def url(self):
return c.app.script_name + '/' + self._id.url_encode() + '/'
def shorthand_id(self):
return '%s/%s' % (self.type_s, text=self.summary)
def index(self):
return self
def root_comments(self):
return Comment.m.find(dict(issue_id=self._id, reply_to=None))
def attachments(self):
return Attachment.m.find(dict(issue_id=self._id))
def reply(self):
while True:
try:
c = Comment.make(dict(issue_id=self._id))
c.m.insert()
return c
except OperationFailure:
sleep(0.1)
continue
Issue = Issue0
class Comment0(Document):
class __mongometa__:
name = 'issue_comment'
type_s = 'Issue Comment'
_id = Field(schema.ObjectId)
version = Field(0)
created_date = Field(datetime, if_missing=datetime.utcnow)
issue_id = Field(schema.ObjectId)
kind = Field(str, if_missing='comment')
reply_to_id = Field(schema.ObjectId, if_missing=None)
text = Field(str)
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
@property
def issue(self):
return Issue.m.get(_id=self.issue_id)
def url(self):
return self.issue.url() + '#comment-' + self._id
def shorthand_id(self):
return '%s-%s' % (self.issue.shorthand_id, self._id)
Comment = Comment0
class Attachment0(Document):
class __mongometa__:
name = 'issue_attachment'
type_s = 'Issue Attachment'
_id = Field(schema.ObjectId)
version = Field(0)
created_date = Field(datetime, if_missing=datetime.utcnow)
issue_id = Field(schema.ObjectId)
file_type = Field(str)
file_name = Field(str)
data = Field(str)
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
@property
def issue(self):
return Issue.m.get(_id=self.issue_id)
def url(self):
return self.issue.url() + '#attachment-' + self._id
def shorthand_id(self):
return '%s-%s' % (self.issue.shorthand_id, self._id)
Attachment = Attachment0