Passed
Push — 2.x ( c53634...536dd4 )
by Jordi
05:55
created

BatchLabelsView.folderitem()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 3
dl 3
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 4
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 AddBatchLabel
30
31
32 View Code Duplication
class BatchLabelsView(ListingView):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
33
34
    def __init__(self, context, request):
35
        super(BatchLabelsView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
39
        self.contentFilter = {
40
            "portal_type": "BatchLabel",
41
            "sort_on": "sortable_title",
42
            "sort_order": "ascending",
43
            "path": {
44
                "query": api.get_path(context),
45
                "depth": 1,
46
            }
47
        }
48
49
        self.context_actions = {
50
            _("listing_batchlabels_action_add", default="Add"): {
51
                "url": "++add++BatchLabel",
52
                "permission": AddBatchLabel,
53
                "icon": "senaite_theme/icon/plus"
54
            }
55
        }
56
57
        self.title = translate(_(
58
            "listing_batchlabels_title",
59
            default="Batch Labels")
60
        )
61
62
        self.icon = api.get_icon("BatchLabels", html_tag=False)
63
        self.description = ""
64
65
        self.columns = collections.OrderedDict((
66
            ("Title", {
67
                "title": _(
68
                    u"listing_batchlabels_column_title",
69
                    default=u"Title"
70
                ),
71
                "index": "sortable_title"}),
72
            ))
73
74
        self.review_states = [
75
            {
76
                "id": "default",
77
                "title": _(
78
                    u"listing_batchlabels_state_active",
79
                    default=u"Active"
80
                ),
81
                "contentFilter": {"is_active": True},
82
                "columns": self.columns.keys(),
83
            }, {
84
                "id": "inactive",
85
                "title": _(
86
                    u"listing_batchlabels_state_inactive",
87
                    default=u"Inactive"
88
                ),
89
                "contentFilter": {"is_active": False},
90
                "columns": self.columns.keys(),
91
            }, {
92
                "id": "all",
93
                "title": _(
94
                    u"listing_batchlabels_state_all",
95
                    default=u"All"
96
                ),
97
                "contentFilter": {},
98
                "columns": self.columns.keys(),
99
            },
100
        ]
101
102
    def folderitem(self, obj, item, index):
103
        item["replace"]["Title"] = get_link_for(obj)
104
        return item
105