|
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-2020 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
from Products.ATContentTypes.content import schemata |
|
22
|
|
|
from Products.Archetypes import atapi |
|
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.config import PROJECTNAME |
|
27
|
|
|
from bika.lims.interfaces import IContainers |
|
28
|
|
|
from bika.lims.permissions import AddContainer |
|
29
|
|
|
from bika.lims.utils import get_link |
|
30
|
|
|
from bika.lims.utils import get_link_for |
|
31
|
|
|
from plone.app.folder.folder import ATFolder, ATFolderSchema |
|
32
|
|
|
from zope.interface.declarations import implements |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
class ContainersView(BikaListingView): |
|
36
|
|
|
|
|
37
|
|
|
def __init__(self, context, request): |
|
38
|
|
|
super(ContainersView, self).__init__(context, request) |
|
39
|
|
|
self.catalog = 'bika_setup_catalog' |
|
40
|
|
|
self.contentFilter = {'portal_type': 'Container', |
|
41
|
|
|
'sort_on': 'sortable_title'} |
|
42
|
|
|
self.context_actions = {_('Add'): |
|
43
|
|
|
{'url': 'createObject?type_name=Container', |
|
44
|
|
|
'permission': AddContainer, |
|
45
|
|
|
'icon': '++resource++bika.lims.images/add.png'}} |
|
46
|
|
|
self.title = self.context.translate(_("Containers")) |
|
47
|
|
|
self.icon = self.portal_url + "/++resource++bika.lims.images/container_big.png" |
|
48
|
|
|
self.description = "" |
|
49
|
|
|
|
|
50
|
|
|
self.show_select_row = False |
|
51
|
|
|
self.show_select_column = True |
|
52
|
|
|
self.pagesize = 25 |
|
53
|
|
|
|
|
54
|
|
|
self.columns = { |
|
55
|
|
|
'Title': {'title': _('Container'), |
|
56
|
|
|
'index':'sortable_title'}, |
|
57
|
|
|
'Description': {'title': _('Description'), |
|
58
|
|
|
'index': 'description', |
|
59
|
|
|
'toggle': True}, |
|
60
|
|
|
'ContainerType': {'title': _('Container Type'), |
|
61
|
|
|
'toggle': True}, |
|
62
|
|
|
'Capacity': {'title': _('Capacity'), |
|
63
|
|
|
'toggle': True}, |
|
64
|
|
|
'Pre-preserved': {'title': _('Pre-preserved'), |
|
65
|
|
|
'toggle': True}, |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
self.review_states = [ # leave these titles and ids alone |
|
69
|
|
|
{'id':'default', |
|
70
|
|
|
'contentFilter': {'is_active': True}, |
|
71
|
|
|
'title': _('Active'), |
|
72
|
|
|
'transitions': [{'id':'deactivate'}, ], |
|
73
|
|
|
'columns': ['Title', |
|
74
|
|
|
'Description', |
|
75
|
|
|
'ContainerType', |
|
76
|
|
|
'Capacity', |
|
77
|
|
|
'Pre-preserved']}, |
|
78
|
|
|
{'id':'inactive', |
|
79
|
|
|
'title': _('Inactive'), |
|
80
|
|
|
'contentFilter': {'is_active': False}, |
|
81
|
|
|
'transitions': [{'id':'activate'}, ], |
|
82
|
|
|
'columns': ['Title', |
|
83
|
|
|
'Description', |
|
84
|
|
|
'ContainerType', |
|
85
|
|
|
'Capacity', |
|
86
|
|
|
'Pre-preserved']}, |
|
87
|
|
|
{'id':'all', |
|
88
|
|
|
'title': _('All'), |
|
89
|
|
|
'contentFilter':{}, |
|
90
|
|
|
'transitions': [], |
|
91
|
|
|
'columns': ['Title', |
|
92
|
|
|
'Description', |
|
93
|
|
|
'ContainerType', |
|
94
|
|
|
'Capacity', |
|
95
|
|
|
'Pre-preserved']}, |
|
96
|
|
|
] |
|
97
|
|
|
|
|
98
|
|
|
def before_render(self): |
|
99
|
|
|
"""Before template render hook |
|
100
|
|
|
""" |
|
101
|
|
|
# Don't allow any context actions |
|
102
|
|
|
self.request.set("disable_border", 1) |
|
103
|
|
|
|
|
104
|
|
|
def folderitem(self, obj, item, index): |
|
105
|
|
|
obj = api.get_object(obj) |
|
106
|
|
|
c_type = obj.getContainerType() |
|
107
|
|
|
capacity = obj.getCapacity() |
|
108
|
|
|
item.update({ |
|
109
|
|
|
"Description": obj.Description(), |
|
110
|
|
|
"ContainerType": c_type and api.get_title(c_type) or "", |
|
111
|
|
|
"Capacity": capacity and str(capacity) or "", |
|
112
|
|
|
"Pre-preserved": "", |
|
113
|
|
|
}) |
|
114
|
|
|
|
|
115
|
|
|
if obj.getPrePreserved(): |
|
116
|
|
|
item["after"]["Pre-preserved"] = get_link_for(obj.getPreservation()) |
|
117
|
|
|
|
|
118
|
|
|
item["replace"]["Title"] = get_link(item["url"], item["Title"]) |
|
119
|
|
|
return item |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
schema = ATFolderSchema.copy() |
|
123
|
|
|
|
|
124
|
|
|
class Containers(ATFolder): |
|
125
|
|
|
implements(IContainers) |
|
126
|
|
|
displayContentsTab = False |
|
127
|
|
|
schema = schema |
|
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
schemata.finalizeATCTSchema(schema, folderish = True, moveDiscussion = False) |
|
131
|
|
|
atapi.registerType(Containers, PROJECTNAME) |
|
132
|
|
|
|