def guard(self, action): """Returns False if the sample is queued or contains queued analyses """ # Check if this current request life-cycle is handled by a consumer request = capi.get_request() queue_task_uid = request.get("queue_tuid", "") if capi.is_uid(queue_task_uid): ctx_id = capi.get_id(self.context) logger.info("Skip guard for {}: {}".format(ctx_id, action)) return True # Don't do anything if senaite.queue is not enabled if not api.is_queue_enabled(): return True # Check if the sample is queued if api.is_queued(self.context, status=["queued"]): return False # Check whether the sample contains queued analyses for brain in self.context.getAnalyses(): if api.is_queued(brain, status=["queued"]): return False return True
def folder_item(self, obj, item, index): # Don't do anything if senaite.queue is not enabled if not api.is_queue_enabled(): return if api.is_queued(self.context): # If the worksheet is in the queue, do not display analyses, but # those to be added and disabled if api.is_queued(obj): item["disabled"] = True else: item.clear() elif api.is_queued(obj): # Return an empty dict, so listing machinery won't render this item item.clear() return item
def guard(self, action): """Returns False if the worksheet has queued jobs """ # Don't do anything if senaite.queue is not enabled if not api.is_queue_enabled(): return True # Check if the worksheet is queued if api.is_queued(self.context, status=["queued"]): return False # Check whether this worksheet contains queued analyses for obj in self.context.getAnalyses(): if api.is_queued(obj, status=["queued"]): return False return True
def folder_item(self, obj, item, index): # Don't do anything if senaite.queue is not enabled if not api.is_queue_enabled(): return if api.is_queued(self.context): item["disabled"] = True return item
def folder_item(self, obj, item, index): # Don't do anything if senaite.queue is not enabled if not api.is_queue_enabled(): return if api.is_queued(obj): item["disabled"] = True icon = get_queue_image("queued.gif", width="55px") item["replace"]["state_title"] = _("Queued") item["replace"]["getProgressPercentage"] = icon return item
def __call__(self): # N.B. form = self.request.form analyst = self.request.get('analyst', '') template = self.request.get('template', '') instrument = self.request.get('instrument', '') if not analyst: message = _("Analyst must be specified.") self.context.plone_utils.addPortalMessage(message, 'info') self.request.RESPONSE.redirect(self.context.absolute_url()) return rc = getToolByName(self.context, REFERENCE_CATALOG) wf = getToolByName(self.context, "portal_workflow") pm = getToolByName(self.context, "portal_membership") ws = _createObjectByType("Worksheet", self.context, tmpID()) ws.processForm() # Set analyst and instrument ws.setAnalyst(analyst) if instrument: ws.setInstrument(instrument) # Set the default layout for results display ws.setResultsLayout(self.context.bika_setup.getWorksheetLayout()) # overwrite saved context UID for event subscribers self.request['context_uid'] = ws.UID() # if no template was specified, redirect to blank worksheet if not template: ws.processForm() self.request.RESPONSE.redirect(ws.absolute_url() + "/add_analyses") return wst = rc.lookupObject(template) ws.applyWorksheetTemplate(wst) if ws.getLayout(): self.request.RESPONSE.redirect(ws.absolute_url() + "/manage_results") elif api.is_queued(ws): msg = _("Analyses for {} have been queued".format(_api.get_id(ws))) self.context.plone_utils.addPortalMessage(msg) self.request.RESPONSE.redirect(_api.get_url(ws.aq_parent)) else: msg = _("No analyses were added") self.context.plone_utils.addPortalMessage(msg) self.request.RESPONSE.redirect(ws.absolute_url() + "/add_analyses")
def handle_submit(self): """Handle form submission for the assignment of a WorksheetTemplate """ wst_uid = self.request.form.get("getWorksheetTemplate") if not wst_uid: return False # Do not allow the assignment of a worksheet template when queued if api.is_queued(self.context): return False # Current context is the worksheet worksheet = self.context layout = worksheet.getLayout() # XXX For what is this used? self.request["context_uid"] = capi.get_uid(worksheet) # Apply the worksheet template to this worksheet wst = capi.get_object_by_uid(wst_uid) worksheet.applyWorksheetTemplate(wst) # Are there tasks queued for this Worksheet? if api.is_queue_enabled(): queue = api.get_queue() tasks = queue.get_tasks_for(worksheet) if tasks: return True # Maybe the queue has not been used (disabled?) new_layout = worksheet.getLayout() if len(new_layout) != len(layout): # Layout has changed. Assume the analyses were added return True return False