|
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 IInstrumentLocations |
|
28
|
|
|
from bika.lims.permissions import AddInstrumentLocation |
|
29
|
|
|
from bika.lims.utils import get_link |
|
30
|
|
|
from plone.app.folder.folder import ATFolder |
|
31
|
|
|
from plone.app.folder.folder import ATFolderSchema |
|
32
|
|
|
from zope.interface import implements |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
class InstrumentLocationsView(BikaListingView): |
|
|
|
|
|
|
37
|
|
|
"""Displays all available instrument locations in a table |
|
38
|
|
|
""" |
|
39
|
|
|
|
|
40
|
|
|
def __init__(self, context, request): |
|
41
|
|
|
super(InstrumentLocationsView, self).__init__(context, request) |
|
42
|
|
|
|
|
43
|
|
|
self.contentFilter = {'portal_type': 'InstrumentLocation', |
|
44
|
|
|
'sort_on': 'sortable_title'} |
|
45
|
|
|
|
|
46
|
|
|
self.context_actions = {_('Add'): |
|
47
|
|
|
{'url': 'createObject?type_name=InstrumentLocation', |
|
48
|
|
|
'permission': AddInstrumentLocation, |
|
49
|
|
|
'icon': '++resource++bika.lims.images/add.png'}} |
|
50
|
|
|
|
|
51
|
|
|
self.title = self.context.translate(_("Instrument Locations")) |
|
52
|
|
|
self.icon = "++resource++bika.lims.images/instrumenttype_big.png" |
|
53
|
|
|
self.description = "" |
|
54
|
|
|
|
|
55
|
|
|
self.show_select_row = False |
|
56
|
|
|
self.show_select_column = True |
|
57
|
|
|
self.pagesize = 25 |
|
58
|
|
|
|
|
59
|
|
|
self.columns = { |
|
60
|
|
|
'Title': {'title': _('Title'), |
|
61
|
|
|
'index': 'sortable_title'}, |
|
62
|
|
|
'Description': {'title': _('Description'), |
|
63
|
|
|
'index': 'description', |
|
64
|
|
|
'toggle': True}, |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
self.review_states = [ |
|
68
|
|
|
{'id': 'default', |
|
69
|
|
|
'title': _('Active'), |
|
70
|
|
|
'contentFilter': {'is_active': True}, |
|
71
|
|
|
'transitions': [{'id': 'deactivate'}, ], |
|
72
|
|
|
'columns': ['Title', 'Description']}, |
|
73
|
|
|
{'id': 'inactive', |
|
74
|
|
|
'title': _('Inactive'), |
|
75
|
|
|
'contentFilter': {'is_active': False}, |
|
76
|
|
|
'transitions': [{'id': 'activate'}, ], |
|
77
|
|
|
'columns': ['Title', 'Description']}, |
|
78
|
|
|
{'id': 'all', |
|
79
|
|
|
'title': _('All'), |
|
80
|
|
|
'contentFilter': {}, |
|
81
|
|
|
'columns': ['Title', 'Description']}, |
|
82
|
|
|
] |
|
83
|
|
|
|
|
84
|
|
|
def before_render(self): |
|
85
|
|
|
"""Before template render hook |
|
86
|
|
|
""" |
|
87
|
|
|
# Don't allow any context actions |
|
88
|
|
|
self.request.set("disable_border", 1) |
|
89
|
|
|
|
|
90
|
|
|
def folderitem(self, obj, item, index): |
|
91
|
|
|
obj = api.get_object(obj) |
|
92
|
|
|
item["Description"] = obj.Description() |
|
93
|
|
|
item["replace"]["title"] = get_link(item["url"], item["Title"]) |
|
94
|
|
|
return item |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
schema = ATFolderSchema.copy() |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
class InstrumentLocations(ATFolder): |
|
101
|
|
|
implements(IInstrumentLocations) |
|
102
|
|
|
displayContentsTab = False |
|
103
|
|
|
schema = schema |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
schemata.finalizeATCTSchema(schema, folderish=True, moveDiscussion=False) |
|
107
|
|
|
atapi.registerType(InstrumentLocations, PROJECTNAME) |
|
108
|
|
|
|