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 bika.lims.utils import t |
9
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
10
|
|
|
from senaite.app.listing import ListingView |
11
|
|
|
from senaite.core.api import label as label_api |
12
|
|
|
from senaite.core.catalog import LABEL_CATALOG |
13
|
|
|
from senaite.core.interfaces import IHaveLabels |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class LabeledObjectsView(ListingView): |
17
|
|
|
"""Displays all available labels |
18
|
|
|
""" |
19
|
|
|
|
20
|
|
|
def __init__(self, context, request): |
21
|
|
|
super(LabeledObjectsView, self).__init__(context, request) |
22
|
|
|
|
23
|
|
|
self.contentFilter = { |
24
|
|
|
"object_provides": IHaveLabels.__identifier__, |
25
|
|
|
"sort_on": "title", |
26
|
|
|
} |
27
|
|
|
self.catalog = LABEL_CATALOG |
28
|
|
|
|
29
|
|
|
self.context_actions = {} |
30
|
|
|
|
31
|
|
|
t = self.context.translate |
32
|
|
|
self.title = t(_("Labeled Objects")) |
33
|
|
|
self.description = t(_("List all objects with labels")) |
34
|
|
|
|
35
|
|
|
self.show_select_column = True |
36
|
|
|
self.show_all = False |
37
|
|
|
|
38
|
|
|
self.columns = collections.OrderedDict(( |
39
|
|
|
("Title", { |
40
|
|
|
"title": _("Title"), |
41
|
|
|
"index": "title"}), |
42
|
|
|
("Type", { |
43
|
|
|
"title": _("Type"), |
44
|
|
|
"toggle": True, |
45
|
|
|
"index": "portal_type"}), |
46
|
|
|
("Labels", { |
47
|
|
|
"title": _("Labels"), |
48
|
|
|
"toggle": True, |
49
|
|
|
"sortable": False}), |
50
|
|
|
)) |
51
|
|
|
|
52
|
|
|
self.review_states = [ |
53
|
|
|
{ |
54
|
|
|
"id": "default", |
55
|
|
|
"title": _("All"), |
56
|
|
|
"contentFilter": {}, |
57
|
|
|
"columns": self.columns.keys(), |
58
|
|
|
}, |
59
|
|
|
] |
60
|
|
|
|
61
|
|
|
def folderitem(self, obj, item, index): |
62
|
|
|
"""Service triggered each time an item is iterated in folderitems. |
63
|
|
|
The use of this service prevents the extra-loops in child objects. |
64
|
|
|
:obj: the instance of the class to be foldered |
65
|
|
|
:item: dict containing the properties of the object to be used by |
66
|
|
|
the template |
67
|
|
|
:index: current index of the item |
68
|
|
|
""" |
69
|
|
|
obj = api.get_object(obj) |
70
|
|
|
labels = label_api.get_obj_labels(obj) |
71
|
|
|
portal_type = api.get_portal_type(obj) |
72
|
|
|
pt = api.get_tool("portal_types") |
73
|
|
|
fti = pt.getTypeInfo(portal_type) |
74
|
|
|
type_title = fti.Title() |
75
|
|
|
|
76
|
|
|
item["replace"]["Title"] = get_link_for(obj) |
77
|
|
|
item["Type"] = t(_(type_title)) |
78
|
|
|
item["Labels"] = ", ".join(labels) |
79
|
|
|
item["replace"]["Labels"] = self.render_labels(labels) |
80
|
|
|
|
81
|
|
|
return item |
82
|
|
|
|
83
|
|
|
def render_labels(self, labels): |
84
|
|
|
template = ViewPageTemplateFile("templates/object_labels.pt") |
85
|
|
|
return template(self, labels=labels) |
86
|
|
|
|
87
|
|
|
def folderitems(self): |
88
|
|
|
items = super(LabeledObjectsView, self).folderitems() |
89
|
|
|
return items |
90
|
|
|
|