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 bikaMessageFactory as _ |
25
|
|
|
from bika.lims.utils import get_link |
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 AddSubGroup |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class SubGroupsView(ListingView): |
33
|
|
|
|
34
|
|
View Code Duplication |
def __init__(self, context, request): |
|
|
|
|
35
|
|
|
super(SubGroupsView, self).__init__(context, request) |
36
|
|
|
|
37
|
|
|
self.catalog = SETUP_CATALOG |
38
|
|
|
self.show_select_column = True |
39
|
|
|
|
40
|
|
|
self.contentFilter = { |
41
|
|
|
"portal_type": "SubGroup", |
42
|
|
|
"sort_on": "sortable_title", |
43
|
|
|
"sort_order": "ascending", |
44
|
|
|
"path": { |
45
|
|
|
"query": api.get_path(self.context), |
46
|
|
|
"depth": 1, |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
self.context_actions = { |
51
|
|
|
_("listing_subgroup_action_add", default="Add"): { |
52
|
|
|
"url": "++add++SubGroup", |
53
|
|
|
"permission": AddSubGroup, |
54
|
|
|
"icon": "senaite_theme/icon/plus" |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
self.title = translate(_( |
59
|
|
|
"listing_subgroups_title", |
60
|
|
|
default="Sub-Groups") |
61
|
|
|
) |
62
|
|
|
self.description = "" |
63
|
|
|
self.icon = api.get_icon("SubGroups", html_tag=False) |
64
|
|
|
|
65
|
|
|
self.columns = collections.OrderedDict(( |
66
|
|
|
("Title", { |
67
|
|
|
"title": _( |
68
|
|
|
"listing_subgroups_column_title", |
69
|
|
|
default="Title" |
70
|
|
|
), |
71
|
|
|
"index": "sortable_title"}), |
72
|
|
|
("Description", { |
73
|
|
|
"title": _( |
74
|
|
|
"listing_subgroups_column_description", |
75
|
|
|
default="Description" |
76
|
|
|
), |
77
|
|
|
"toggle": True, |
78
|
|
|
}), |
79
|
|
|
("SortKey", { |
80
|
|
|
"title": _( |
81
|
|
|
"listing_subgroups_column_sortkey", |
82
|
|
|
default="Sort Key" |
83
|
|
|
), |
84
|
|
|
"toggle": True, |
85
|
|
|
}), |
86
|
|
|
)) |
87
|
|
|
|
88
|
|
|
self.review_states = [ |
89
|
|
|
{ |
90
|
|
|
"id": "default", |
91
|
|
|
"title": _( |
92
|
|
|
"listing_subgroups_state_active", |
93
|
|
|
default="Active" |
94
|
|
|
), |
95
|
|
|
"contentFilter": {"is_active": True}, |
96
|
|
|
"transitions": [{"id": "deactivate"}, ], |
97
|
|
|
"columns": self.columns.keys(), |
98
|
|
|
}, { |
99
|
|
|
"id": "inactive", |
100
|
|
|
"title": _( |
101
|
|
|
"listing_subgroups_state_inactive", |
102
|
|
|
default="Inactive" |
103
|
|
|
), |
104
|
|
|
"contentFilter": {'is_active': False}, |
105
|
|
|
"transitions": [{"id": "activate"}, ], |
106
|
|
|
"columns": self.columns.keys(), |
107
|
|
|
}, { |
108
|
|
|
"id": "all", |
109
|
|
|
"title": _( |
110
|
|
|
"listing_subgroups_state_all", |
111
|
|
|
default="All" |
112
|
|
|
), |
113
|
|
|
"contentFilter": {}, |
114
|
|
|
"columns": self.columns.keys(), |
115
|
|
|
}, |
116
|
|
|
] |
117
|
|
|
|
118
|
|
|
def folderitem(self, obj, item, index): |
119
|
|
|
obj = api.get_object(obj) |
120
|
|
|
item["Description"] = obj.Description() |
121
|
|
|
item["replace"]["Title"] = get_link(item["url"], item["Title"]) |
122
|
|
|
item["SortKey"] = obj.getSortKey() |
123
|
|
|
return item |
124
|
|
|
|