Passed
Push — 2.x ( aec8b4...7066e1 )
by Jordi
08:07
created

StorageLocationsView.folderitem()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 13
rs 9.85
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.core.i18n import translate
27
from senaite.app.listing import ListingView
28
from senaite.core.catalog import SETUP_CATALOG
29
from senaite.core.permissions import AddStorageLocation
30
31
32
class StorageLocationsView(ListingView):
33
34
    def __init__(self, context, request):
35
        super(StorageLocationsView, self).__init__(context, request)
36
37
        self.catalog = SETUP_CATALOG
38
39
        self.contentFilter = {
40
            "portal_type": "StorageLocation",
41
            "sort_on": "sortable_title",
42
            "path": {
43
                "query": api.get_path(self.context),
44
                "depth": 1,
45
            }
46
        }
47
48
        self.context_actions = {
49
            _("listing_storagelocations_action_add", default="Add"): {
50
                "url": "++add++StorageLocation",
51
                "permission": AddStorageLocation,
52
                "icon": "senaite_theme/icon/plus"
53
            }}
54
55
        self.title = translate(_(
56
            "listing_storagelocations_title",
57
            default="Storage Locations")
58
        )
59
        self.description = ""
60
        self.icon = api.get_icon("StorageLocations", html_tag=False)
61
62
        self.show_select_row = False
63
        self.show_select_column = True
64
        self.pagesize = 25
65
66
        self.columns = collections.OrderedDict((
67
            ("Title", {
68
                "title": _(
69
                    "listing_storagelocations_column_title",
70
                    default="Storage Location",
71
                ),
72
                "index": "sortable_title",
73
            }),
74
            ("Description", {
75
                "title": _(
76
                    "listing_storagelocations_column_description",
77
                    default="Description",
78
                ),
79
                "index": "description",
80
                "toggle": True,
81
            }),
82
            ("SiteTitle", {
83
                "title": _(
84
                    "listing_storagelocations_column_site_title",
85
                    default="Site Title",
86
                ),
87
                "toggle": True,
88
            }),
89
            ("SiteCode", {
90
                "title": _(
91
                    "listing_storagelocations_column_site_code",
92
                    default="Site Code",
93
                ),
94
                "toggle": True,
95
            }),
96
            ("LocationTitle", {
97
                "title": _(
98
                    "listing_storagelocations_column_location_title",
99
                    default="Location Title",
100
                ),
101
                "toggle": True,
102
            }),
103
            ("LocationCode", {
104
                "title": _(
105
                    "listing_storagelocations_column_location_code",
106
                    default="Location Code",
107
                ),
108
                "toggle": True,
109
            }),
110
            ("ShelfTitle", {
111
                "title": _(
112
                    "listing_storagelocations_column_shelf_title",
113
                    default="Shelf Title",
114
                ),
115
                "toggle": True,
116
            }),
117
            ("ShelfCode", {
118
                "title": _(
119
                    "listing_storagelocations_column_shelf_code",
120
                    default="Shelf Code",
121
                ),
122
                "toggle": True,
123
            }),
124
        ))
125
126
        self.review_states = [
127
            {
128
                "id": "default",
129
                "title": _(
130
                    "listing_storagelocations_state_active",
131
                    default="Active",
132
                ),
133
                "contentFilter": {"is_active": True},
134
                "transitions": [{"id": "deactivate"}, ],
135
                "columns": self.columns.keys(),
136
            }, {
137
                "id": "inactive",
138
                "title": _(
139
                    "listing_storagelocations_state_inactive",
140
                    default="Inactive",
141
                ),
142
                "contentFilter": {"is_active": False},
143
                "transitions": [{"id": "activate"}, ],
144
                "columns": self.columns.keys(),
145
            }, {
146
                "id": "all",
147
                "title": _(
148
                    "listing_storagelocations_state_all",
149
                    default="All",
150
                ),
151
                "contentFilter": {},
152
                "columns": self.columns.keys(),
153
            },
154
        ]
155
156
    def folderitem(self, obj, item, index):
157
        obj = api.get_object(obj)
158
        item["Description"] = api.get_description(obj)
159
        item["replace"]["Title"] = get_link_for(obj)
160
161
        item["SiteTitle"] = obj.getSiteTitle()
162
        item["SiteCode"] = obj.getSiteCode()
163
        item["LocationTitle"] = obj.getLocationTitle()
164
        item["LocationCode"] = obj.getLocationCode()
165
        item["ShelfTitle"] = obj.getShelfTitle()
166
        item["ShelfCode"] = obj.getShelfCode()
167
168
        return item
169