1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE. |
4
|
|
|
# |
5
|
|
|
# SENAITE.CORE is free software: you can redistribute it and/or modify it under |
6
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
7
|
|
|
# Foundation, version 2. |
8
|
|
|
# |
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
12
|
|
|
# details. |
13
|
|
|
# |
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17
|
|
|
# |
18
|
|
|
# Copyright 2018-2021 by it's authors. |
19
|
|
|
# Some rights reserved, see README and LICENSE. |
20
|
|
|
|
21
|
|
|
import collections |
22
|
|
|
|
23
|
|
|
from bika.lims import api |
24
|
|
|
from bika.lims import bikaMessageFactory as _ |
25
|
|
|
from bika.lims.browser.bika_listing import BikaListingView |
26
|
|
|
from bika.lims.permissions import AddMethod |
27
|
|
|
from bika.lims.utils import check_permission |
28
|
|
|
from bika.lims.utils import get_link |
29
|
|
|
from bika.lims.utils import get_link_for |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class MethodFolderContentsView(BikaListingView): |
33
|
|
|
"""Listing view for all Methods |
34
|
|
|
""" |
35
|
|
|
|
36
|
|
|
def __init__(self, context, request): |
37
|
|
|
super(MethodFolderContentsView, self).__init__(context, request) |
38
|
|
|
|
39
|
|
|
self.catalog = "bika_setup_catalog" |
40
|
|
|
|
41
|
|
|
self.contentFilter = { |
42
|
|
|
"portal_type": "Method", |
43
|
|
|
"sort_on": "sortable_title", |
44
|
|
|
"sort_order": "ascending" |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
self.context_actions = {} |
48
|
|
|
self.title = self.context.translate(_("Methods")) |
49
|
|
|
self.description = "" |
50
|
|
|
self.icon = "{}/{}".format( |
51
|
|
|
self.portal_url, "++resource++bika.lims.images/method_big.png") |
52
|
|
|
|
53
|
|
|
self.show_select_column = True |
54
|
|
|
self.pagesize = 25 |
55
|
|
|
|
56
|
|
|
self.columns = collections.OrderedDict(( |
57
|
|
|
("Title", { |
58
|
|
|
"title": _("Method"), |
59
|
|
|
"index": "sortable_title", |
60
|
|
|
}), |
61
|
|
|
("Description", { |
62
|
|
|
"title": _("Description"), |
63
|
|
|
"index": "description", |
64
|
|
|
"toggle": True, |
65
|
|
|
}), |
66
|
|
|
("Instruments", { |
67
|
|
|
"title": _("Instruments"), |
68
|
|
|
"toggle": True, |
69
|
|
|
}), |
70
|
|
|
("Calculations", { |
71
|
|
|
"title": _("Calculations"), |
72
|
|
|
"toggle": True, |
73
|
|
|
}), |
74
|
|
|
)) |
75
|
|
|
|
76
|
|
|
self.review_states = [ |
77
|
|
|
{ |
78
|
|
|
"id": "default", |
79
|
|
|
"title": _("Active"), |
80
|
|
|
"contentFilter": {"is_active": True}, |
81
|
|
|
"transitions": [{"id": "deactivate"}, ], |
82
|
|
|
"columns": self.columns.keys(), |
83
|
|
|
}, { |
84
|
|
|
"id": "inactive", |
85
|
|
|
"title": _("Inactive"), |
86
|
|
|
"contentFilter": {'is_active': False}, |
87
|
|
|
"transitions": [{"id": "activate"}, ], |
88
|
|
|
"columns": self.columns.keys(), |
89
|
|
|
}, { |
90
|
|
|
"id": "all", |
91
|
|
|
"title": _("All"), |
92
|
|
|
"contentFilter": {}, |
93
|
|
|
"columns": self.columns.keys(), |
94
|
|
|
}, |
95
|
|
|
] |
96
|
|
|
|
97
|
|
|
def update(self): |
98
|
|
|
"""Before template render hook |
99
|
|
|
""" |
100
|
|
|
super(MethodFolderContentsView, self).update() |
101
|
|
|
|
102
|
|
|
# Render the Add button if the user has the AddMethod permission |
103
|
|
|
if check_permission(AddMethod, self.context): |
104
|
|
|
self.context_actions[_("Add")] = { |
|
|
|
|
105
|
|
|
"url": "createObject?type_name=Method", |
106
|
|
|
"icon": "++resource++bika.lims.images/add.png" |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
def folderitem(self, obj, item, index): |
110
|
|
|
"""Applies new properties to the item (Client) that is currently being |
111
|
|
|
rendered as a row in the list |
112
|
|
|
|
113
|
|
|
:param obj: client to be rendered as a row in the list |
114
|
|
|
:param item: dict representation of the client, suitable for the list |
115
|
|
|
:param index: current position of the item within the list |
116
|
|
|
:type obj: ATContentType/DexterityContentType |
117
|
|
|
:type item: dict |
118
|
|
|
:type index: int |
119
|
|
|
:return: the dict representation of the item |
120
|
|
|
:rtype: dict |
121
|
|
|
""" |
122
|
|
|
|
123
|
|
|
obj = api.get_object(obj) |
124
|
|
|
url = obj.absolute_url() |
125
|
|
|
title = obj.Title() |
126
|
|
|
|
127
|
|
|
item["replace"]["Title"] = get_link(url, value=title) |
128
|
|
|
|
129
|
|
|
instruments = obj.getInstruments() |
130
|
|
|
if instruments: |
131
|
|
|
titles = map(api.get_title, instruments) |
132
|
|
|
links = map(get_link_for, instruments) |
133
|
|
|
item["Insatruments"] = ",".join(titles) |
134
|
|
|
item["replace"]["Instruments"] = ", ".join(links) |
135
|
|
|
else: |
136
|
|
|
item["Instruments"] = "" |
137
|
|
|
|
138
|
|
|
calculations = obj.getCalculations() |
139
|
|
|
if calculations: |
140
|
|
|
titles = map(api.get_title, calculations) |
141
|
|
|
links = map(get_link_for, calculations) |
142
|
|
|
item["Calculations"] = ",".join(titles) |
143
|
|
|
item["replace"]["Calculations"] = ",".join(links) |
144
|
|
|
else: |
145
|
|
|
item["Calculations"] = "" |
146
|
|
|
|
147
|
|
|
return item |
148
|
|
|
|