Passed
Push — 2.x ( 3a8d9c...f90226 )
by Ramon
06:47
created

DynamicAnalysisSpecsView.__init__()   B

Complexity

Conditions 1

Size

Total Lines 72
Code Lines 51

Duplication

Lines 72
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 51
dl 72
loc 72
rs 8.6036
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 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
from senaite.core.i18n import translate
29
from senaite.core.permissions import AddAnalysisSpec
30
31
32 View Code Duplication
class DynamicAnalysisSpecsView(ListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
33
    """Displays all system's dynamic analysis specifications
34
    """
35
36
    def __init__(self, context, request):
37
        super(DynamicAnalysisSpecsView, self).__init__(context, request)
38
39
        self.catalog = SETUP_CATALOG
40
41
        self.contentFilter = {
42
            "portal_type": "DynamicAnalysisSpec",
43
            "sort_on": "created",
44
            "sort_order": "descending",
45
            "path": {
46
                "query": api.get_path(self.context),
47
                "depth": 1,
48
            },
49
        }
50
51
        self.context_actions = {
52
            _("listing_dynamic_analysisspec_action_add", default="Add"): {
53
                "url": "++add++DynamicAnalysisSpec",
54
                "permission": AddAnalysisSpec,
55
                "icon": "senaite_theme/icon/plus"
56
            }
57
        }
58
59
        self.icon = api.get_icon("DynamicAnalysisSpecs", html_tag=False)
60
61
        self.title = translate(_(
62
            u"listing_dynamic_analysisspecs_title",
63
            default=u"Dynamic Analysis Specifications")
64
        )
65
        self.description = self.context.Description()
66
        self.show_select_column = True
67
68
        self.columns = collections.OrderedDict((
69
            ("Title", {
70
                "title": _(
71
                    u"listing_dynamic_analysisspecs_column_title",
72
                    default=u"Title"
73
                ),
74
                "index": "sortable_title"}),
75
            ("Description", {
76
                "title": _(
77
                    u"listing_dynamic_analysisspecs_column_description",
78
                    default=u"Description"
79
                ),
80
                "toggle": True}),
81
        ))
82
83
        self.review_states = [
84
            {
85
                "id": "default",
86
                "title": _(
87
                    u"listing_dynamic_analysisspecs_state_active",
88
                    default=u"Active"
89
                ),
90
                "contentFilter": {"is_active": True},
91
                "columns": self.columns.keys(),
92
            }, {
93
                "id": "inactive",
94
                "title": _(
95
                    u"listing_dynamic_analysisspecs_state_inactive",
96
                    default=u"Inactive"
97
                ),
98
                "contentFilter": {"is_active": False},
99
                "columns": self.columns.keys(),
100
            }, {
101
                "id": "all",
102
                "title": _(
103
                    u"listing_dynamic_analysisspecs_state_all",
104
                    default=u"All"
105
                ),
106
                "contentFilter": {},
107
                "columns": self.columns.keys(),
108
            },
109
        ]
110
111
    def folderitem(self, obj, item, index):
112
        """Service triggered each time an item is iterated in folderitems.
113
        The use of this service prevents the extra-loops in child objects.
114
        :obj: the instance of the class to be foldered
115
        :item: dict containing the properties of the object to be used by
116
            the template
117
        :index: current index of the item
118
        """
119
        item["replace"]["Title"] = get_link_for(obj)
120
        return item
121