Passed
Push — 2.x ( e94308...699219 )
by Jordi
09:28
created

senaite.core.browser.controlpanel.labels   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 84
Duplicated Lines 86.9 %

Importance

Changes 0
Metric Value
wmc 3
eloc 50
dl 73
loc 84
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A LabelsView.__init__() 48 48 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
import collections
4
5
from bika.lims import api
6
from bika.lims import bikaMessageFactory as _
7
from bika.lims.utils import get_link_for
8
from senaite.app.listing import ListingView
9
10
11 View Code Duplication
class LabelsView(ListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
    """Displays all available labels
13
    """
14
15
    def __init__(self, context, request):
16
        super(LabelsView, self).__init__(context, request)
17
18
        self.contentFilter = {
19
            "portal_type": "Label",
20
            "sort_on": "sortable_title",
21
        }
22
23
        self.context_actions = {
24
            _("Add"): {
25
                "url": "++add++Label",
26
                "icon": "++resource++bika.lims.images/add.png",
27
            }}
28
29
        t = self.context.translate
30
        self.title = t(_("Labels"))
31
        self.description = t(_("Add default selectable labels"))
32
33
        self.show_select_column = True
34
        self.show_all = False
35
36
        self.columns = collections.OrderedDict((
37
            ("Title", {
38
                "title": _("Title"),
39
                "index": "sortable_title"}),
40
            ("Description", {
41
                "title": _("Description"),
42
                "index": "Description",
43
                "toggle": True,
44
            }),
45
        ))
46
47
        self.review_states = [
48
            {
49
                "id": "default",
50
                "title": _("Active"),
51
                "contentFilter": {"is_active": True},
52
                "columns": self.columns.keys(),
53
            }, {
54
                "id": "inactive",
55
                "title": _("Inactive"),
56
                "contentFilter": {'is_active': False},
57
                "columns": self.columns.keys(),
58
            }, {
59
                "id": "all",
60
                "title": _("All"),
61
                "contentFilter": {},
62
                "columns": self.columns.keys(),
63
            },
64
        ]
65
66
    def folderitem(self, obj, item, index):
67
        """Service triggered each time an item is iterated in folderitems.
68
        The use of this service prevents the extra-loops in child objects.
69
        :obj: the instance of the class to be foldered
70
        :item: dict containing the properties of the object to be used by
71
            the template
72
        :index: current index of the item
73
        """
74
        obj = api.get_object(obj)
75
76
        item["replace"]["Title"] = get_link_for(obj)
77
        item["Description"] = api.get_description(obj)
78
79
        return item
80
81
    def folderitems(self):
82
        items = super(LabelsView, self).folderitems()
83
        return items
84