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): |
|
|
|
|
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
|
|
|
|