1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE |
4
|
|
|
# |
5
|
|
|
# Copyright 2018 by it's authors. |
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
7
|
|
|
|
8
|
|
|
from bika.lims import bikaMessageFactory as _ |
9
|
|
|
from bika.lims.browser.bika_listing import BikaListingView |
10
|
|
|
from bika.lims.config import PROJECTNAME |
11
|
|
|
from bika.lims.interfaces import IReflexRuleFolder |
12
|
|
|
from bika.lims.permissions import ManageBika |
13
|
|
|
from plone.app.folder.folder import ATFolder |
14
|
|
|
from plone.app.folder.folder import ATFolderSchema |
15
|
|
|
from Products.Archetypes import atapi |
16
|
|
|
from Products.ATContentTypes.content import schemata |
17
|
|
|
from Products.CMFCore import permissions |
18
|
|
|
from Products.CMFCore.utils import getToolByName |
19
|
|
|
from zope.interface.declarations import implements |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class ReflexRuleFolderView(BikaListingView): |
23
|
|
|
|
24
|
|
View Code Duplication |
def __init__(self, context, request): |
|
|
|
|
25
|
|
|
super(ReflexRuleFolderView, self).__init__(context, request) |
26
|
|
|
self.catalog = "portal_catalog" |
27
|
|
|
self.contentFilter = { |
28
|
|
|
'portal_type': 'ReflexRule', |
29
|
|
|
'path': { |
30
|
|
|
"query": "/".join(self.context.getPhysicalPath()), |
31
|
|
|
"level": 0 |
32
|
|
|
}, |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
self.show_select_row = False |
36
|
|
|
self.show_select_column = True |
37
|
|
|
self.icon = self.portal_url +\ |
38
|
|
|
"/++resource++bika.lims.images/reflexrule_big.png" |
39
|
|
|
self.title = self.context.translate(_("Reflex rules folder")) |
40
|
|
|
self.description = "" |
41
|
|
|
self.columns = { |
42
|
|
|
'Title': { |
43
|
|
|
'title': _('Reflex Rule'), |
44
|
|
|
'index': 'sortable_title' |
45
|
|
|
}, |
46
|
|
|
'Method': { |
47
|
|
|
'title': _('Method'), |
48
|
|
|
'index': 'sortable_title' |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
self.review_states = [ |
52
|
|
|
{'id': 'default', |
53
|
|
|
'title': _('Active'), |
54
|
|
|
'contentFilter': {'inactive_state': 'active'}, |
55
|
|
|
'columns': ['Title', 'Method', ]}, |
56
|
|
|
{'id': 'inactive', |
57
|
|
|
'title': _('Dormant'), |
58
|
|
|
'contentFilter': {'inactive_state': 'inactive'}, |
59
|
|
|
'columns': ['Title', 'Method', ]}, |
60
|
|
|
{'id': 'all', |
61
|
|
|
'title': _('All'), |
62
|
|
|
'contentFilter': {}, |
63
|
|
|
'columns': ['Title', 'Method', ]}, |
64
|
|
|
] |
65
|
|
|
|
66
|
|
|
def __call__(self): |
67
|
|
|
mtool = getToolByName(self.context, 'portal_membership') |
68
|
|
|
if mtool.checkPermission( |
69
|
|
|
permissions.ModifyPortalContent, |
70
|
|
|
self.context): |
71
|
|
|
self.context_actions[_('Add Reflex rule')] = { |
|
|
|
|
72
|
|
|
'url': 'createObject?type_name=ReflexRule', |
73
|
|
|
'icon': '++resource++bika.lims.images/add.png' |
74
|
|
|
} |
75
|
|
|
if not mtool.checkPermission(ManageBika, self.context): |
76
|
|
|
self.show_select_column = False |
77
|
|
|
self.review_states = [ |
78
|
|
|
{'id': 'default', |
79
|
|
|
'title': _('All'), |
80
|
|
|
'contentFilter': {}, |
81
|
|
|
'columns': ['Title']} |
82
|
|
|
] |
83
|
|
|
return super(ReflexRuleFolderView, self).__call__() |
84
|
|
|
|
85
|
|
|
def before_render(self): |
86
|
|
|
"""Before template render hook |
87
|
|
|
""" |
88
|
|
|
# Don't allow any context actions |
89
|
|
|
self.request.set("disable_border", 1) |
90
|
|
|
|
91
|
|
|
# TODO use folderitem in develop! |
92
|
|
|
def folderitems(self): |
93
|
|
|
items = BikaListingView.folderitems(self) |
94
|
|
|
for x in range(len(items)): |
95
|
|
|
if 'obj' not in items[x]: |
96
|
|
|
continue |
97
|
|
|
obj = items[x]['obj'] |
98
|
|
|
items[x]['replace']['Title'] = "<a href='%s'>%s</a>" % \ |
99
|
|
|
(items[x]['url'], items[x]['Title']) |
100
|
|
|
method = items[x]['obj'].getMethod() |
101
|
|
|
items[x]['Method'] = method.title if method else '' |
102
|
|
|
items[x]['replace']['Method'] = "<a href='%s'>%s</a>" % \ |
103
|
|
|
(method.absolute_url(), items[x]['Method']) if method else '' |
104
|
|
|
return items |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
schema = ATFolderSchema.copy() |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
class ReflexRuleFolder(ATFolder): |
111
|
|
|
implements(IReflexRuleFolder) |
112
|
|
|
displayContentsTab = False |
113
|
|
|
schema = schema |
|
|
|
|
114
|
|
|
|
115
|
|
|
|
116
|
|
|
schemata.finalizeATCTSchema( |
117
|
|
|
schema, |
118
|
|
|
folderish=True, |
119
|
|
|
moveDiscussion=False) |
120
|
|
|
|
121
|
|
|
atapi.registerType(ReflexRuleFolder, PROJECTNAME) |
122
|
|
|
|