Passed
Push — 2.x ( a1ea4f...a653ea )
by Jordi
06:57
created

senaite.core.browser.controlpanel.samplingdeviations.view   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 66
dl 0
loc 123
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A SamplingDeviationsView.folderitem() 0 14 1
B SamplingDeviationsView.__init__() 0 72 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.core.i18n import translate
27
from senaite.app.listing import ListingView
28
from senaite.core.catalog import SETUP_CATALOG
29
from senaite.core.permissions import AddSamplingDeviation
30
31
32
class SamplingDeviationsView(ListingView):
33
34
    def __init__(self, context, request):
35
        super(SamplingDeviationsView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
        self.contentFilter = {
39
            "portal_type": "SamplingDeviation",
40
            "sort_on": "sortable_title",
41
            "sort_order": "ascending",
42
            "path": {
43
                "query": api.get_path(self.context),
44
                "depth": 1,
45
            },
46
        }
47
48
        self.context_actions = {
49
            _("listing_samplingdeviations_action_add", default="Add"): {
50
                "url": "++add++SamplingDeviation",
51
                "permission": AddSamplingDeviation,
52
                "icon": "senaite_theme/icon/plus"
53
            }
54
        }
55
56
        self.title = translate(_(
57
            "listing_samplingdeviations_title",
58
            default="Sampling Deviations")
59
        )
60
        self.icon = api.get_icon("SamplingDeviations", html_tag=False)
61
        self.show_select_column = True
62
63
        self.columns = collections.OrderedDict((
64
            ("Title", {
65
                "title": _(
66
                    "listing_samplingdeviations_column_title",
67
                    default="Sampling Deviation",
68
                ),
69
                "index": "sortable_title",
70
            }),
71
            ("Description", {
72
                "title": _(
73
                    "listing_samplingdeviations_column_description",
74
                    default="Description",
75
                ),
76
                "index": "Description",
77
                "toggle": True,
78
            }),
79
        ))
80
81
        self.review_states = [
82
            {
83
                "id": "default",
84
                "title": _(
85
                    "listing_samplingdeviations_state_all",
86
                    default="All",
87
                ),
88
                "contentFilter": {},
89
                "columns": self.columns.keys(),
90
            }, {
91
                "id": "active",
92
                "title": _(
93
                    "listing_samplingdeviations_state_active",
94
                    default="Active",
95
                ),
96
                "contentFilter": {"is_active": True},
97
                "columns": self.columns.keys(),
98
            }, {
99
                "id": "inactive",
100
                "title": _(
101
                    "listing_samplingdeviations_state_inactive",
102
                    default="Inactive",
103
                ),
104
                "contentFilter": {'is_active': False},
105
                "columns": self.columns.keys(),
106
            }
107
        ]
108
109
    def folderitem(self, obj, item, index):
110
        """Service triggered each time an item is iterated in folderitems.
111
        The use of this service prevents the extra-loops in child objects.
112
        :obj: the instance of the class to be foldered
113
        :item: dict containing the properties of the object to be used by
114
            the template
115
        :index: current index of the item
116
        """
117
        obj = api.get_object(obj)
118
119
        item["replace"]["Title"] = get_link_for(obj)
120
        item["Description"] = api.get_description(obj)
121
122
        return item
123