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 itertools |
22
|
|
|
|
23
|
|
|
from Acquisition import aq_base |
24
|
|
|
from bika.lims import api |
25
|
|
|
from bika.lims import logger |
26
|
|
|
from bika.lims.catalog import auditlog_catalog |
27
|
|
|
from bika.lims.catalog import getCatalogDefinitions |
28
|
|
|
from bika.lims.catalog import setup_catalogs |
29
|
|
|
from bika.lims.catalog.catalog_utilities import addZCTextIndex |
30
|
|
|
from plone import api as ploneapi |
31
|
|
|
|
32
|
|
|
PROFILE_ID = "profile-bika.lims:default" |
33
|
|
|
|
34
|
|
|
GROUPS = [ |
35
|
|
|
{ |
36
|
|
|
"id": "Analysts", |
37
|
|
|
"title": "Analysts", |
38
|
|
|
"roles": ["Analyst"], |
39
|
|
|
}, { |
40
|
|
|
"id": "Clients", |
41
|
|
|
"title": "Clients", |
42
|
|
|
"roles": ["Client"], |
43
|
|
|
}, { |
44
|
|
|
"id": "LabClerks", |
45
|
|
|
"title": "Lab Clerks", |
46
|
|
|
"roles": ["LabClerk"], |
47
|
|
|
}, { |
48
|
|
|
"id": "LabManagers", |
49
|
|
|
"title": "Lab Managers", |
50
|
|
|
"roles": ["LabManager"], |
51
|
|
|
}, { |
52
|
|
|
"id": "Preservers", |
53
|
|
|
"title": "Preservers", |
54
|
|
|
"roles": ["Preserver"], |
55
|
|
|
}, { |
56
|
|
|
"id": "Publishers", |
57
|
|
|
"title": "Publishers", |
58
|
|
|
"roles": ["Publisher"], |
59
|
|
|
}, { |
60
|
|
|
"id": "Verifiers", |
61
|
|
|
"title": "Verifiers", |
62
|
|
|
"roles": ["Verifier"], |
63
|
|
|
}, { |
64
|
|
|
"id": "Samplers", |
65
|
|
|
"title": "Samplers", |
66
|
|
|
"roles": ["Sampler"], |
67
|
|
|
}, { |
68
|
|
|
"id": "RegulatoryInspectors", |
69
|
|
|
"title": "Regulatory Inspectors", |
70
|
|
|
"roles": ["RegulatoryInspector"], |
71
|
|
|
}, { |
72
|
|
|
"id": "SamplingCoordinators", |
73
|
|
|
"title": "Sampling Coordinator", |
74
|
|
|
"roles": ["SamplingCoordinator"], |
75
|
|
|
} |
76
|
|
|
] |
77
|
|
|
|
78
|
|
|
NAV_BAR_ITEMS_TO_HIDE = ( |
79
|
|
|
# List of items to hide from navigation bar |
80
|
|
|
"arimports", |
81
|
|
|
"pricelists", |
82
|
|
|
"supplyorders", |
83
|
|
|
) |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
CONTENTS_TO_DELETE = ( |
87
|
|
|
# List of items to delete |
88
|
|
|
"Members", |
89
|
|
|
"news", |
90
|
|
|
"events", |
91
|
|
|
) |
92
|
|
|
|
93
|
|
|
CATALOG_MAPPINGS = ( |
94
|
|
|
# portal_type, catalog_ids |
95
|
|
|
("ARTemplate", ["bika_setup_catalog", "portal_catalog"]), |
96
|
|
|
("AnalysisCategory", ["bika_setup_catalog"]), |
97
|
|
|
("AnalysisProfile", ["bika_setup_catalog", "portal_catalog"]), |
98
|
|
|
("AnalysisService", ["bika_setup_catalog", "portal_catalog"]), |
99
|
|
|
("AnalysisSpec", ["bika_setup_catalog"]), |
100
|
|
|
("Attachment", ["portal_catalog"]), |
101
|
|
|
("AttachmentType", ["bika_setup_catalog"]), |
102
|
|
|
("Batch", ["bika_catalog", "portal_catalog"]), |
103
|
|
|
("BatchLabel", ["bika_setup_catalog"]), |
104
|
|
|
("Calculation", ["bika_setup_catalog", "portal_catalog"]), |
105
|
|
|
("Container", ["bika_setup_catalog"]), |
106
|
|
|
("ContainerType", ["bika_setup_catalog"]), |
107
|
|
|
("Department", ["bika_setup_catalog", "portal_catalog"]), |
108
|
|
|
("IdentifierType", ["bika_setup_catalog"]), |
109
|
|
|
("Instrument", ["bika_setup_catalog", "portal_catalog"]), |
110
|
|
|
("InstrumentLocation", ["bika_setup_catalog", "portal_catalog"]), |
111
|
|
|
("InstrumentType", ["bika_setup_catalog", "portal_catalog"]), |
112
|
|
|
("LabContact", ["bika_setup_catalog", "portal_catalog"]), |
113
|
|
|
("LabProduct", ["bika_setup_catalog", "portal_catalog"]), |
114
|
|
|
("Manufacturer", ["bika_setup_catalog", "portal_catalog"]), |
115
|
|
|
("Method", ["bika_setup_catalog", "portal_catalog"]), |
116
|
|
|
("Multifile", ["bika_setup_catalog"]), |
117
|
|
|
("Preservation", ["bika_setup_catalog"]), |
118
|
|
|
("ReferenceDefinition", ["bika_setup_catalog", "portal_catalog"]), |
119
|
|
|
("ReferenceSample", ["bika_catalog", "portal_catalog"]), |
120
|
|
|
("SRTemplate", ["bika_setup_catalog", "portal_catalog"]), |
121
|
|
|
("SampleCondition", ["bika_setup_catalog"]), |
122
|
|
|
("SampleMatrix", ["bika_setup_catalog"]), |
123
|
|
|
("SamplePoint", ["bika_setup_catalog", "portal_catalog"]), |
124
|
|
|
("SampleType", ["bika_setup_catalog", "portal_catalog"]), |
125
|
|
|
("SamplingDeviation", ["bika_setup_catalog"]), |
126
|
|
|
("StorageLocation", ["bika_setup_catalog", "portal_catalog"]), |
127
|
|
|
("SubGroup", ["bika_setup_catalog"]), |
128
|
|
|
("Supplier", ["bika_setup_catalog", "portal_catalog"]), |
129
|
|
|
("WorksheetTemplate", ["bika_setup_catalog", "portal_catalog"]), |
130
|
|
|
) |
131
|
|
|
|
132
|
|
|
INDEXES = ( |
133
|
|
|
# catalog, id, indexed attribute, type |
134
|
|
|
("bika_catalog", "BatchDate", "", "DateIndex"), |
135
|
|
|
("bika_catalog", "Creator", "", "FieldIndex"), |
136
|
|
|
("bika_catalog", "Description", "", "ZCTextIndex"), |
137
|
|
|
("bika_catalog", "Identifiers", "", "KeywordIndex"), |
138
|
|
|
("bika_catalog", "Title", "", "ZCTextIndex"), |
139
|
|
|
("bika_catalog", "Type", "", "FieldIndex"), |
140
|
|
|
("bika_catalog", "UID", "", "FieldIndex"), |
141
|
|
|
("bika_catalog", "allowedRolesAndUsers", "", "KeywordIndex"), |
142
|
|
|
("bika_catalog", "created", "", "DateIndex"), |
143
|
|
|
("bika_catalog", "getBlank", "", "BooleanIndex"), |
144
|
|
|
("bika_catalog", "getClientBatchID", "", "FieldIndex"), |
145
|
|
|
("bika_catalog", "getClientID", "", "FieldIndex"), |
146
|
|
|
("bika_catalog", "getClientTitle", "", "FieldIndex"), |
147
|
|
|
("bika_catalog", "getClientUID", "", "FieldIndex"), |
148
|
|
|
("bika_catalog", "getDateReceived", "", "DateIndex"), |
149
|
|
|
("bika_catalog", "getDateSampled", "", "DateIndex"), |
150
|
|
|
("bika_catalog", "getDueDate", "", "DateIndex"), |
151
|
|
|
("bika_catalog", "getExpiryDate", "", "DateIndex"), |
152
|
|
|
("bika_catalog", "getId", "", "FieldIndex"), |
153
|
|
|
("bika_catalog", "getReferenceDefinitionUID", "", "FieldIndex"), |
154
|
|
|
("bika_catalog", "getSampleTypeTitle", "", "FieldIndex"), |
155
|
|
|
("bika_catalog", "getSampleTypeUID", "", "FieldIndex"), |
156
|
|
|
("bika_catalog", "getSupportedServices", "", "KeywordIndex"), |
157
|
|
|
("bika_catalog", "id", "getId", "FieldIndex"), |
158
|
|
|
("bika_catalog", "isValid", "", "BooleanIndex"), |
159
|
|
|
("bika_catalog", "is_active", "", "BooleanIndex"), |
160
|
|
|
("bika_catalog", "path", "getPhysicalPath", "ExtendedPathIndex"), |
161
|
|
|
("bika_catalog", "portal_type", "", "FieldIndex"), |
162
|
|
|
("bika_catalog", "review_state", "", "FieldIndex"), |
163
|
|
|
("bika_catalog", "sortable_title", "", "FieldIndex"), |
164
|
|
|
("bika_catalog", "title", "", "FieldIndex"), |
165
|
|
|
|
166
|
|
|
("bika_setup_catalog", "Creator", "", "FieldIndex"), |
167
|
|
|
("bika_setup_catalog", "Description", "", "ZCTextIndex"), |
168
|
|
|
("bika_setup_catalog", "Identifiers", "", "KeywordIndex"), |
169
|
|
|
("bika_setup_catalog", "Title", "", "ZCTextIndex"), |
170
|
|
|
("bika_setup_catalog", "Type", "", "FieldIndex"), |
171
|
|
|
("bika_setup_catalog", "UID", "", "FieldIndex"), |
172
|
|
|
("bika_setup_catalog", "allowedRolesAndUsers", "", "KeywordIndex"), |
173
|
|
|
("bika_setup_catalog", "created", "", "DateIndex"), |
174
|
|
|
("bika_setup_catalog", "getAccredited", "", "FieldIndex"), |
175
|
|
|
("bika_setup_catalog", "getAnalyst", "", "FieldIndex"), |
176
|
|
|
("bika_setup_catalog", "getAvailableMethodUIDs", "", "KeywordIndex"), |
177
|
|
|
("bika_setup_catalog", "getBlank", "", "FieldIndex"), |
178
|
|
|
("bika_setup_catalog", "getCalculationTitle", "", "FieldIndex"), |
179
|
|
|
("bika_setup_catalog", "getCalculationUID", "", "FieldIndex"), |
180
|
|
|
("bika_setup_catalog", "getCalibrationExpiryDate", "", "FieldIndex"), |
181
|
|
|
("bika_setup_catalog", "getCategoryTitle", "", "FieldIndex"), |
182
|
|
|
("bika_setup_catalog", "getCategoryUID", "", "FieldIndex"), |
183
|
|
|
("bika_setup_catalog", "getClientUID", "", "FieldIndex"), |
184
|
|
|
("bika_setup_catalog", "getDepartmentTitle", "", "FieldIndex"), |
185
|
|
|
("bika_setup_catalog", "getDocumentID", "", "FieldIndex"), |
186
|
|
|
("bika_setup_catalog", "getDuplicateVariation", "", "FieldIndex"), |
187
|
|
|
("bika_setup_catalog", "getFormula", "", "FieldIndex"), |
188
|
|
|
("bika_setup_catalog", "getFullname", "", "FieldIndex"), |
189
|
|
|
("bika_setup_catalog", "getHazardous", "", "FieldIndex"), |
190
|
|
|
("bika_setup_catalog", "getId", "", "FieldIndex"), |
191
|
|
|
("bika_setup_catalog", "getInstrumentLocationName", "", "FieldIndex"), |
192
|
|
|
("bika_setup_catalog", "getInstrumentTitle", "", "FieldIndex"), |
193
|
|
|
("bika_setup_catalog", "getInstrumentType", "", "FieldIndex"), |
194
|
|
|
("bika_setup_catalog", "getInstrumentTypeName", "", "FieldIndex"), |
195
|
|
|
("bika_setup_catalog", "getKeyword", "", "FieldIndex"), |
196
|
|
|
("bika_setup_catalog", "getManagerEmail", "", "FieldIndex"), |
197
|
|
|
("bika_setup_catalog", "getManagerName", "", "FieldIndex"), |
198
|
|
|
("bika_setup_catalog", "getManagerPhone", "", "FieldIndex"), |
199
|
|
|
("bika_setup_catalog", "getMaxTimeAllowed", "", "FieldIndex"), |
200
|
|
|
("bika_setup_catalog", "getMethodID", "", "FieldIndex"), |
201
|
|
|
("bika_setup_catalog", "getModel", "", "FieldIndex"), |
202
|
|
|
("bika_setup_catalog", "getName", "", "FieldIndex"), |
203
|
|
|
("bika_setup_catalog", "getPointOfCapture", "", "FieldIndex"), |
204
|
|
|
("bika_setup_catalog", "getPrice", "", "FieldIndex"), |
205
|
|
|
("bika_setup_catalog", "getSamplePointTitle", "", "KeywordIndex"), |
206
|
|
|
("bika_setup_catalog", "getSamplePointUID", "", "FieldIndex"), |
207
|
|
|
("bika_setup_catalog", "getSampleTypeTitle", "", "FieldIndex"), |
208
|
|
|
("bika_setup_catalog", "getSampleTypeTitles", "", "KeywordIndex"), |
209
|
|
|
("bika_setup_catalog", "getSampleTypeUID", "", "FieldIndex"), |
210
|
|
|
("bika_setup_catalog", "getServiceUID", "", "FieldIndex"), |
211
|
|
|
("bika_setup_catalog", "getServiceUIDs", "", "KeywordIndex"), |
212
|
|
|
("bika_setup_catalog", "getTotalPrice", "", "FieldIndex"), |
213
|
|
|
("bika_setup_catalog", "getUnit", "", "FieldIndex"), |
214
|
|
|
("bika_setup_catalog", "getVATAmount", "getVATAmount", "FieldIndex"), |
215
|
|
|
("bika_setup_catalog", "getVolume", "", "FieldIndex"), |
216
|
|
|
("bika_setup_catalog", "id", "getId", "FieldIndex"), |
217
|
|
|
("bika_setup_catalog", "is_active", "", "BooleanIndex"), |
218
|
|
|
("bika_setup_catalog", "path", "getPhysicalPath", "ExtendedPathIndex"), |
219
|
|
|
("bika_setup_catalog", "portal_type", "", "FieldIndex"), |
220
|
|
|
("bika_setup_catalog", "review_state", "", "FieldIndex"), |
221
|
|
|
("bika_setup_catalog", "sortable_title", "", "FieldIndex"), |
222
|
|
|
("bika_setup_catalog", "title", "", "FieldIndex"), |
223
|
|
|
|
224
|
|
|
("portal_catalog", "Analyst", "", "FieldIndex"), |
225
|
|
|
) |
226
|
|
|
|
227
|
|
|
COLUMNS = ( |
228
|
|
|
# catalog, column name |
229
|
|
|
("bika_catalog", "path"), |
230
|
|
|
("bika_catalog", "UID"), |
231
|
|
|
("bika_catalog", "id"), |
232
|
|
|
("bika_catalog", "getId"), |
233
|
|
|
("bika_catalog", "Type"), |
234
|
|
|
("bika_catalog", "portal_type"), |
235
|
|
|
("bika_catalog", "creator"), |
236
|
|
|
("bika_catalog", "Created"), |
237
|
|
|
("bika_catalog", "Title"), |
238
|
|
|
("bika_catalog", "Description"), |
239
|
|
|
("bika_catalog", "sortable_title"), |
240
|
|
|
("bika_catalog", "getClientTitle"), |
241
|
|
|
("bika_catalog", "getClientID"), |
242
|
|
|
("bika_catalog", "getClientBatchID"), |
243
|
|
|
("bika_catalog", "getSampleTypeTitle"), |
244
|
|
|
("bika_catalog", "getDateReceived"), |
245
|
|
|
("bika_catalog", "getDateSampled"), |
246
|
|
|
("bika_catalog", "review_state"), |
247
|
|
|
|
248
|
|
|
("bika_setup_catalog", "path"), |
249
|
|
|
("bika_setup_catalog", "UID"), |
250
|
|
|
("bika_setup_catalog", "id"), |
251
|
|
|
("bika_setup_catalog", "getId"), |
252
|
|
|
("bika_setup_catalog", "Type"), |
253
|
|
|
("bika_setup_catalog", "portal_type"), |
254
|
|
|
("bika_setup_catalog", "Title"), |
255
|
|
|
("bika_setup_catalog", "Description"), |
256
|
|
|
("bika_setup_catalog", "title"), |
257
|
|
|
("bika_setup_catalog", "sortable_title"), |
258
|
|
|
("bika_setup_catalog", "description"), |
259
|
|
|
("bika_setup_catalog", "review_state"), |
260
|
|
|
("bika_setup_catalog", "getAccredited"), |
261
|
|
|
("bika_setup_catalog", "getInstrumentType"), |
262
|
|
|
("bika_setup_catalog", "getInstrumentTypeName"), |
263
|
|
|
("bika_setup_catalog", "getInstrumentLocationName"), |
264
|
|
|
("bika_setup_catalog", "getBlank"), |
265
|
|
|
("bika_setup_catalog", "getCalculationTitle"), |
266
|
|
|
("bika_setup_catalog", "getCalculationUID"), |
267
|
|
|
("bika_setup_catalog", "getCalibrationExpiryDate"), |
268
|
|
|
("bika_setup_catalog", "getCategoryTitle"), |
269
|
|
|
("bika_setup_catalog", "getCategoryUID"), |
270
|
|
|
("bika_setup_catalog", "getClientUID"), |
271
|
|
|
("bika_setup_catalog", "getDepartmentTitle"), |
272
|
|
|
("bika_setup_catalog", "getDuplicateVariation"), |
273
|
|
|
("bika_setup_catalog", "getFormula"), |
274
|
|
|
("bika_setup_catalog", "getFullname"), |
275
|
|
|
("bika_setup_catalog", "getHazardous"), |
276
|
|
|
("bika_setup_catalog", "getInstrumentTitle"), |
277
|
|
|
("bika_setup_catalog", "getKeyword"), |
278
|
|
|
("bika_setup_catalog", "getManagerName"), |
279
|
|
|
("bika_setup_catalog", "getManagerPhone"), |
280
|
|
|
("bika_setup_catalog", "getManagerEmail"), |
281
|
|
|
("bika_setup_catalog", "getMaxTimeAllowed"), |
282
|
|
|
("bika_setup_catalog", "getModel"), |
283
|
|
|
("bika_setup_catalog", "getName"), |
284
|
|
|
("bika_setup_catalog", "getPointOfCapture"), |
285
|
|
|
("bika_setup_catalog", "getPrice"), |
286
|
|
|
("bika_setup_catalog", "getSamplePointTitle"), |
287
|
|
|
("bika_setup_catalog", "getSamplePointUID"), |
288
|
|
|
("bika_setup_catalog", "getSampleTypeTitle"), |
289
|
|
|
("bika_setup_catalog", "getSampleTypeUID"), |
290
|
|
|
("bika_setup_catalog", "getServiceUID"), |
291
|
|
|
("bika_setup_catalog", "getTotalPrice"), |
292
|
|
|
("bika_setup_catalog", "getUnit"), |
293
|
|
|
("bika_setup_catalog", "getVATAmount"), |
294
|
|
|
("bika_setup_catalog", "getVolume"), |
295
|
|
|
|
296
|
|
|
("portal_catalog", "Analyst"), |
297
|
|
|
) |
298
|
|
|
|
299
|
|
|
|
300
|
|
|
def pre_install(portal_setup): |
301
|
|
|
"""Runs before the first import step of the *default* profile |
302
|
|
|
|
303
|
|
|
This handler is registered as a *pre_handler* in the generic setup profile |
304
|
|
|
|
305
|
|
|
:param portal_setup: SetupTool |
306
|
|
|
""" |
307
|
|
|
logger.info("SENAITE PRE-INSTALL handler [BEGIN]") |
308
|
|
|
|
309
|
|
|
# https://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py |
310
|
|
|
profile_id = PROFILE_ID |
311
|
|
|
|
312
|
|
|
context = portal_setup._getImportContext(profile_id) |
313
|
|
|
portal = context.getSite() # noqa |
314
|
|
|
|
315
|
|
|
logger.info("SENAITE PRE-INSTALL handler [DONE]") |
316
|
|
|
|
317
|
|
|
|
318
|
|
|
def post_install(portal_setup): |
319
|
|
|
"""Runs after the last import step of the *default* profile |
320
|
|
|
|
321
|
|
|
This handler is registered as a *post_handler* in the generic setup profile |
322
|
|
|
|
323
|
|
|
:param portal_setup: SetupTool |
324
|
|
|
""" |
325
|
|
|
logger.info("SENAITE POST-INSTALL handler [BEGIN]") |
326
|
|
|
|
327
|
|
|
# https://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py |
328
|
|
|
profile_id = PROFILE_ID |
329
|
|
|
|
330
|
|
|
context = portal_setup._getImportContext(profile_id) |
331
|
|
|
portal = context.getSite() # noqa |
332
|
|
|
|
333
|
|
|
logger.info("SENAITE POST-INSTALL handler [DONE]") |
334
|
|
|
|
335
|
|
|
|
336
|
|
|
def setup_handler(context): |
337
|
|
|
"""SENAITE setup handler |
338
|
|
|
""" |
339
|
|
|
|
340
|
|
|
if context.readDataFile("bika.lims_various.txt") is None: |
341
|
|
|
return |
342
|
|
|
|
343
|
|
|
logger.info("SENAITE setup handler [BEGIN]") |
344
|
|
|
|
345
|
|
|
portal = context.getSite() |
346
|
|
|
|
347
|
|
|
# Run Installers |
348
|
|
|
remove_default_content(portal) |
349
|
|
|
hide_navbar_items(portal) |
350
|
|
|
reindex_content_structure(portal) |
351
|
|
|
setup_groups(portal) |
352
|
|
|
setup_catalog_mappings(portal) |
353
|
|
|
setup_core_catalogs(portal) |
354
|
|
|
|
355
|
|
|
# Setting up all LIMS catalogs defined in catalog folder |
356
|
|
|
setup_catalogs(portal, getCatalogDefinitions()) |
357
|
|
|
|
358
|
|
|
# Run after all catalogs have been setup |
359
|
|
|
setup_auditlog_catalog(portal) |
360
|
|
|
|
361
|
|
|
logger.info("SENAITE setup handler [DONE]") |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
def remove_default_content(portal): |
365
|
|
|
"""Remove default Plone contents |
366
|
|
|
""" |
367
|
|
|
logger.info("*** Delete Default Content ***") |
368
|
|
|
|
369
|
|
|
# Get the list of object ids for portal |
370
|
|
|
object_ids = portal.objectIds() |
371
|
|
|
delete_ids = filter(lambda id: id in object_ids, CONTENTS_TO_DELETE) |
372
|
|
|
portal.manage_delObjects(ids=delete_ids) |
373
|
|
|
|
374
|
|
|
|
375
|
|
|
def hide_navbar_items(portal): |
376
|
|
|
"""Hide root items in navigation |
377
|
|
|
""" |
378
|
|
|
logger.info("*** Hide Navigation Items ***") |
379
|
|
|
|
380
|
|
|
# Get the list of object ids for portal |
381
|
|
|
object_ids = portal.objectIds() |
382
|
|
|
object_ids = filter(lambda id: id in object_ids, NAV_BAR_ITEMS_TO_HIDE) |
383
|
|
|
for object_id in object_ids: |
384
|
|
|
item = portal[object_id] |
385
|
|
|
item.setExcludeFromNav(True) |
386
|
|
|
item.reindexObject() |
387
|
|
|
|
388
|
|
|
|
389
|
|
|
def reindex_content_structure(portal): |
390
|
|
|
"""Reindex contents generated by Generic Setup |
391
|
|
|
""" |
392
|
|
|
logger.info("*** Reindex content structure ***") |
393
|
|
|
|
394
|
|
|
def reindex(obj, recurse=False): |
395
|
|
|
# skip catalog tools etc. |
396
|
|
|
if api.is_object(obj): |
397
|
|
|
obj.reindexObject() |
398
|
|
|
if recurse and hasattr(aq_base(obj), "objectValues"): |
399
|
|
|
map(reindex, obj.objectValues()) |
400
|
|
|
|
401
|
|
|
setup = api.get_setup() |
402
|
|
|
setupitems = setup.objectValues() |
403
|
|
|
rootitems = portal.objectValues() |
404
|
|
|
|
405
|
|
|
for obj in itertools.chain(setupitems, rootitems): |
406
|
|
|
logger.info("Reindexing {}".format(repr(obj))) |
407
|
|
|
reindex(obj) |
408
|
|
|
|
409
|
|
|
|
410
|
|
|
def setup_groups(portal): |
411
|
|
|
"""Setup roles and groups for BECHEM |
412
|
|
|
""" |
413
|
|
|
logger.info("*** Setup Roles and Groups ***") |
414
|
|
|
|
415
|
|
|
portal_groups = api.get_tool("portal_groups") |
416
|
|
|
|
417
|
|
|
for gdata in GROUPS: |
418
|
|
|
group_id = gdata["id"] |
419
|
|
|
# create the group and grant the roles |
420
|
|
|
if group_id not in portal_groups.listGroupIds(): |
421
|
|
|
logger.info("+++ Adding group {title} ({id})".format(**gdata)) |
422
|
|
|
portal_groups.addGroup(group_id, |
423
|
|
|
title=gdata["title"], |
424
|
|
|
roles=gdata["roles"]) |
425
|
|
|
# grant the roles to the existing group |
426
|
|
|
else: |
427
|
|
|
ploneapi.group.grant_roles( |
428
|
|
|
groupname=gdata["id"], |
429
|
|
|
roles=gdata["roles"],) |
430
|
|
|
logger.info("+++ Granted group {title} ({id}) the roles {roles}" |
431
|
|
|
.format(**gdata)) |
432
|
|
|
|
433
|
|
|
|
434
|
|
|
def setup_catalog_mappings(portal): |
435
|
|
|
"""Setup portal_type -> catalog mappings |
436
|
|
|
""" |
437
|
|
|
logger.info("*** Setup Catalog Mappings ***") |
438
|
|
|
|
439
|
|
|
at = api.get_tool("archetype_tool") |
440
|
|
|
for portal_type, catalogs in CATALOG_MAPPINGS: |
441
|
|
|
at.setCatalogsByType(portal_type, catalogs) |
442
|
|
|
|
443
|
|
|
|
444
|
|
|
def setup_core_catalogs(portal): |
445
|
|
|
"""Setup core catalogs |
446
|
|
|
""" |
447
|
|
|
logger.info("*** Setup Core Catalogs ***") |
448
|
|
|
|
449
|
|
|
to_reindex = [] |
450
|
|
|
for catalog, name, attribute, meta_type in INDEXES: |
451
|
|
|
c = api.get_tool(catalog) |
452
|
|
|
indexes = c.indexes() |
453
|
|
|
if name in indexes: |
454
|
|
|
logger.info("*** Index '%s' already in Catalog [SKIP]" % name) |
455
|
|
|
continue |
456
|
|
|
|
457
|
|
|
logger.info("*** Adding Index '%s' for field '%s' to catalog ..." |
458
|
|
|
% (meta_type, name)) |
459
|
|
|
|
460
|
|
|
# do we still need ZCTextIndexes? |
461
|
|
|
if meta_type == "ZCTextIndex": |
462
|
|
|
addZCTextIndex(c, name) |
463
|
|
|
else: |
464
|
|
|
c.addIndex(name, meta_type) |
465
|
|
|
|
466
|
|
|
# get the new created index |
467
|
|
|
index = c._catalog.getIndex(name) |
468
|
|
|
# set the indexed attributes |
469
|
|
|
if hasattr(index, "indexed_attrs"): |
470
|
|
|
index.indexed_attrs = [attribute or name] |
471
|
|
|
|
472
|
|
|
to_reindex.append((c, name)) |
473
|
|
|
logger.info("*** Added Index '%s' for field '%s' to catalog [DONE]" |
474
|
|
|
% (meta_type, name)) |
475
|
|
|
|
476
|
|
|
# catalog columns |
477
|
|
|
for catalog, name in COLUMNS: |
478
|
|
|
c = api.get_tool(catalog) |
479
|
|
|
if name not in c.schema(): |
480
|
|
|
logger.info("*** Adding Column '%s' to catalog '%s' ..." |
481
|
|
|
% (name, catalog)) |
482
|
|
|
c.addColumn(name) |
483
|
|
|
logger.info("*** Added Column '%s' to catalog '%s' [DONE]" |
484
|
|
|
% (name, catalog)) |
485
|
|
|
else: |
486
|
|
|
logger.info("*** Column '%s' already in catalog '%s' [SKIP]" |
487
|
|
|
% (name, catalog)) |
488
|
|
|
continue |
489
|
|
|
|
490
|
|
|
for catalog, name in to_reindex: |
491
|
|
|
logger.info("*** Indexing new index '%s' ..." % name) |
492
|
|
|
catalog.manage_reindexIndex(name) |
493
|
|
|
logger.info("*** Indexing new index '%s' [DONE]" % name) |
494
|
|
|
|
495
|
|
|
|
496
|
|
|
def setup_auditlog_catalog(portal): |
497
|
|
|
"""Setup auditlog catalog |
498
|
|
|
""" |
499
|
|
|
logger.info("*** Setup Audit Log Catalog ***") |
500
|
|
|
|
501
|
|
|
catalog_id = auditlog_catalog.CATALOG_AUDITLOG |
502
|
|
|
catalog = api.get_tool(catalog_id) |
503
|
|
|
|
504
|
|
|
for name, meta_type in auditlog_catalog._indexes.iteritems(): |
505
|
|
|
indexes = catalog.indexes() |
506
|
|
|
if name in indexes: |
507
|
|
|
logger.info("*** Index '%s' already in Catalog [SKIP]" % name) |
508
|
|
|
continue |
509
|
|
|
|
510
|
|
|
logger.info("*** Adding Index '%s' for field '%s' to catalog ..." |
511
|
|
|
% (meta_type, name)) |
512
|
|
|
|
513
|
|
|
catalog.addIndex(name, meta_type) |
514
|
|
|
|
515
|
|
|
# Setup TextIndexNG3 for listings |
516
|
|
|
# XXX is there another way to do this? |
517
|
|
|
if meta_type == "TextIndexNG3": |
518
|
|
|
index = catalog._catalog.getIndex(name) |
519
|
|
|
index.index.default_encoding = "utf-8" |
520
|
|
|
index.index.query_parser = "txng.parsers.en" |
521
|
|
|
index.index.autoexpand = "always" |
522
|
|
|
index.index.autoexpand_limit = 3 |
523
|
|
|
|
524
|
|
|
logger.info("*** Added Index '%s' for field '%s' to catalog [DONE]" |
525
|
|
|
% (meta_type, name)) |
526
|
|
|
|
527
|
|
|
# Attach the catalog to all known portal types |
528
|
|
|
at = api.get_tool("archetype_tool") |
529
|
|
|
pt = api.get_tool("portal_types") |
530
|
|
|
|
531
|
|
|
for portal_type in pt.listContentTypes(): |
532
|
|
|
catalogs = at.getCatalogsByType(portal_type) |
533
|
|
|
if catalog not in catalogs: |
534
|
|
|
new_catalogs = map(lambda c: c.getId(), catalogs) + [catalog_id] |
535
|
|
|
at.setCatalogsByType(portal_type, new_catalogs) |
536
|
|
|
logger.info("*** Adding catalog '{}' for '{}'".format( |
537
|
|
|
catalog_id, portal_type)) |
538
|
|
|
|