1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE |
4
|
|
|
# |
5
|
|
|
# Copyright 2018 by it's authors. |
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
import collections |
10
|
|
|
|
11
|
|
|
from bika.lims import bikaMessageFactory as _ |
12
|
|
|
from bika.lims.browser.bika_listing import BikaListingView |
13
|
|
|
from bika.lims.config import PROJECTNAME |
14
|
|
|
from bika.lims.interfaces import IReferenceDefinitions |
15
|
|
|
from bika.lims.permissions import AddReferenceDefinition |
16
|
|
|
from bika.lims.utils import get_image |
17
|
|
|
from bika.lims.utils import get_link |
18
|
|
|
from bika.lims.utils import t |
19
|
|
|
from plone.app.folder.folder import ATFolder |
20
|
|
|
from plone.app.folder.folder import ATFolderSchema |
21
|
|
|
from Products.ATContentTypes.content import schemata |
22
|
|
|
from Products.Archetypes.public import registerType |
23
|
|
|
from zope.interface.declarations import implements |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class ReferenceDefinitionsView(BikaListingView): |
27
|
|
|
"""Listing view for all Methods |
28
|
|
|
""" |
29
|
|
|
|
30
|
|
View Code Duplication |
def __init__(self, context, request): |
|
|
|
|
31
|
|
|
super(ReferenceDefinitionsView, self).__init__(context, request) |
32
|
|
|
|
33
|
|
|
self.catalog = "bika_setup_catalog" |
34
|
|
|
|
35
|
|
|
self.contentFilter = { |
36
|
|
|
"portal_type": "ReferenceDefinition", |
37
|
|
|
"sort_on": "sortable_title", |
38
|
|
|
"sort_order": "ascending" |
39
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
self.context_actions = { |
43
|
|
|
_("Add"): { |
44
|
|
|
"url": "createObject?type_name=ReferenceDefinition", |
45
|
|
|
"permission": AddReferenceDefinition, |
46
|
|
|
"icon": "++resource++bika.lims.images/add.png"}} |
47
|
|
|
|
48
|
|
|
self.title = self.context.translate(_("Reference Definitions")) |
49
|
|
|
self.description = "" |
50
|
|
|
self.icon = "{}/{}".format( |
51
|
|
|
self.portal_url, |
52
|
|
|
"++resource++bika.lims.images/referencedefinition_big.png") |
53
|
|
|
|
54
|
|
|
self.show_select_column = True |
55
|
|
|
self.pagesize = 25 |
56
|
|
|
|
57
|
|
|
self.columns = collections.OrderedDict(( |
58
|
|
|
("Title", { |
59
|
|
|
"title": _("Title"), |
60
|
|
|
"index": "sortable_title"}), |
61
|
|
|
("Description", { |
62
|
|
|
"title": _("Description"), |
63
|
|
|
"index": "description", |
64
|
|
|
"toggle": True}), |
65
|
|
|
)) |
66
|
|
|
|
67
|
|
|
self.review_states = [ |
68
|
|
|
{ |
69
|
|
|
"id": "default", |
70
|
|
|
"title": _("Active"), |
71
|
|
|
"contentFilter": {"is_active": True}, |
72
|
|
|
"columns": self.columns.keys(), |
73
|
|
|
}, { |
74
|
|
|
"id": "inactive", |
75
|
|
|
"title": _("Inactive"), |
76
|
|
|
"contentFilter": {"is_active": False}, |
77
|
|
|
"columns": self.columns.keys(), |
78
|
|
|
}, { |
79
|
|
|
"id": "all", |
80
|
|
|
"title": _("All"), |
81
|
|
|
"contentFilter": {}, |
82
|
|
|
"columns": self.columns.keys(), |
83
|
|
|
}, |
84
|
|
|
] |
85
|
|
|
|
86
|
|
|
def before_render(self): |
87
|
|
|
"""Before template render hook |
88
|
|
|
""" |
89
|
|
|
# Don't allow any context actions |
90
|
|
|
self.request.set("disable_border", 1) |
91
|
|
|
|
92
|
|
|
def folderitem(self, obj, item, index): |
93
|
|
|
"""Applies new properties to the item (Client) that is currently being |
94
|
|
|
rendered as a row in the list |
95
|
|
|
|
96
|
|
|
:param obj: client to be rendered as a row in the list |
97
|
|
|
:param item: dict representation of the client, suitable for the list |
98
|
|
|
:param index: current position of the item within the list |
99
|
|
|
:type obj: ATContentType/DexterityContentType |
100
|
|
|
:type item: dict |
101
|
|
|
:type index: int |
102
|
|
|
:return: the dict representation of the item |
103
|
|
|
:rtype: dict |
104
|
|
|
""" |
105
|
|
|
|
106
|
|
|
url = obj.absolute_url() |
107
|
|
|
title = obj.Title() |
108
|
|
|
|
109
|
|
|
item['Description'] = obj.Description() |
110
|
|
|
item["replace"]["Title"] = get_link(url, value=title) |
111
|
|
|
|
112
|
|
|
# Icons |
113
|
|
|
after_icons = "" |
114
|
|
|
if obj.getBlank(): |
115
|
|
|
after_icons += get_image( |
116
|
|
|
"blank.png", title=t(_("Blank"))) |
117
|
|
|
if obj.getHazardous(): |
118
|
|
|
after_icons += get_image( |
119
|
|
|
"hazardous.png", title=t(_("Hazardous"))) |
120
|
|
|
if after_icons: |
121
|
|
|
item["after"]["Title"] = after_icons |
122
|
|
|
|
123
|
|
|
return item |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
schema = ATFolderSchema.copy() |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
class ReferenceDefinitions(ATFolder): |
130
|
|
|
"""Reference definition content |
131
|
|
|
""" |
132
|
|
|
implements(IReferenceDefinitions) |
133
|
|
|
|
134
|
|
|
displayContentsTab = False |
135
|
|
|
schema = schema |
|
|
|
|
136
|
|
|
|
137
|
|
|
|
138
|
|
|
schemata.finalizeATCTSchema(schema, folderish=True, moveDiscussion=False) |
139
|
|
|
|
140
|
|
|
registerType(ReferenceDefinitions, PROJECTNAME) |
141
|
|
|
|