-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.py
251 lines (210 loc) · 7.34 KB
/
project.py
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
from Acquisition import aq_inner
from datetime import date
from zope.component import getUtility
from zope.schema.interfaces import IVocabularyFactory
from zope.security import checkPermission
from z3c.form.interfaces import IFormLayer
from five import grok
from plone.z3cform import z2
from plone.memoize.instance import memoize
from plone.dexterity.content import Container
from Products.CMFCore.utils import getToolByName
from plone.uuid.interfaces import IUUID
from plone.app.uuid.utils import uuidToObject
from .interfaces import IProject, IStoriesListing, IBacklogView
from .configure import DOCUMENTS_ID
from .utils import get_user_details
from .utils import get_text
from .utils import AttrDict
from .iteration import IterationViewMixin
from .story import ProjectStoryQuickForm
from . import messageFactory as _
class Project(Container):
grok.implements(IProject)
def get_notes(self):
notes = self.notes
if notes:
return self.notes.output
class View(grok.View):
grok.context(IProject)
grok.require('zope2.View')
@property
@memoize
def tools(self):
return AttrDict({
'portal_catalog': getToolByName(self.context, 'portal_catalog')
})
@property
def user_can_manage_project(self):
return checkPermission(
'simplemanagement.ManageProject', self.context
)
def user_can_add_story(self):
return checkPermission('simplemanagement.AddStory', self.context)
def add_story_form(self):
z2.switch_on(self, request_layer=IFormLayer)
addform = ProjectStoryQuickForm(
aq_inner(self.context),
self.request
)
addform.update()
return addform.render()
def iterations(self):
iterations = {
'past': [],
'current': [],
'future': []
}
pc = self.tools['portal_catalog']
raw_iterations = pc.searchResults({
'path': '/'.join(self.context.getPhysicalPath()),
'portal_type': 'Iteration',
'sort_on': 'start',
'sort_order': 'ascending'
})
now = date.today()
have_iterations = False
for iteration_brain in raw_iterations:
iteration = iteration_brain.getObject()
if iteration.end < now:
iterations['past'].append(iteration)
have_iterations = True
elif iteration.end >= now and iteration.start <= now:
iterations['current'].append(iteration)
have_iterations = True
else:
iterations['future'].append(iteration)
have_iterations = True
if not have_iterations:
return None
return iterations
class AllIterations(View):
grok.context(IProject)
grok.name('alliterations')
grok.require('zope2.View')
class OverView(View):
grok.context(IProject)
grok.name('overview')
grok.require('zope2.View')
MAX_ELEMENTS = 5
@memoize
def status_vocabulary(self):
name = "collective.simplemanagement.status"
return getUtility(IVocabularyFactory, name)(self.context)
def get_milestone_status(self, value):
voc = self.status_vocabulary()
return voc.getTermByToken(value).title
@memoize
def roles_vocabulary(self):
name = "collective.simplemanagement.roles"
return getUtility(IVocabularyFactory, name)(self.context)
def get_role(self, value):
voc = self.roles_vocabulary()
return voc.getTermByToken(value).title
@memoize
def env_vocabulary(self):
name = "collective.simplemanagement.envtypes"
return getUtility(IVocabularyFactory, name)(self.context)
def get_env_type(self, value):
voc = self.env_vocabulary()
return voc.getTermByToken(value).title
def documents(self):
last_documents = []
documents_folder = None
if DOCUMENTS_ID in self.context:
# documents_folder = self.context[DOCUMENTS_ID]
# XXX: tryiing to resolve document folder raises a
# unauthorized error when a user doesn't have view
# permissions
document_folder_path = list(self.context.getPhysicalPath())
document_folder_path.append(DOCUMENTS_ID)
pc = self.tools['portal_catalog']
folder_path = '/'.join(document_folder_path)
last_stuff = pc.searchResults({
'path': folder_path,
'sort_on': 'modified',
'sort_order': 'descending'
})
for item in last_stuff[:self.MAX_ELEMENTS + 1]:
if item.getPath() != folder_path:
last_documents.append(item)
return {
'last': last_documents,
'folder': documents_folder
}
def operatives(self):
operatives = self.context.operatives
if not operatives:
operatives = []
for i in operatives:
yield {
'role': self.get_role(i.role),
'user': get_user_details(self.context, i.user_id)
}
class Planning(grok.View):
grok.context(IProject)
grok.require('cmf.ModifyPortalContent')
grok.name('planning')
@memoize
def portal_catalog(self):
return getToolByName(self.context, 'portal_catalog')
@memoize
def get_iterations(self, mode='left'):
iterations = [
{
'title': _(u"Backlog"),
'uuid': IUUID(self.context),
'selected': False
}
]
if mode == 'left':
iterations[0]['selected'] = True
pc = self.portal_catalog()
raw_iterations = pc.searchResults({
'path': '/'.join(self.context.getPhysicalPath()),
'portal_type': 'Iteration',
'sort_on': 'start',
'sort_order': 'ascending'
})
now = date.today()
selected = None
for iteration_brain in raw_iterations:
data = {
'title': iteration_brain.Title,
'uuid': iteration_brain.UID,
'selected': False
}
# on the right pane, either select the current iteration,
# or the first future one
if mode == 'right' and selected is None:
iteration = iteration_brain.getObject()
if iteration.end >= now and iteration.start <= now:
data['selected'] = True
selected = iteration
elif iteration.start > now and selected is None:
data['selected'] = True
selected = iteration
iterations.append(data)
return iterations
class Stories(grok.View):
grok.context(IProject)
grok.require('cmf.ModifyPortalContent')
grok.name('stories')
@memoize
def uuid(self):
return self.request['iteration']
@memoize
def widget_id(self):
return self.request['widget_id']
@memoize
def iteration(self):
return uuidToObject(self.uuid())
@memoize
def stories(self):
adpt = IStoriesListing(self.iteration())
return adpt.stories()
class Backlog(grok.View, IterationViewMixin):
grok.implements(IBacklogView)
grok.context(IProject)
grok.require('cmf.ModifyPortalContent')
grok.name('backlog')