Passed
Pull Request — 2.x (#1911)
by Jordi
12:55 queued 07:53
created

senaite.core.browser.controlpanel.samplecontainers   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 71
dl 0
loc 113
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 60 1
1
# -*- coding: utf-8 -*-
2
3
import collections
4
5
from bika.lims import api
6
from bika.lims import senaiteMessageFactory as _
7
from bika.lims.utils import get_link_for
8
from senaite.app.listing import ListingView
9
10
11
class SampleContainersView(ListingView):
12
    """Displays all available sample containers in a table
13
    """
14
15
    def __init__(self, context, request):
16
        super(SampleContainersView, self).__init__(context, request)
17
18
        self.contentFilter = {
19
            "portal_type": "SampleContainer",
20
            "sort_on": "sortable_title",
21
        }
22
23
        self.context_actions = {
24
            _("Add"): {
25
                "url": "++add++SampleContainer",
26
                "icon": "++resource++bika.lims.images/add.png",
27
            }}
28
29
        t = self.context.translate
30
        self.title = t(_("Sample Containers"))
31
        self.description = t(_(""))
32
33
        self.show_select_column = True
34
        self.pagesize = 25
35
36
        self.columns = collections.OrderedDict((
37
            ("title", {
38
                "title": _("Container"),
39
                "index": "sortable_title"}),
40
            ("description", {
41
                "title": _("Description"),
42
                "index": "Description",
43
                "toggle": True,
44
            }),
45
            ("containertype", {
46
                "title": _("Container Type"),
47
                "toggle": True}),
48
            ("capacity", {
49
                "title": _("Capacity"),
50
                "toggle": True}),
51
            ("pre_preserved", {
52
                "title": _("Pre-preserved"),
53
                "toggle": True}),
54
            ("security_seal_intact", {
55
                "title": _("Security seal intact"),
56
                "toggle": True}),
57
        ))
58
59
        self.review_states = [
60
            {
61
                "id": "default",
62
                "title": _("Active"),
63
                "contentFilter": {"is_active": True},
64
                "columns": self.columns.keys(),
65
            }, {
66
                "id": "inactive",
67
                "title": _("Inactive"),
68
                "contentFilter": {'is_active': False},
69
                "columns": self.columns.keys(),
70
            }, {
71
                "id": "all",
72
                "title": _("All"),
73
                "contentFilter": {},
74
                "columns": self.columns.keys(),
75
            },
76
        ]
77
78
    def folderitem(self, obj, item, index):
79
        """Service triggered each time an item is iterated in folderitems.
80
        The use of this service prevents the extra-loops in child objects.
81
82
        :obj: the instance of the class to be foldered
83
        :item: dict containing the properties of the object to be used by
84
            the template
85
        :index: current index of the item
86
        """
87
        obj = api.get_object(obj)
88
89
        item["replace"]["title"] = get_link_for(obj)
90
        item["description"] = api.get_description(obj)
91
92
        # container type
93
        containertype = obj.getContainerType()
94
        if containertype:
95
            item["containertype"] = containertype.title
96
            item["replace"]["containertype"] = get_link_for(containertype)
97
98
        # capacity
99
        item["capacity"] = obj.getCapacity()
100
101
        # pre-preserved and preservation
102
        if obj.getPrePreserved():
103
            preservation = obj.getPreservation()
104
            if preservation:
105
                item["after"]["pre_preserved"] = get_link_for(preservation)
106
107
        if obj.getSecuritySealIntact():
108
            item["security_seal_intact"] = _("Yes")
109
        else:
110
            item["security_seal_intact"] = _("No")
111
112
        return item
113