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-2024 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 senaiteMessageFactory as _ |
25
|
|
|
from bika.lims.utils import get_link_for |
26
|
|
|
from senaite.app.listing import ListingView |
27
|
|
|
from senaite.core.catalog import SETUP_CATALOG |
28
|
|
|
from senaite.core.i18n import translate |
29
|
|
|
from senaite.core.permissions import AddSamplePoint |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class SamplePointsView(ListingView): |
33
|
|
|
|
34
|
|
|
def __init__(self, context, request): |
35
|
|
|
super(SamplePointsView, self).__init__(context, request) |
36
|
|
|
|
37
|
|
|
self.catalog = SETUP_CATALOG |
38
|
|
|
self.show_select_column = True |
39
|
|
|
|
40
|
|
|
self.contentFilter = { |
41
|
|
|
"portal_type": "SamplePoint", |
42
|
|
|
"sort_on": "sortable_title", |
43
|
|
|
"sort_order": "ascending", |
44
|
|
|
"path": { |
45
|
|
|
"query": api.get_path(context), |
46
|
|
|
"level": 0, |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
self.context_actions = { |
51
|
|
|
_(u"listing_samplepoints_action_add", default=u"Add"): { |
52
|
|
|
"url": "++add++SamplePoint", |
53
|
|
|
"permission": AddSamplePoint, |
54
|
|
|
"icon": "senaite_theme/icon/plus" |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
self.title = translate(_( |
59
|
|
|
u"listing_samplepoints_title", |
60
|
|
|
default=u"Sample Points") |
61
|
|
|
) |
62
|
|
|
self.icon = api.get_icon("SamplePoints", html_tag=False) |
63
|
|
|
|
64
|
|
|
self.columns = collections.OrderedDict(( |
65
|
|
|
("Title", { |
66
|
|
|
"title": _( |
67
|
|
|
u"listing_samplepoints_column_title", |
68
|
|
|
default=u"Sample Point" |
69
|
|
|
), |
70
|
|
|
"index": "sortable_title" |
71
|
|
|
}), |
72
|
|
|
("Description", { |
73
|
|
|
"title": _( |
74
|
|
|
u"listing_samplepoints_column_description", |
75
|
|
|
default=u"Description" |
76
|
|
|
), |
77
|
|
|
"toggle": True |
78
|
|
|
}), |
79
|
|
|
("SampleTypes", { |
80
|
|
|
"title": _( |
81
|
|
|
u"listing_samplepoints_column_sampletypes", |
82
|
|
|
default=u"Sample Types", |
83
|
|
|
), |
84
|
|
|
"index": "sampletype_title", |
85
|
|
|
"sortable": True, |
86
|
|
|
}), |
87
|
|
|
)) |
88
|
|
|
|
89
|
|
|
self.review_states = [ |
90
|
|
|
{ |
91
|
|
|
"id": "default", |
92
|
|
|
"title": _( |
93
|
|
|
u"listing_samplepoints_state_active", |
94
|
|
|
default=u"Active" |
95
|
|
|
), |
96
|
|
|
"contentFilter": {"is_active": True}, |
97
|
|
|
"columns": self.columns.keys(), |
98
|
|
|
}, { |
99
|
|
|
"id": "inactive", |
100
|
|
|
"title": _( |
101
|
|
|
u"listing_samplepoints_state_inactive", |
102
|
|
|
default=u"Inactive" |
103
|
|
|
), |
104
|
|
|
"contentFilter": {"is_active": False}, |
105
|
|
|
"columns": self.columns.keys(), |
106
|
|
|
}, { |
107
|
|
|
"id": "all", |
108
|
|
|
"title": _( |
109
|
|
|
u"listing_samplepoints_state_all", |
110
|
|
|
default=u"All" |
111
|
|
|
), |
112
|
|
|
"contentFilter": {}, |
113
|
|
|
"columns": self.columns.keys(), |
114
|
|
|
}, |
115
|
|
|
] |
116
|
|
|
|
117
|
|
View Code Duplication |
def folderitem(self, obj, item, index): |
|
|
|
|
118
|
|
|
obj = api.get_object(obj) |
119
|
|
|
item["replace"]["Title"] = get_link_for(obj) |
120
|
|
|
item["Description"] = obj.Description() |
121
|
|
|
|
122
|
|
|
sample_types = obj.getSampleTypes() |
123
|
|
|
titles = map(api.get_title, sample_types) |
124
|
|
|
links = map(get_link_for, sample_types) |
125
|
|
|
item["SampleTypes"] = ", ".join(titles) |
126
|
|
|
item["replace"]["SampleTypes"] = ", ".join(links) |
127
|
|
|
return item |
128
|
|
|
|