|
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_for |
|
26
|
|
|
from senaite.core.i18n import translate |
|
27
|
|
|
from senaite.app.listing import ListingView |
|
28
|
|
|
from senaite.core.catalog import SETUP_CATALOG |
|
29
|
|
|
from senaite.core.permissions import AddManufacturer |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class ManufacturersView(ListingView): |
|
33
|
|
|
"""Displays all available manufacturers |
|
34
|
|
|
""" |
|
35
|
|
|
|
|
36
|
|
|
def __init__(self, context, request): |
|
37
|
|
|
super(ManufacturersView, self).__init__(context, request) |
|
38
|
|
|
|
|
39
|
|
|
self.catalog = SETUP_CATALOG |
|
40
|
|
|
|
|
41
|
|
|
self.contentFilter = { |
|
42
|
|
|
"portal_type": "Manufacturer", |
|
43
|
|
|
"sort_on": "sortable_title", |
|
44
|
|
|
"path": { |
|
45
|
|
|
"query": api.get_path(self.context), |
|
46
|
|
|
"depth": 1, |
|
47
|
|
|
}, |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
self.context_actions = { |
|
51
|
|
|
_(u"listing_manufacturers_action_add", default=u"Add"): { |
|
52
|
|
|
"url": "++add++Manufacturer", |
|
53
|
|
|
"permission": AddManufacturer, |
|
54
|
|
|
"icon": "senaite_theme/icon/plus" |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
self.title = translate(_( |
|
59
|
|
|
u"listing_manufacturers_title", |
|
60
|
|
|
default=u"Manufacturers") |
|
61
|
|
|
) |
|
62
|
|
|
self.description = "" |
|
63
|
|
|
self.icon = "{}/{}".format( |
|
64
|
|
|
self.portal_url, |
|
65
|
|
|
"/++resource++bika.lims.images/manufacturer_big.png" |
|
66
|
|
|
) |
|
67
|
|
|
|
|
68
|
|
|
self.show_select_row = False |
|
69
|
|
|
self.show_select_column = True |
|
70
|
|
|
self.show_all = False |
|
71
|
|
|
|
|
72
|
|
|
self.columns = collections.OrderedDict(( |
|
73
|
|
|
("Title", { |
|
74
|
|
|
"title": _( |
|
75
|
|
|
u"listing_manufacturers_column_title", |
|
76
|
|
|
default=u"Title", |
|
77
|
|
|
), |
|
78
|
|
|
"index": "sortable_title"}), |
|
79
|
|
|
("Description", { |
|
80
|
|
|
"title": _( |
|
81
|
|
|
u"listing_manufacturers_column_description", |
|
82
|
|
|
default=u"Description" |
|
83
|
|
|
), |
|
84
|
|
|
"toggle": True, |
|
85
|
|
|
}), |
|
86
|
|
|
)) |
|
87
|
|
|
|
|
88
|
|
|
self.review_states = [ |
|
89
|
|
|
{ |
|
90
|
|
|
"id": "default", |
|
91
|
|
|
"title": _( |
|
92
|
|
|
u"listing_manufacturers_state_active", |
|
93
|
|
|
default=u"Active", |
|
94
|
|
|
), |
|
95
|
|
|
"contentFilter": {"is_active": True}, |
|
96
|
|
|
"columns": self.columns.keys(), |
|
97
|
|
|
}, { |
|
98
|
|
|
"id": "inactive", |
|
99
|
|
|
"title": _( |
|
100
|
|
|
u"listing_manufacturers_state_inactive", |
|
101
|
|
|
default=u"Inactive", |
|
102
|
|
|
), |
|
103
|
|
|
"contentFilter": {'is_active': False}, |
|
104
|
|
|
"columns": self.columns.keys(), |
|
105
|
|
|
}, { |
|
106
|
|
|
"id": "all", |
|
107
|
|
|
"title": _( |
|
108
|
|
|
u"listing_manufacturers_state_all", |
|
109
|
|
|
default=u"All", |
|
110
|
|
|
), |
|
111
|
|
|
"contentFilter": {}, |
|
112
|
|
|
"columns": self.columns.keys(), |
|
113
|
|
|
}, |
|
114
|
|
|
] |
|
115
|
|
|
|
|
116
|
|
|
def folderitem(self, obj, item, index): |
|
117
|
|
|
"""Service triggered each time an item is iterated in folderitems. |
|
118
|
|
|
The use of this service prevents the extra-loops in child objects. |
|
119
|
|
|
:obj: the instance of the class to be foldered |
|
120
|
|
|
:item: dict containing the properties of the object to be used by |
|
121
|
|
|
the template |
|
122
|
|
|
:index: current index of the item |
|
123
|
|
|
""" |
|
124
|
|
|
obj = api.get_object(obj) |
|
125
|
|
|
|
|
126
|
|
|
item["replace"]["Title"] = get_link_for(obj) |
|
127
|
|
|
item["Description"] = api.get_description(obj) |
|
128
|
|
|
|
|
129
|
|
|
return item |
|
130
|
|
|
|
|
131
|
|
|
def folderitems(self): |
|
132
|
|
|
items = super(ManufacturersView, self).folderitems() |
|
133
|
|
|
return items |
|
134
|
|
|
|