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