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

senaite.core.browser.controlpanel.samplecontainers.view   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 73
dl 0
loc 134
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A SampleContainersView.folderitem() 0 35 5
B SampleContainersView.__init__() 0 62 1
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 senaiteMessageFactory 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
29
30
class SampleContainersView(ListingView):
31
    """Displays all available sample containers in a table
32
    """
33
34
    def __init__(self, context, request):
35
        super(SampleContainersView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
39
        self.contentFilter = {
40
            "portal_type": "SampleContainer",
41
            "sort_on": "sortable_title",
42
        }
43
44
        self.context_actions = {
45
            _("Add"): {
46
                "url": "++add++SampleContainer",
47
                "icon": "++resource++bika.lims.images/add.png",
48
            }}
49
50
        t = self.context.translate
51
        self.title = t(_("Sample Containers"))
52
        self.description = t(_(""))
53
54
        self.show_select_column = True
55
        self.pagesize = 25
56
57
        self.columns = collections.OrderedDict((
58
            ("title", {
59
                "title": _("Container"),
60
                "index": "sortable_title"}),
61
            ("description", {
62
                "title": _("Description"),
63
                "index": "Description",
64
                "toggle": True,
65
            }),
66
            ("containertype", {
67
                "title": _("Container Type"),
68
                "toggle": True}),
69
            ("capacity", {
70
                "title": _("Capacity"),
71
                "toggle": True}),
72
            ("pre_preserved", {
73
                "title": _("Pre-preserved"),
74
                "toggle": True}),
75
            ("security_seal_intact", {
76
                "title": _("Security seal intact"),
77
                "toggle": True}),
78
        ))
79
80
        self.review_states = [
81
            {
82
                "id": "default",
83
                "title": _("Active"),
84
                "contentFilter": {"is_active": True},
85
                "columns": self.columns.keys(),
86
            }, {
87
                "id": "inactive",
88
                "title": _("Inactive"),
89
                "contentFilter": {'is_active': False},
90
                "columns": self.columns.keys(),
91
            }, {
92
                "id": "all",
93
                "title": _("All"),
94
                "contentFilter": {},
95
                "columns": self.columns.keys(),
96
            },
97
        ]
98
99
    def folderitem(self, obj, item, index):
100
        """Service triggered each time an item is iterated in folderitems.
101
        The use of this service prevents the extra-loops in child objects.
102
103
        :obj: the instance of the class to be foldered
104
        :item: dict containing the properties of the object to be used by
105
            the template
106
        :index: current index of the item
107
        """
108
        obj = api.get_object(obj)
109
110
        item["replace"]["title"] = get_link_for(obj)
111
        item["description"] = api.get_description(obj)
112
113
        # container type
114
        containertype = obj.getContainerType()
115
        if containertype:
116
            item["containertype"] = containertype.title
117
            item["replace"]["containertype"] = get_link_for(containertype)
118
119
        # capacity
120
        item["capacity"] = obj.getCapacity()
121
122
        # pre-preserved and preservation
123
        if obj.getPrePreserved():
124
            preservation = obj.getPreservation()
125
            if preservation:
126
                item["after"]["pre_preserved"] = get_link_for(preservation)
127
128
        if obj.getSecuritySealIntact():
129
            item["security_seal_intact"] = _("Yes")
130
        else:
131
            item["security_seal_intact"] = _("No")
132
133
        return item
134