Passed
Push — 2.x ( 44675d...5e1af5 )
by Jordi
09:20
created

InstrumentLocationsView.folderitem()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 5

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 5
dl 14
loc 14
rs 10
c 0
b 0
f 0
cc 1
nop 4
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.app.listing import ListingView
27
from senaite.core.catalog import SETUP_CATALOG
28
from senaite.core.permissions import AddInstrumentLocation
29
30
31 View Code Duplication
class InstrumentLocationsView(ListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
32
    """Displays all available instrument locations in a table
33
    """
34
35
    def __init__(self, context, request):
36
        super(InstrumentLocationsView, self).__init__(context, request)
37
38
        self.catalog = SETUP_CATALOG
39
40
        self.contentFilter = {
41
            "portal_type": "InstrumentLocation",
42
            "sort_on": "sortable_title",
43
        }
44
45
        self.context_actions = {
46
            _("Add"): {
47
                "url": "++add++InstrumentLocation",
48
                "permission": AddInstrumentLocation,
49
                "icon": "++resource++bika.lims.images/add.png",
50
            }}
51
52
        t = self.context.translate
53
        self.title = t(_("Instrument Locations"))
54
        self.description = t(_(
55
            "The place where the instrument is located in the laboratory"))
56
57
        self.show_select_column = True
58
        self.pagesize = 25
59
60
        self.columns = collections.OrderedDict((
61
            ("Title", {
62
                "title": _("Location"),
63
                "index": "sortable_title"}),
64
            ("Description", {
65
                "title": _("Description"),
66
                "index": "Description",
67
                "toggle": True,
68
            }),
69
        ))
70
71
        self.review_states = [
72
            {
73
                "id": "default",
74
                "title": _("Active"),
75
                "contentFilter": {"is_active": True},
76
                "columns": self.columns.keys(),
77
            }, {
78
                "id": "inactive",
79
                "title": _("Inactive"),
80
                "contentFilter": {'is_active': False},
81
                "columns": self.columns.keys(),
82
            }, {
83
                "id": "all",
84
                "title": _("All"),
85
                "contentFilter": {},
86
                "columns": self.columns.keys(),
87
            },
88
        ]
89
90
    def folderitem(self, obj, item, index):
91
        """Service triggered each time an item is iterated in folderitems.
92
        The use of this service prevents the extra-loops in child objects.
93
        :obj: the instance of the class to be foldered
94
        :item: dict containing the properties of the object to be used by
95
            the template
96
        :index: current index of the item
97
        """
98
        obj = api.get_object(obj)
99
100
        item["replace"]["Title"] = get_link_for(obj)
101
        item["Description"] = api.get_description(obj)
102
103
        return item
104