forked from OdooBulgaria/OLiMS
/
log.py
152 lines (138 loc) · 6.02 KB
/
log.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
from dependencies.dependency import newSecurityManager
from dependencies.dependency import aq_inner, aq_parent
from lims import bikaMessageFactory as _
from lims.utils import t
from lims.browser.bika_listing import BikaListingView
from lims.utils import to_utf8
from dependencies.dependency import DateTime
from operator import itemgetter
from dependencies.dependency import IViewView
from dependencies.dependency import ContentHistoryView, ContentHistoryViewlet
from dependencies.dependency import REFERENCE_CATALOG
from dependencies.dependency import getToolByName
from dependencies.dependency import WorkflowException
from dependencies.dependency import safe_unicode
from dependencies.dependency import ViewPageTemplateFile
from dependencies.dependency import implements
from dependencies.dependency import TestRequest
import json
class LogView(BikaListingView):
""" Show log entries, workflow history and revision history details
for an object
"""
implements(IViewView)
template = ViewPageTemplateFile("templates/log.pt")
def __init__(self, context, request):
BikaListingView.__init__(self, context, request)
self.show_sort_column = False
self.show_select_row = False
self.show_select_column = False
self.show_workflow_action_buttons = False
self.pagesize = 999999
self.icon = self.portal_url + "/++resource++bika.lims.images/%s_big.png" % \
context.portal_type.lower()
self.title = to_utf8(self.context.Title()) + " " + t(_("Log"))
self.description = ""
self.columns = {
'Version': {'title': _('Version'), 'sortable': False},
'Date': {'title': _('Date'), 'sortable': False},
'User': {'title': _('User'), 'sortable': False},
'Action': {'title': _('Action'), 'sortable': False},
'Description': {'title': _('Description'), 'sortable': False},
}
self.review_states = [
{'id': 'default',
'title': 'All',
'contentFilter': {},
'columns': ['Version',
'Date',
'User',
'Action',
'Description']},
]
def folderitems(self):
rc = getToolByName(self.context, REFERENCE_CATALOG)
wf = getToolByName(self.context, 'portal_workflow')
pr = getToolByName(self.context, 'portal_repository')
isVersionable = pr.isVersionable(aq_inner(self.context))
try:
review_history = wf.getInfoFor(self.context, 'review_history')
review_history = list(review_history)
review_history.reverse()
except WorkflowException:
review_history = []
items = []
for entry in review_history:
# this folderitems doesn't subclass from the bika_listing.py
# so we create items from scratch
review_state = entry.get('review_state')
state_title = wf.getTitleForStateOnType(review_state, self.context.portal_type)
item = {
'obj': self.context,
'id': self.context.id,
'uid': self.context.UID(),
'title': self.context.title_or_id(),
'type_class': '',
'url': self.context.absolute_url(),
'relative_url': self.context.absolute_url(),
'view_url': self.context.absolute_url(),
'path': "/".join(self.context.getPhysicalPath()),
'replace': {},
'before': {},
'after': {},
'choices': {},
'class': {},
'state_class': '',
'allow_edit': [],
'required': [],
'Version': isVersionable and self.context.get('version_id', '') or '0',
'Date': self.ulocalized_time(entry.get('time')),
'sortable_date': entry.get('time'),
'User': entry.get('actor'),
'Action': entry.get('action') and entry.get('action') or 'Create',
'Description': "review state: %s" % state_title,
}
items.append(item)
if isVersionable:
request = TestRequest()
chv = ContentHistoryViewlet(self.context, request, None, None)
chv.navigation_root_url = chv.site_url = 'http://localhost:8080/bikas'
version_history = chv.revisionHistory()
else:
version_history = []
for entry in version_history:
# this folderitems doesn't subclass from the bika_listing.py
# so we create items from scratch
# disregard the first entry of version history, as it is
# represented by the first entry in review_history
if not entry.get('version_id'):
continue
item = {
'obj': self.context,
'id': self.context.id,
'uid': self.context.UID(),
'title': self.context.title_or_id(),
'type_class': '',
'url': self.context.absolute_url(),
'relative_url': self.context.absolute_url(),
'view_url': self.context.absolute_url(),
'path': "/".join(self.context.getPhysicalPath()),
'replace': {},
'before': {},
'after': {},
'choices': {},
'class': {},
'state_class': '',
'allow_edit': [],
'required': [],
'Version': entry.get('version_id'),
'Date': self.ulocalized_time(DateTime(entry.get('time'))),
'sortable_date': entry.get('time'),
'User': entry.get('actor').get('fullname'),
'Action': entry.get('action') and entry.get('action') or 'Create',
'Description': entry.get('comments'),
}
items.append(item)
items = sorted(items, key=itemgetter('sortable_date'))
items.reverse()
return items