Passed
Push — 2.x ( 5e1af5...1a3808 )
by Ramon
05:55
created

SampleConditionsView.__init__()   B

Complexity

Conditions 1

Size

Total Lines 69
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 69
rs 8.6363
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 AddSampleCondition
30
31
32
class SampleConditionsView(ListingView):
33
34
    def __init__(self, context, request):
35
        super(SampleConditionsView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
        self.show_select_column = True
39
40
        self.contentFilter = {
41
            "portal_type": "SampleCondition",
42
            "sort_on": "sortable_title",
43
            "sort_order": "ascending",
44
        }
45
46
        self.context_actions = {
47
            _(u"listing_sampleconditions_action_add", default=u"Add"): {
48
                "url": "createObject?type_name=SampleCondition",
49
                "permission": AddSampleCondition,
50
                "icon": "++resource++bika.lims.images/add.png"
51
            }
52
        }
53
54
        self.title = translate(_(
55
            u"listing_sampleconditions_title",
56
            default=u"Sample Conditions")
57
        )
58
        self.icon = api.get_icon("SampleConditions", html_tag=False)
59
60
        self.columns = collections.OrderedDict((
61
            ("Title", {
62
                "title": _(
63
                    u"listing_sampleconditions_column_title",
64
                    default=u"Sample Condition"
65
                ),
66
                "index": "sortable_title"}),
67
            ("Description", {
68
                "title": _(
69
                    u"listing_sampleconditions_column_description",
70
                    default=u"Description"
71
                ),
72
                "index": "description",
73
                "toggle": True}),
74
        ))
75
76
        self.review_states = [
77
            {
78
                "id": "default",
79
                "title": _(
80
                    u"listing_sampleconditions_state_active",
81
                    default=u"Active"
82
                ),
83
                "contentFilter": {"is_active": True},
84
                "transitions": [{"id": "deactivate"}, ],
85
                "columns": self.columns.keys(),
86
            }, {
87
                "id": "inactive",
88
                "title": _(
89
                    u"listing_sampleconditions_state_inactive",
90
                    default=u"Inactive"
91
                ),
92
                "contentFilter": {'is_active': False},
93
                "transitions": [{"id": "activate"}, ],
94
                "columns": self.columns.keys(),
95
            }, {
96
                "id": "all",
97
                "title": _(
98
                    u"listing_sampleconditions_state_all",
99
                    default=u"All"
100
                ),
101
                "contentFilter": {},
102
                "columns": self.columns.keys(),
103
            },
104
        ]
105
106
    def folderitem(self, obj, item, index):
107
        """Service triggered each time an item is iterated in folderitems.
108
        The use of this service prevents the extra-loops in child objects.
109
        :obj: the instance of the class to be foldered
110
        :item: dict containing the properties of the object to be used by
111
            the template
112
        :index: current index of the item
113
        """
114
        item["replace"]["Title"] = get_link_for(obj)
115
        return item
116