Code Duplication    Length = 71-73 lines in 2 locations

src/senaite/core/browser/controlpanel/labels.py 1 location

@@ 11-83 (lines=73) @@
8
from senaite.app.listing import ListingView
9
10
11
class LabelsView(ListingView):
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

src/senaite/core/browser/controlpanel/instrumentlocations.py 1 location

@@ 30-100 (lines=71) @@
27
from senaite.app.listing import ListingView
28
29
30
class InstrumentLocationsView(ListingView):
31
    """Displays all available instrument locations in a table
32
    """
33
34
    def __init__(self, context, request):
35
        super(InstrumentLocationsView, self).__init__(context, request)
36
37
        self.contentFilter = {
38
            "portal_type": "InstrumentLocation",
39
            "sort_on": "sortable_title",
40
        }
41
42
        self.context_actions = {
43
            _("Add"): {
44
                "url": "++add++InstrumentLocation",
45
                "permission": AddInstrumentLocation,
46
                "icon": "++resource++bika.lims.images/add.png",
47
            }}
48
49
        t = self.context.translate
50
        self.title = t(_("Instrument Locations"))
51
        self.description = t(_(
52
            "The place where the instrument is located in the laboratory"))
53
54
        self.show_select_column = True
55
        self.pagesize = 25
56
57
        self.columns = collections.OrderedDict((
58
            ("Title", {
59
                "title": _("Location"),
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