def workflow_script_deactivat(self): # A instance cannot be deactivated if it contains services pu = getToolByName(self, 'plone_utils') bsc = getToolByName(self, 'bika_setup_catalog') ars = bsc(portal_type='AnalysisService', getCategoryUID=self.UID()) if ars: message = _("Category cannot be deactivated because " "it contains Analysis Services") pu.addPortalMessage(message, 'error') transaction.get().abort() raise WorkflowException
def workflow_script_activate(self): wf = getToolByName(self, 'portal_workflow') pu = getToolByName(self, 'plone_utils') # A calculation cannot be re-activated if services it depends on # are deactivated. services = self.getDependentServices() inactive_services = [] for service in services: if wf.getInfoFor(service, "inactive_state") == "inactive": inactive_services.append(service.Title()) if inactive_services: msg = _("Cannot activate calculation, because the following " "service dependencies are inactive: ${inactive_services}", mapping={'inactive_services': safe_unicode(", ".join(inactive_services))}) pu.addPortalMessage(msg, 'error') transaction.get().abort() raise WorkflowException
def workflow_script_deactivate(self): bsc = getToolByName(self, 'bika_setup_catalog') pu = getToolByName(self, 'plone_utils') # A calculation cannot be deactivated if active services are using it. services = bsc(portal_type="AnalysisService", inactive_state="active") calc_services = [] for service in services: service = service.getObject() calc = service.getCalculation() if calc and calc.UID() == self.UID(): calc_services.append(service.Title()) if calc_services: msg = _('Cannot deactivate calculation, because it is in use by the ' 'following services: ${calc_services}', mapping={'calc_services': safe_unicode(", ".join(calc_services))}) pu.addPortalMessage(msg, 'error') transaction.get().abort() raise WorkflowException