Passed
Push — 2.x ( 44675d...5e1af5 )
by Jordi
09:20
created

senaite.core.browser.controlpanel.labels.view   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 105
Duplicated Lines 71.43 %

Importance

Changes 0
Metric Value
wmc 3
eloc 52
dl 75
loc 105
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A LabelsView.__init__() 50 50 1
A LabelsView.folderitem() 14 14 1
A LabelsView.folderitems() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
29
30 View Code Duplication
class LabelsView(ListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
31
    """Displays all available labels
32
    """
33
34
    def __init__(self, context, request):
35
        super(LabelsView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
39
        self.contentFilter = {
40
            "portal_type": "Label",
41
            "sort_on": "sortable_title",
42
        }
43
44
        self.context_actions = {
45
            _("Add"): {
46
                "url": "++add++Label",
47
                "icon": "++resource++bika.lims.images/add.png",
48
            }}
49
50
        t = self.context.translate
51
        self.title = t(_("Labels"))
52
        self.description = t(_("Add default selectable labels"))
53
54
        self.show_select_column = True
55
        self.show_all = False
56
57
        self.columns = collections.OrderedDict((
58
            ("Title", {
59
                "title": _("Title"),
60
                "index": "sortable_title"}),
61
            ("Description", {
62
                "title": _("Description"),
63
                "index": "Description",
64
                "toggle": True,
65
            }),
66
        ))
67
68
        self.review_states = [
69
            {
70
                "id": "default",
71
                "title": _("Active"),
72
                "contentFilter": {"is_active": True},
73
                "columns": self.columns.keys(),
74
            }, {
75
                "id": "inactive",
76
                "title": _("Inactive"),
77
                "contentFilter": {'is_active': False},
78
                "columns": self.columns.keys(),
79
            }, {
80
                "id": "all",
81
                "title": _("All"),
82
                "contentFilter": {},
83
                "columns": self.columns.keys(),
84
            },
85
        ]
86
87
    def folderitem(self, obj, item, index):
88
        """Service triggered each time an item is iterated in folderitems.
89
        The use of this service prevents the extra-loops in child objects.
90
        :obj: the instance of the class to be foldered
91
        :item: dict containing the properties of the object to be used by
92
            the template
93
        :index: current index of the item
94
        """
95
        obj = api.get_object(obj)
96
97
        item["replace"]["Title"] = get_link_for(obj)
98
        item["Description"] = api.get_description(obj)
99
100
        return item
101
102
    def folderitems(self):
103
        items = super(LabelsView, self).folderitems()
104
        return items
105