Passed
Push — 2.x ( e9dfc8...fde57f )
by Ramon
06:12
created

SampleMatricesView.__init__()   B

Complexity

Conditions 1

Size

Total Lines 66
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 66
rs 8.7345
c 0
b 0
f 0
cc 1
nop 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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.i18n import translate
29
from senaite.core.permissions import AddSampleMatrix
30
31
32
class SampleMatricesView(ListingView):
33
34
    def __init__(self, context, request):
35
        super(SampleMatricesView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
        self.show_select_column = True
39
40
        self.contentFilter = {
41
            "portal_type": "SampleMatrix",
42
            "sort_on": "sortable_title",
43
            "sort_order": "ascending",
44
        }
45
46
        self.context_actions = {
47
            _(u"listing_samplematrices_action_add", default=u"Add"): {
48
                "url": "++add++SampleMatrix",
49
                "permission": AddSampleMatrix,
50
                "icon": "senaite_theme/icon/plus"
51
            }
52
        }
53
54
        self.title = translate(_(
55
            u"listing_samplematrices_title",
56
            default=u"Sample Matrices")
57
        )
58
        self.icon = api.get_icon("SampleMatrices", html_tag=False)
59
60
        self.columns = collections.OrderedDict((
61
            ("Title", {
62
                "title": _(
63
                    u"listing_samplematrices_column_title",
64
                    default=u"Sample Matrix"
65
                ),
66
                "index": "sortable_title"}),
67
            ("Description", {
68
                "title": _(
69
                    u"listing_samplematrices_column_description",
70
                    default=u"Description"
71
                ),
72
                "toggle": True}),
73
        ))
74
75
        self.review_states = [
76
            {
77
                "id": "default",
78
                "title": _(
79
                    u"listing_samplematrices_state_active",
80
                    default=u"Active"
81
                ),
82
                "contentFilter": {"is_active": True},
83
                "columns": self.columns.keys(),
84
            }, {
85
                "id": "inactive",
86
                "title": _(
87
                    u"listing_samplematrices_state_inactive",
88
                    default=u"Inactive"
89
                ),
90
                "contentFilter": {"is_active": False},
91
                "columns": self.columns.keys(),
92
            }, {
93
                "id": "all",
94
                "title": _(
95
                    u"listing_samplematrices_state_all",
96
                    default=u"All"
97
                ),
98
                "contentFilter": {},
99
                "columns": self.columns.keys(),
100
            },
101
        ]
102
103
    def folderitem(self, obj, item, index):
104
        item["replace"]["Title"] = get_link_for(obj)
105
        return item
106