def setup_control_panels(portal): """Setup Plone control and Senaite management panels """ logger.info("Setup Control panels ...") # get the bika_setup object bika_setup = api.get_bika_setup() cp = api.get_tool("portal_controlpanel") def get_action_index(action_id): if action_id == "*": action = cp.listActions()[-1] action_id = action.getId() for n, action in enumerate(cp.listActions()): if action.getId() == action_id: return n return -1 for item in CONTROL_PANELS: id = item.get("id") type = item.get("type") title = item.get("title") description = item.get("description") panel = bika_setup.get(id, None) if panel is None: logger.info("Creating Setup Folder '{}' in Setup.".format(id)) # allow content creation in setup temporary portal_types = api.get_tool("portal_types") fti = portal_types.getTypeInfo(bika_setup) fti.filter_content_types = False myfti = portal_types.getTypeInfo(type) global_allow = myfti.global_allow myfti.global_allow = True _ = bika_setup.invokeFactory(type, id, title=title) panel = bika_setup[_] myfti.global_allow = global_allow fti.filter_content_types = True else: # set some meta data panel.setTitle(title) panel.setDescription(description) # Move configlet action to the right index action_index = get_action_index(id) ref_index = get_action_index(item["insert-after"]) if (action_index != -1) and (ref_index != -1): actions = cp._cloneActions() action = actions.pop(action_index) actions.insert(ref_index + 1, action) cp._actions = tuple(actions) cp._p_changed = 1 # reindex the object to render it properly in the navigation portlet panel.reindexObject() logger.info("Setup Control panels [DONE]")
def search(self): """Search all ARs of the system """ catalog = api.get_tool("bika_catalog_analysisrequest_listing") query = { "portal_type": "AnalysisRequest", "sort_on": "created", "sort_order": "descending", } # Client? client = self.get_current_client() if client: query["getClientUID"] = api.get_uid(client) # review_state review_state = self.request.get("review_state") if review_state in REVIEW_STATE_MAP: query["review_state"] = review_state # limit limit = self.request.get("limit", "30") if limit.isdigit(): limit = int(limit) if limit > 0: query["sort_limit"] = int(limit) return catalog(query)
def update_role_mappings(portal): logger.info("Updating role mappings ...") processed = dict() for rm_query in ROLE_MAPPINGS: wf_tool = api.get_tool("portal_workflow") wf_id = rm_query[0] workflow = wf_tool.getWorkflowById(wf_id) query = rm_query[1].copy() exclude_states = [] if 'not_review_state' in query: exclude_states = query.get('not_review_state', []) del query['not_review_state'] brains = api.search(query, rm_query[2]) total = len(brains) for num, brain in enumerate(brains): if num % 100 == 0: logger.info("Updating role mappings '{0}': {1}/{2}".format( wf_id, num, total)) if api.get_uid(brain) in processed.get(wf_id, []): # Already processed, skip continue if api.get_workflow_status_of(brain) in exclude_states: # We explicitely want to exclude objs in these states continue workflow.updateRoleMappingsFor(api.get_object(brain)) if wf_id not in processed: processed[wf_id] = [] processed[wf_id].append(api.get_uid(brain)) logger.info("Updating role mappings [DONE]")
def update_workflow(workflow_id, settings): logger.info("Updating workflow '{}' ...".format(workflow_id)) wf_tool = api.get_tool("portal_workflow") workflow = wf_tool.getWorkflowById(workflow_id) if not workflow: logger.warn("Workflow '{}' not found [SKIP]".format(workflow_id)) states = settings.get("states", {}) for state_id, values in states.items(): update_workflow_state(workflow, state_id, values) transitions = settings.get("transitions", {}) for transition_id, values in transitions.items(): update_workflow_transition(workflow, transition_id, values)
def setup_catalogs(portal): """Setup Plone catalogs """ logger.info("Setup Catalogs ...") # Setup catalogs by type for type_name, catalogs in CATALOGS_BY_TYPE: at = api.get_tool("archetype_tool") # get the current registered catalogs current_catalogs = at.getCatalogsByType(type_name) # get the desired catalogs this type should be in desired_catalogs = map(api.get_tool, catalogs) # check if the catalogs changed for this portal_type if set(desired_catalogs).difference(current_catalogs): # fetch the brains to reindex brains = api.search({"portal_type": type_name}) # updated the catalogs at.setCatalogsByType(type_name, catalogs) logger.info("Assign '%s' type to Catalogs %s" % (type_name, catalogs)) for brain in brains: obj = api.get_object(brain) logger.info("Reindexing '%s'" % repr(obj)) obj.reindexObject() # Setup catalog indexes to_index = [] for catalog, name, meta_type in INDEXES: c = api.get_tool(catalog) indexes = c.indexes() if name in indexes: logger.info("Index '%s' already in Catalog [SKIP]" % name) continue logger.info("Adding Index '%s' for field '%s' to catalog '%s" % (meta_type, name, catalog)) if meta_type == "ZCTextIndex": addZCTextIndex(c, name) else: c.addIndex(name, meta_type) to_index.append((c, name)) logger.info("Added Index '%s' for field '%s' to catalog [DONE]" % (meta_type, name)) for catalog, name in to_index: logger.info("Indexing new index '%s' ..." % name) catalog.manage_reindexIndex(name) logger.info("Indexing new index '%s' [DONE]" % name) # Setup catalog metadata columns for catalog, name in COLUMNS: c = api.get_tool(catalog) if name not in c.schema(): logger.info("Adding Column '%s' to catalog '%s' ..." % (name, catalog)) c.addColumn(name) logger.info("Added Column '%s' to catalog '%s' [DONE]" % (name, catalog)) else: logger.info("Column '%s' already in catalog '%s' [SKIP]" % (name, catalog)) continue logger.info("Setup Catalogs [DONE]")