def folderitem(self, obj, item, index): """ :obj: is a brain """ # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) item['getDateReceived'] = self.ulocalized_time(obj.getDateReceived) DueDate = obj.getDueDate item['getDueDate'] = self.ulocalized_time(DueDate) if DueDate < DateTime(): item['after']['DueDate'] = '<img width="16" height="16"' ' src="%s/++resource++bika.lims.images/late.png" title="%s"/>' % \ (self.context.absolute_url(), t(_("Late Analysis"))) if self.hideclientlink: del item['replace']['Client'] # Add Priority column priority_sort_key = obj.getPrioritySortkey if not priority_sort_key: # Default priority is Medium = 3. # The format of PrioritySortKey is <priority>.<created> priority_sort_key = '3.%s' % obj.created.ISO8601() priority = priority_sort_key.split('.')[0] priority_text = PRIORITIES.getValue(priority) priority_div = '<div class="priority-ico priority-%s"><span class="notext">%s</span><div>' item['replace']['Priority'] = priority_div % (priority, priority_text) return item
def folderitem(self, obj, item, index): # Additional info from AnalysisRequest to be added in the item generated # by default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None member = self.mtool.getAuthenticatedMember() roles = member.getRoles() hideclientlink = 'RegulatoryInspector' in roles \ and 'Manager' not in roles \ and 'LabManager' not in roles \ and 'LabClerk' not in roles sample = obj.getSample() url = obj.absolute_url() if getSecurityManager().checkPermission(EditResults, obj): url += "/manage_results" item['Client'] = obj.aq_parent.Title() if (hideclientlink == False): item['replace']['Client'] = "<a href='%s'>%s</a>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) item['Creator'] = self.user_fullname(obj.Creator()) item['getRequestID'] = obj.getRequestID() item['replace']['getRequestID'] = "<a href='%s'>%s</a>" % \ (url, item['getRequestID']) item['getSample'] = sample item['replace']['getSample'] = \ "<a href='%s'>%s</a>" % (sample.absolute_url(), sample.Title()) item['replace']['getProfilesTitle'] = ", ".join( [p.Title() for p in obj.getProfiles()]) analysesnum = obj.getAnalysesNum() if analysesnum: item['getAnalysesNum'] = str(analysesnum[0]) + '/' + str(analysesnum[1]) else: item['getAnalysesNum'] = '' batch = obj.getBatch() if batch: item['BatchID'] = batch.getBatchID() item['replace']['BatchID'] = "<a href='%s'>%s</a>" % \ (batch.absolute_url(), item['BatchID']) else: item['BatchID'] = '' val = obj.Schema().getField('SubGroup').get(obj) item['SubGroup'] = val.Title() if val else '' samplingdate = obj.getSample().getSamplingDate() item['SamplingDate'] = self.ulocalized_time(samplingdate, long_format=1) item['getDateReceived'] = self.ulocalized_time(obj.getDateReceived()) item['getDatePublished'] = self.ulocalized_time(obj.getDatePublished()) items[x]['getDateVerified'] = getTransitionDate(obj, 'verify')
def folderitem(self, obj, item, index): item = BikaListingView.folderitem(self, obj, item, index) # https://github.com/collective/uwosh.pfg.d2c/issues/20 # https://github.com/collective/uwosh.pfg.d2c/pull/21 item['replace']['Title'] = \ "<a href='%s/ReportFile'>%s</a>" % \ (item['url'], item['Title']) item['replace']['created'] = self.ulocalized_time(item['created']) return item
def folderitem(self, obj, item, index): item = BikaListingView.folderitem(self, obj, item, index) # https://github.com/collective/uwosh.pfg.d2c/issues/20 # https://github.com/collective/uwosh.pfg.d2c/pull/21 item['replace']['Title'] = \ "<a href='%s/ReportFile'>%s</a>" % \ (item['url'], item['Title']) item['replace']['created'] = self.ulocalized_time(item['created']) return item
def folderitem(self, obj, item, index): """ :obj: is a worksheet brain. """ # Additional info from Worksheet to be added in the item generated by # default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) item['CreationDate'] = self.ulocalized_time(obj.created) if len(obj.getAnalysesUIDs) == 0: item['table_row_class'] = 'state-empty-worksheet' layout = obj.getLayout item['Title'] = obj.Title turl = "manage_results" if len(layout) > 0 else "add_analyses" item['replace']['Title'] = "<a href='%s/%s'>%s</a>" % \ (item['url'], turl, item['Title']) pos_parent = {} for slot in layout: # compensate for bad data caused by a stupid bug. if type(slot['position']) in (list, tuple): slot['position'] = slot['position'][0] if slot['position'] == 'new': continue if slot['position'] in pos_parent: continue pos_parent[slot['position']] =\ self.rc.lookupObject(slot.get('container_uid')) # Total QC Analyses item['NumQCAnalyses'] = str(obj.getNumberOfQCAnalyses) # Total Routine Analyses item['NumRegularAnalyses'] = str(obj.getNumberOfRegularAnalyses) # Total Number of Samples item['NumRegularSamples'] = str(obj.getNumberOfRegularSamples) if item['review_state'] == 'open' \ and self.allow_edit \ and not self.restrict_results \ and self.can_manage: item['Analyst'] = obj.getAnalyst item['allow_edit'] = [ 'Analyst', ] item['required'] = [ 'Analyst', ] item['choices'] = {'Analyst': self.analyst_choices} self.can_reassign = True else: item['Analyst'] = user_fullname(self.context, obj.getAnalyst) return item
def folderitem(self, obj, item, index): """ :obj: is a worksheet brain. """ # Additional info from Worksheet to be added in the item generated by # default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) item['CreationDate'] = self.ulocalized_time(obj.created) if len(obj.getAnalysesUIDs) == 0: item['table_row_class'] = 'state-empty-worksheet' layout = obj.getLayout item['Title'] = obj.Title turl = "manage_results" if len(layout) > 0 else "add_analyses" item['replace']['Title'] = "<a href='%s/%s'>%s</a>" % \ (item['url'], turl, item['Title']) pos_parent = {} for slot in layout: # compensate for bad data caused by a stupid bug. if type(slot['position']) in (list, tuple): slot['position'] = slot['position'][0] if slot['position'] == 'new': continue if slot['position'] in pos_parent: continue pos_parent[slot['position']] =\ self.rc.lookupObject(slot.get('container_uid')) # Total QC Analyses item['NumQCAnalyses'] = str(obj.getNumberOfQCAnalyses) # Total Routine Analyses item['NumRegularAnalyses'] = str(obj.getNumberOfRegularAnalyses) # Total Number of Samples item['NumRegularSamples'] = str(obj.getNumberOfRegularSamples) if item['review_state'] == 'open' \ and self.allow_edit \ and not self.restrict_results \ and self.can_manage: item['Analyst'] = obj.getAnalyst item['allow_edit'] = ['Analyst', ] item['required'] = ['Analyst', ] item['choices'] = {'Analyst': self.analyst_choices} self.can_reassign = True else: item['Analyst'] = user_fullname(self.context, obj.getAnalyst) return item
def folderitem(self, obj, item, index): # Additional info from Worksheet to be added in the item generated by # default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None item['CreationDate'] = self.ulocalized_time(obj.creation_date) item['Analyst'] = obj.getAnalyst().strip() item['Priority'] = '' item['getPriority'] = '' instrument = obj.getInstrument() item['Instrument'] = instrument.Title() if instrument else '' wst = obj.getWorksheetTemplate() item['Template'] = wst.Title() if wst else '' if wst: item['replace']['Template'] = "<a href='%s'>%s</a>" % \ (wst.absolute_url(), wst.Title()) if len(obj.getAnalyses()) == 0: item['table_row_class'] = 'state-empty-worksheet' layout = obj.getLayout() item['Title'] = obj.Title() turl = "manage_results" if len(layout) > 0 else "add_analyses" item['replace']['Title'] = "<a href='%s/%s'>%s</a>" % \ (item['url'], turl, item['Title']) # Set services ws_services = {} for slot in [s for s in layout if s['type'] == 'a']: analysis = self.rc.lookupObject(slot['analysis_uid']) if not analysis: error = "Analysis with uid '%s' NOT FOUND in Reference Catalog.\n Worksheet: '%s'. Layout: '%s'" % \ (slot['analysis_uid'], obj, layout) logging.info(error) continue service = analysis.getService() title = service.Title() if title not in ws_services: ws_services[title] = "<a href='%s'>%s</a>" % \ (service.absolute_url(), title) keys = list(ws_services.keys()) keys.sort() services = [ws_services[k] for k in keys] item['Services'] = "" item['replace']['Services'] = ", ".join(services) pos_parent = {} for slot in layout: # compensate for bad data caused by a stupid bug. if type(slot['position']) in (list, tuple): slot['position'] = slot['position'][0] if slot['position'] == 'new': continue if slot['position'] in pos_parent: continue pos_parent[slot['position']] = self.rc.lookupObject(slot['container_uid']) # Set Sample Types and QC Samples sampletypes = [] qcsamples = [] for container in pos_parent.values(): if container.portal_type == 'AnalysisRequest': sampletype = "<a href='%s'>%s</a>" % \ (container.getSample().getSampleType().absolute_url(), container.getSample().getSampleType().Title()) sampletypes.append(sampletype) if container.portal_type == 'ReferenceSample': qcsample = "<a href='%s'>%s</a>" % \ (container.absolute_url(), container.Title()) qcsamples.append(qcsample) sampletypes = list(set(sampletypes)) sampletypes.sort() item['SampleTypes'] = "" item['replace']['SampleTypes'] = ", ".join(sampletypes) qcsamples = list(set(qcsamples)) qcsamples.sort() item['QC'] = "" item['replace']['QC'] = ", ".join(qcsamples) item['QCTotals'] = '' # Total QC Samples (Total Routine Analyses) analyses = obj.getAnalyses() totalQCAnalyses = [a for a in analyses if a.portal_type == 'ReferenceAnalysis' or a.portal_type == 'DuplicateAnalysis'] totalQCSamples = [a.getSample().UID() for a in totalQCAnalyses] totalQCSamples = list(set(totalQCSamples)) item['QCTotals'] = str(len(totalQCSamples)) + ' (' + str(len(totalQCAnalyses)) + ')' # Total Routine Samples (Total Routine Analyses) totalRoutineAnalyses = [a for a in analyses if a not in totalQCAnalyses] totalRoutineSamples = [a.getSample().UID() for a in totalRoutineAnalyses] totalRoutineSamples = list(set(totalRoutineSamples)) item['RoutineTotals'] = str(len(totalRoutineSamples)) + ' (' + str(len(totalRoutineAnalyses)) + ')' if item['review_state'] == 'open' \ and self.allow_edit \ and self.restrict_results == False \ and self.can_manage == True: item['allow_edit'] = ['Analyst', ] item['required'] = ['Analyst', ] item['choices'] = {'Analyst': self.analyst_choices} self.can_reassign = True return item
def folderitem(self, obj, item, index): # Additional info from Worksheet to be added in the item generated by # default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None item['CreationDate'] = self.ulocalized_time(obj.creation_date) item['Analyst'] = obj.getAnalyst().strip() item['Priority'] = '' item['getPriority'] = '' instrument = obj.getInstrument() item['Instrument'] = instrument.Title() if instrument else '' wst = obj.getWorksheetTemplate() item['Template'] = wst.Title() if wst else '' if wst: item['replace']['Template'] = "<a href='%s'>%s</a>" % \ (wst.absolute_url(), wst.Title()) if len(obj.getAnalyses()) == 0: item['table_row_class'] = 'state-empty-worksheet' layout = obj.getLayout() item['Title'] = obj.Title() turl = "manage_results" if len(layout) > 0 else "add_analyses" item['replace']['Title'] = "<a href='%s/%s'>%s</a>" % \ (item['url'], turl, item['Title']) # Set services ws_services = {} for slot in [s for s in layout if s['type'] == 'a']: analysis = self.rc.lookupObject(slot['analysis_uid']) if not analysis: error = "Analysis with uid '%s' NOT FOUND in Reference Catalog.\n Worksheet: '%s'. Layout: '%s'" % \ (slot['analysis_uid'], obj, layout) logging.info(error) continue service = analysis.getService() title = service.Title() if title not in ws_services: ws_services[title] = "<a href='%s'>%s</a>" % \ (service.absolute_url(), title) keys = list(ws_services.keys()) keys.sort() services = [ws_services[k] for k in keys] item['Services'] = "" item['replace']['Services'] = ", ".join(services) pos_parent = {} for slot in layout: # compensate for bad data caused by a stupid bug. if type(slot['position']) in (list, tuple): slot['position'] = slot['position'][0] if slot['position'] == 'new': continue if slot['position'] in pos_parent: continue pos_parent[slot['position']] = self.rc.lookupObject( slot['container_uid']) # Set Sample Types and QC Samples sampletypes = [] qcsamples = [] for container in pos_parent.values(): if container.portal_type == 'AnalysisRequest': sampletype = "<a href='%s'>%s</a>" % \ (container.getSample().getSampleType().absolute_url(), container.getSample().getSampleType().Title()) sampletypes.append(sampletype) if container.portal_type == 'ReferenceSample': qcsample = "<a href='%s'>%s</a>" % \ (container.absolute_url(), container.Title()) qcsamples.append(qcsample) sampletypes = list(set(sampletypes)) sampletypes.sort() item['SampleTypes'] = "" item['replace']['SampleTypes'] = ", ".join(sampletypes) qcsamples = list(set(qcsamples)) qcsamples.sort() item['QC'] = "" item['replace']['QC'] = ", ".join(qcsamples) item['QCTotals'] = '' # Total QC Samples (Total Routine Analyses) analyses = obj.getAnalyses() totalQCAnalyses = [ a for a in analyses if a.portal_type == 'ReferenceAnalysis' or a.portal_type == 'DuplicateAnalysis' ] totalQCSamples = [a.getSample().UID() for a in totalQCAnalyses] totalQCSamples = list(set(totalQCSamples)) item['QCTotals'] = str(len(totalQCSamples)) + ' (' + str( len(totalQCAnalyses)) + ')' # Total Routine Samples (Total Routine Analyses) totalRoutineAnalyses = [ a for a in analyses if a not in totalQCAnalyses ] totalRoutineSamples = [ a.getSample().UID() for a in totalRoutineAnalyses ] totalRoutineSamples = list(set(totalRoutineSamples)) item['RoutineTotals'] = str(len(totalRoutineSamples)) + ' (' + str( len(totalRoutineAnalyses)) + ')' if item['review_state'] == 'open' \ and self.allow_edit \ and self.restrict_results == False \ and self.can_manage == True: item['allow_edit'] = [ 'Analyst', ] item['required'] = [ 'Analyst', ] item['choices'] = {'Analyst': self.analyst_choices} self.can_reassign = True return item
def folderitem(self, obj, item, index): # Additional info from AnalysisRequest to be added in the item # generated by default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None # This variable will contain the full analysis request if there is # need to work with the full object instead of the brain full_object = None item["Creator"] = self.user_fullname(obj.Creator) # If we redirect from the folderitems view we should check if the # user has permissions to medify the element or not. priority_sort_key = obj.getPrioritySortkey if not priority_sort_key: # Default priority is Medium = 3. # The format of PrioritySortKey is <priority>.<created> priority_sort_key = "3.%s" % obj.created.ISO8601() priority = priority_sort_key.split(".")[0] priority_text = PRIORITIES.getValue(priority) priority_div = """<div class="priority-ico priority-%s"> <span class="notext">%s</span><div> """ item["replace"]["Priority"] = priority_div % (priority, priority_text) item["replace"]["getProfilesTitle"] = obj.getProfilesTitleStr analysesnum = obj.getAnalysesNum if analysesnum: num_verified = str(analysesnum[0]) num_total = str(analysesnum[1]) item["getAnalysesNum"] = "{0}/{1}".format(num_verified, num_total) else: item["getAnalysesNum"] = "" # Progress progress_perc = self.get_progress_percentage(obj) item["replace"]["Progress"] = get_progress_bar_html(progress_perc) item["BatchID"] = obj.getBatchID if obj.getBatchID: item['replace']['BatchID'] = "<a href='%s'>%s</a>" % \ (obj.getBatchURL, obj.getBatchID) # TODO: SubGroup ??? # val = obj.Schema().getField('SubGroup').get(obj) # item['SubGroup'] = val.Title() if val else '' date = obj.getSamplingDate item["SamplingDate"] = \ self.ulocalized_time(date, long_format=1) if date else "" date = obj.getDateReceived item["getDateReceived"] = \ self.ulocalized_time(date, long_format=1) if date else "" date = obj.getDueDate item["getDueDate"] = \ self.ulocalized_time(date, long_format=1) if date else "" date = obj.getDatePublished item["getDatePublished"] = \ self.ulocalized_time(date, long_format=1) if date else "" date = obj.getDateVerified item["getDateVerified"] = \ self.ulocalized_time(date, long_format=1) if date else "" if self.printwfenabled: item["Printed"] = "" printed = obj.getPrinted if hasattr(obj, "getPrinted") else "0" print_icon = "" if printed == "0": print_icon = get_image("delete.png", title=t(_("Not printed yet"))) elif printed == "1": print_icon = get_image("ok.png", title=t(_("Printed"))) elif printed == "2": print_icon = get_image("exclamation.png", title=t( _("Republished after last print"))) item["after"]["Printed"] = print_icon item["SamplingDeviation"] = obj.getSamplingDeviationTitle item["getStorageLocation"] = obj.getStorageLocationTitle after_icons = "" # Getting a dictionary with each workflow id and current state in it states_dict = obj.getObjectWorkflowStates if obj.assigned_state == 'assigned': after_icons += get_image("worksheet.png", title=t(_("All analyses assigned"))) if states_dict.get('review_state', '') == 'invalid': after_icons += get_image("delete.png", title=t(_("Results have been withdrawn"))) due_date = obj.getDueDate if due_date and due_date < (obj.getDatePublished or DateTime()): due_date_str = self.ulocalized_time(due_date) img_title = "{}: {}".format(t(_("Late Analyses")), due_date_str) after_icons += get_image("late.png", title=img_title) if obj.getSamplingDate and obj.getSamplingDate > DateTime(): after_icons += get_image("calendar.png", title=t(_("Future dated sample"))) if obj.getInvoiceExclude: after_icons += get_image("invoice_exclude.png", title=t(_("Exclude from invoice"))) if obj.getHazardous: after_icons += get_image("hazardous.png", title=t(_("Hazardous"))) if obj.getInternalUse: after_icons += get_image("locked.png", title=t(_("Internal use"))) if after_icons: item['after']['getId'] = after_icons item['Created'] = self.ulocalized_time(obj.created, long_format=1) if obj.getContactUID: item['ClientContact'] = obj.getContactFullName item['replace']['ClientContact'] = "<a href='%s'>%s</a>" % \ (obj.getContactURL, obj.getContactFullName) else: item["ClientContact"] = "" # TODO-performance: If SamplingWorkflowEnabled, we have to get the # full object to check the user permissions, so far this is # a performance hit. if obj.getSamplingWorkflowEnabled: # We don't do anything with Sampling Date. # User can modify Sampling date # inside AR view. In this listing view, # we only let the user to edit Date Sampled # and Sampler if he wants to make 'sample' transaction. if not obj.getDateSampled: datesampled = self.ulocalized_time(DateTime(), long_format=True) item["class"]["getDateSampled"] = "provisional" else: datesampled = self.ulocalized_time(obj.getDateSampled, long_format=True) sampler = obj.getSampler if sampler: item["replace"]["getSampler"] = obj.getSamplerFullName if "Sampler" in self.roles and not sampler: sampler = self.member.id item["class"]["getSampler"] = "provisional" # sampling workflow - inline edits for Sampler and Date Sampled if states_dict.get('review_state', '') == 'to_be_sampled': # We need to get the full object in order to check # the permissions full_object = obj.getObject() checkPermission =\ self.context.portal_membership.checkPermission # TODO Do we really need this check? if checkPermission(TransitionSampleSample, full_object): item["required"] = ["getSampler", "getDateSampled"] item["allow_edit"] = ["getSampler", "getDateSampled"] # TODO-performance: hit performance while getting the # sample object... # TODO Can LabManagers be a Sampler?! samplers = getUsers(full_object, [ "Sampler", ]) username = self.member.getUserName() users = [({ "ResultValue": u, "ResultText": samplers.getValue(u) }) for u in samplers] item['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' sampler = Sampler else: datesampled = self.ulocalized_time(obj.getDateSampled, long_format=True) sampler = obj.getSamplerFullName if obj.getSampler else '' else: datesampled = self.ulocalized_time(obj.getDateSampled, long_format=True) sampler = "" item["getDateSampled"] = datesampled item["getSampler"] = sampler # These don't exist on ARs # XXX This should be a list of preservers... item["getPreserver"] = "" item["getDatePreserved"] = "" # Advanced partitioning # append the UID of the primary AR as parent item["parent"] = obj.getRawParentAnalysisRequest or "" # append partition UIDs of this AR as children item["children"] = [] if self.show_partitions: item["children"] = obj.getDescendantsUIDs or [] return item
def folderitem(self, obj, item, index): # Additional info from AnalysisRequest to be added in the item generated # by default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None member = self.mtool.getAuthenticatedMember() roles = member.getRoles() hideclientlink = 'RegulatoryInspector' in roles \ and 'Manager' not in roles \ and 'LabManager' not in roles \ and 'LabClerk' not in roles sample = obj.getSample() url = obj.absolute_url() if getSecurityManager().checkPermission(EditResults, obj): url += "/manage_results" item['Client'] = obj.aq_parent.Title() if (hideclientlink == False): item['replace']['Client'] = "<a href='%s'>%s</a>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) item['Creator'] = self.user_fullname(obj.Creator()) item['getRequestID'] = obj.getRequestID() item['replace']['getRequestID'] = "<a href='%s'>%s</a>" % \ (url, item['getRequestID']) item['getSample'] = sample item['replace']['getSample'] = \ "<a href='%s'>%s</a>" % (sample.absolute_url(), sample.Title()) item['replace']['getProfilesTitle'] = ", ".join( [p.Title() for p in obj.getProfiles()]) analysesnum = obj.getAnalysesNum() if analysesnum: item['getAnalysesNum'] = str(analysesnum[0]) + '/' + str( analysesnum[1]) else: item['getAnalysesNum'] = '' batch = obj.getBatch() if batch: item['BatchID'] = batch.getBatchID() item['replace']['BatchID'] = "<a href='%s'>%s</a>" % \ (batch.absolute_url(), item['BatchID']) else: item['BatchID'] = '' val = obj.Schema().getField('SubGroup').get(obj) item['SubGroup'] = val.Title() if val else '' sd = obj.getSample().getSamplingDate() item['SamplingDate'] = \ self.ulocalized_time(sd, long_format=1) if sd else '' item['getDateReceived'] = \ self.ulocalized_time(obj.getDateReceived()) item['getDatePublished'] = \ self.ulocalized_time(getTransitionDate(obj, 'publish')) item['getDateVerified'] = \ self.ulocalized_time(getTransitionDate(obj, 'verify')) deviation = sample.getSamplingDeviation() item['SamplingDeviation'] = deviation and deviation.Title() or '' priority = obj.getPriority() item['Priority'] = '' # priority.Title() item['getStorageLocation'] = sample.getStorageLocation( ) and sample.getStorageLocation().Title() or '' item['AdHoc'] = sample.getAdHoc() and True or '' after_icons = "" state = self.workflow.getInfoFor(obj, 'worksheetanalysis_review_state') if state == 'assigned': after_icons += "<img src='%s/++resource++bika.lims.images/worksheet.png' title='%s'/>" % \ (self.portal_url, t(_("All analyses assigned"))) if self.workflow.getInfoFor(obj, 'review_state') == 'invalid': after_icons += "<img src='%s/++resource++bika.lims.images/delete.png' title='%s'/>" % \ (self.portal_url, t(_("Results have been withdrawn"))) if obj.getLate(): after_icons += "<img src='%s/++resource++bika.lims.images/late.png' title='%s'>" % \ (self.portal_url, t(_("Late Analyses"))) if sd and sd > DateTime(): after_icons += "<img src='%s/++resource++bika.lims.images/calendar.png' title='%s'>" % \ (self.portal_url, t(_("Future dated sample"))) if obj.getInvoiceExclude(): after_icons += "<img src='%s/++resource++bika.lims.images/invoice_exclude.png' title='%s'>" % \ (self.portal_url, t(_("Exclude from invoice"))) if sample.getSampleType().getHazardous(): after_icons += "<img src='%s/++resource++bika.lims.images/hazardous.png' title='%s'>" % \ (self.portal_url, t(_("Hazardous"))) if after_icons: item['after']['getRequestID'] = after_icons item['Created'] = self.ulocalized_time(obj.created()) contact = obj.getContact() if contact: item['ClientContact'] = contact.Title() item['replace']['ClientContact'] = "<a href='%s'>%s</a>" % \ (contact.absolute_url(), contact.Title()) else: item['ClientContact'] = "" SamplingWorkflowEnabled = sample.getSamplingWorkflowEnabled() if SamplingWorkflowEnabled and (not sd or not sd > DateTime()): datesampled = self.ulocalized_time(sample.getDateSampled(), long_format=True) if not datesampled: datesampled = self.ulocalized_time(DateTime(), long_format=True) item['class']['getDateSampled'] = 'provisional' sampler = sample.getSampler().strip() if sampler: item['replace']['getSampler'] = self.user_fullname(sampler) if 'Sampler' in member.getRoles() and not sampler: sampler = member.id item['class']['getSampler'] = 'provisional' else: datesampled = '' sampler = '' item['getDateSampled'] = datesampled item['getSampler'] = sampler # sampling workflow - inline edits for Sampler and Date Sampled checkPermission = self.context.portal_membership.checkPermission state = self.workflow.getInfoFor(obj, 'review_state') if state == 'to_be_sampled' \ and checkPermission(SampleSample, obj) \ and (not sd or not sd > DateTime()): item['required'] = ['getSampler', 'getDateSampled'] item['allow_edit'] = ['getSampler', 'getDateSampled'] samplers = getUsers(sample, ['Sampler', 'LabManager', 'Manager']) username = member.getUserName() users = [({ 'ResultValue': u, 'ResultText': samplers.getValue(u) }) for u in samplers] item['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' item['getSampler'] = Sampler # These don't exist on ARs # XXX This should be a list of preservers... item['getPreserver'] = '' item['getDatePreserved'] = '' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, obj): item['required'] = ['getPreserver', 'getDatePreserved'] item['allow_edit'] = ['getPreserver', 'getDatePreserved'] preservers = getUsers(obj, ['Preserver', 'LabManager', 'Manager']) username = member.getUserName() users = [({ 'ResultValue': u, 'ResultText': preservers.getValue(u) }) for u in preservers] item['choices'] = {'getPreserver': users} preserver = username in preservers.keys() and username or '' item['getPreserver'] = preserver item['getDatePreserved'] = self.ulocalized_time(DateTime(), long_format=1) item['class']['getPreserver'] = 'provisional' item['class']['getDatePreserved'] = 'provisional' # Submitting user may not verify results if item['review_state'] == 'to_be_verified': username = member.getUserName() allowed = api.user.has_permission(VerifyPermission, username=username) if allowed and not obj.isUserAllowedToVerify(member): item['after']['state_title'] = \ "<img src='++resource++bika.lims.images/submitted-by-current-user.png' title='%s'/>" % \ t(_("Cannot verify: Submitted by current user")) return item
def folderitem(self, obj, item, index): # Additional info from AnalysisRequest to be added in the item # generated by default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None # This variable will contain the full analysis request if there is # need to work with the full object instead of the brain full_object = None item["Creator"] = self.user_fullname(obj.Creator) # If we redirect from the folderitems view we should check if the # user has permissions to medify the element or not. priority_sort_key = obj.getPrioritySortkey if not priority_sort_key: # Default priority is Medium = 3. # The format of PrioritySortKey is <priority>.<created> priority_sort_key = "3.%s" % obj.created.ISO8601() priority = priority_sort_key.split(".")[0] priority_text = PRIORITIES.getValue(priority) priority_div = """<div class="priority-ico priority-%s"> <span class="notext">%s</span><div> """ item["replace"]["Priority"] = priority_div % (priority, priority_text) item["replace"]["getProfilesTitle"] = obj.getProfilesTitleStr analysesnum = obj.getAnalysesNum if analysesnum: num_verified = str(analysesnum[0]) num_total = str(analysesnum[1]) item["getAnalysesNum"] = "{0}/{1}".format(num_verified, num_total) else: item["getAnalysesNum"] = "" # Progress num_verified = 0 num_submitted = 0 num_total = 0 if analysesnum and len(analysesnum) > 1: num_verified = analysesnum[0] num_total = analysesnum[1] num_submitted = num_total - num_verified if len(analysesnum) > 2: num_wo_results = analysesnum[2] num_submitted = num_total - num_verified - num_wo_results num_steps_total = num_total * 2 num_steps = (num_verified * 2) + (num_submitted) progress_perc = 0 if num_steps > 0 and num_steps_total > 0: progress_perc = (num_steps * 100) / num_steps_total progress = '<div class="progress-bar-container">' + \ '<div class="progress-bar" style="width:{0}%"></div>' + \ '<div class="progress-perc">{0}%</div></div>' item["replace"]["Progress"] = progress.format(progress_perc) item["BatchID"] = obj.getBatchID if obj.getBatchID: item['replace']['BatchID'] = "<a href='%s'>%s</a>" % \ (obj.getBatchURL, obj.getBatchID) # TODO: SubGroup ??? # val = obj.Schema().getField('SubGroup').get(obj) # item['SubGroup'] = val.Title() if val else '' date = obj.getSamplingDate item["SamplingDate"] = \ self.ulocalized_time(date, long_format=1) if date else "" date = obj.getDateReceived item["getDateReceived"] = \ self.ulocalized_time(date, long_format=1) if date else "" date = obj.getDatePublished item["getDatePublished"] = \ self.ulocalized_time(date, long_format=1) if date else "" date = obj.getDateVerified item["getDateVerified"] = \ self.ulocalized_time(date, long_format=1) if date else "" if self.printwfenabled: item["Printed"] = "" printed = obj.getPrinted if hasattr(obj, "getPrinted") else "0" print_icon = "" if printed == "0": print_icon = \ """<img src='%s/++resource++bika.lims.images/delete.png' title='%s'> """ % (self.portal_url, t(_("Not printed yet"))) elif printed == "1": print_icon = \ """<img src='%s/++resource++bika.lims.images/ok.png' title='%s'> """ % (self.portal_url, t(_("Printed"))) elif printed == "2": print_icon = \ """<img src='%s/++resource++bika.lims.images/exclamation.png' title='%s'> """ \ % (self.portal_url, t(_("Republished after last print"))) item["after"]["Printed"] = print_icon item["SamplingDeviation"] = obj.getSamplingDeviationTitle item["getStorageLocation"] = obj.getStorageLocationTitle after_icons = "" # Getting a dictionary with each workflow id and current state in it states_dict = obj.getObjectWorkflowStates if obj.assigned_state == 'assigned': after_icons += \ """<img src='%s/++resource++bika.lims.images/worksheet.png' title='%s'/> """ % (self.portal_url, t(_("All analyses assigned"))) if states_dict.get('review_state', '') == 'invalid': after_icons += \ """<img src='%s/++resource++bika.lims.images/delete.png' title='%s'/> """ % (self.portal_url, t(_("Results have been withdrawn"))) if obj.getLate: after_icons += \ """<img src='%s/++resource++bika.lims.images/late.png' title='%s'> """ % (self.portal_url, t(_("Late Analyses"))) if obj.getSamplingDate and obj.getSamplingDate > DateTime(): after_icons += \ """<img src='%s/++resource++bika.lims.images/calendar.png' title='%s'> """ % (self.portal_url, t(_("Future dated sample"))) if obj.getInvoiceExclude: after_icons += \ """<img src='%s/++resource++bika.lims.images/invoice_exclude.png' title='%s'> """ % (self.portal_url, t(_("Exclude from invoice"))) if obj.getHazardous: after_icons += \ """<img src='%s/++resource++bika.lims.images/hazardous.png' title='%s'> """ % (self.portal_url, t(_("Hazardous"))) if after_icons: item['after']['getId'] = after_icons item['Created'] = self.ulocalized_time(obj.created, long_format=1) if obj.getContactUID: item['ClientContact'] = obj.getContactFullName item['replace']['ClientContact'] = "<a href='%s'>%s</a>" % \ (obj.getContactURL, obj.getContactFullName) else: item["ClientContact"] = "" # TODO-performance: If SamplingWorkflowEnabled, we have to get the # full object to check the user permissions, so far this is # a performance hit. if obj.getSamplingWorkflowEnabled: # We don't do anything with Sampling Date. # User can modify Sampling date # inside AR view. In this listing view, # we only let the user to edit Date Sampled # and Sampler if he wants to make 'sample' transaction. if not obj.getDateSampled: datesampled = self.ulocalized_time(DateTime(), long_format=True) item["class"]["getDateSampled"] = "provisional" else: datesampled = self.ulocalized_time(obj.getDateSampled, long_format=True) sampler = obj.getSampler if sampler: item["replace"]["getSampler"] = obj.getSamplerFullName if "Sampler" in self.roles and not sampler: sampler = self.member.id item["class"]["getSampler"] = "provisional" # sampling workflow - inline edits for Sampler and Date Sampled if states_dict.get('review_state', '') == 'to_be_sampled': # We need to get the full object in order to check # the permissions full_object = obj.getObject() checkPermission =\ self.context.portal_membership.checkPermission if checkPermission(SampleSample, full_object): item["required"] = ["getSampler", "getDateSampled"] item["allow_edit"] = ["getSampler", "getDateSampled"] # TODO-performance: hit performance while getting the # sample object... # TODO Can LabManagers be a Sampler?! samplers = getUsers(full_object.getSample(), [ "Sampler", ]) username = self.member.getUserName() users = [({ "ResultValue": u, "ResultText": samplers.getValue(u) }) for u in samplers] item['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' sampler = Sampler else: datesampled = self.ulocalized_time(obj.getDateSampled, long_format=True) sampler = obj.getSamplerFullName if obj.getSampler else '' else: datesampled = self.ulocalized_time(obj.getDateSampled, long_format=True) sampler = "" item["getDateSampled"] = datesampled item["getSampler"] = sampler # These don't exist on ARs # XXX This should be a list of preservers... item["getPreserver"] = "" item["getDatePreserved"] = "" # TODO-performance: If inline preservation wants to be used, we # have to get the full object to check the user permissions, so # far this is a performance hit. # inline edits for Preserver and Date Preserved # if checkPermission(PreserveSample, obj): # item['required'] = ['getPreserver', 'getDatePreserved'] # item['allow_edit'] = ['getPreserver', 'getDatePreserved'] # preservers = getUsers(obj, ['Preserver', # 'LabManager', 'Manager']) # username = self.member.getUserName() # users = [({'ResultValue': u, # 'ResultText': preservers.getValue(u)}) # for u in preservers] # item['choices'] = {'getPreserver': users} # preserver = username in preservers.keys() and username or '' # item['getPreserver'] = preserver # item['getDatePreserved'] = self.ulocalized_time( # DateTime(), # long_format=1) # item['class']['getPreserver'] = 'provisional' # item['class']['getDatePreserved'] = 'provisional' # Submitting user may not verify results # Thee conditions to improve performance, some functions to check # the condition need to get the full analysis request. if states_dict.get("review_state", "") == "to_be_verified": allowed = user.has_permission(VerifyPermission, username=self.member.getUserName()) # TODO-performance: isUserAllowedToVerify getts all analysis # objects inside the analysis request. if allowed: # Gettin the full object if not get before full_object = full_object if full_object else obj.getObject() if not full_object.isUserAllowedToVerify(self.member): item["after"]["state_title"] = \ """<img src='++resource++bika.lims.images/submitted-by-current-user.png' title='%s'/> """ % t(_("Cannot verify: Submitted by current user")) return item
def folderitem(self, obj, item, index): # Additional info from AnalysisRequest to be added in the item generated # by default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None member = self.mtool.getAuthenticatedMember() roles = member.getRoles() hideclientlink = 'RegulatoryInspector' in roles \ and 'Manager' not in roles \ and 'LabManager' not in roles \ and 'LabClerk' not in roles sample = obj.getSample() url = obj.absolute_url() if getSecurityManager().checkPermission(EditResults, obj): url += "/manage_results" item['Client'] = obj.aq_parent.Title() if (hideclientlink == False): item['replace']['Client'] = "<a href='%s'>%s</a>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) item['Creator'] = self.user_fullname(obj.Creator()) item['getRequestID'] = obj.getRequestID() item['replace']['getRequestID'] = "<a href='%s'>%s</a>" % \ (url, item['getRequestID']) item['getSample'] = sample item['replace']['getSample'] = \ "<a href='%s'>%s</a>" % (sample.absolute_url(), sample.Title()) item['replace']['getProfilesTitle'] = ", ".join( [p.Title() for p in obj.getProfiles()]) analysesnum = obj.getAnalysesNum() if analysesnum: item['getAnalysesNum'] = str(analysesnum[0]) + '/' + str(analysesnum[1]) else: item['getAnalysesNum'] = '' batch = obj.getBatch() if batch: item['BatchID'] = batch.getBatchID() item['replace']['BatchID'] = "<a href='%s'>%s</a>" % \ (batch.absolute_url(), item['BatchID']) else: item['BatchID'] = '' val = obj.Schema().getField('SubGroup').get(obj) item['SubGroup'] = val.Title() if val else '' samplingdate = obj.getSample().getSamplingDate() item['SamplingDate'] = self.ulocalized_time(samplingdate, long_format=1) item['getDateReceived'] = self.ulocalized_time(obj.getDateReceived()) item['getDatePublished'] = self.ulocalized_time(obj.getDatePublished()) item['getDateVerified'] = getTransitionDate(obj, 'verify') deviation = sample.getSamplingDeviation() item['SamplingDeviation'] = deviation and deviation.Title() or '' priority = obj.getPriority() item['Priority'] = '' # priority.Title() item['getStorageLocation'] = sample.getStorageLocation() and sample.getStorageLocation().Title() or '' item['AdHoc'] = sample.getAdHoc() and True or '' after_icons = "" state = self.workflow.getInfoFor(obj, 'worksheetanalysis_review_state') if state == 'assigned': after_icons += "<img src='%s/++resource++bika.lims.images/worksheet.png' title='%s'/>" % \ (self.portal_url, t(_("All analyses assigned"))) if self.workflow.getInfoFor(obj, 'review_state') == 'invalid': after_icons += "<img src='%s/++resource++bika.lims.images/delete.png' title='%s'/>" % \ (self.portal_url, t(_("Results have been withdrawn"))) if obj.getLate(): after_icons += "<img src='%s/++resource++bika.lims.images/late.png' title='%s'>" % \ (self.portal_url, t(_("Late Analyses"))) if samplingdate > DateTime(): after_icons += "<img src='%s/++resource++bika.lims.images/calendar.png' title='%s'>" % \ (self.portal_url, t(_("Future dated sample"))) if obj.getInvoiceExclude(): after_icons += "<img src='%s/++resource++bika.lims.images/invoice_exclude.png' title='%s'>" % \ (self.portal_url, t(_("Exclude from invoice"))) if sample.getSampleType().getHazardous(): after_icons += "<img src='%s/++resource++bika.lims.images/hazardous.png' title='%s'>" % \ (self.portal_url, t(_("Hazardous"))) if after_icons: item['after']['getRequestID'] = after_icons item['Created'] = self.ulocalized_time(obj.created()) contact = obj.getContact() if contact: item['ClientContact'] = contact.Title() item['replace']['ClientContact'] = "<a href='%s'>%s</a>" % \ (contact.absolute_url(), contact.Title()) else: item['ClientContact'] = "" SamplingWorkflowEnabled = sample.getSamplingWorkflowEnabled() if SamplingWorkflowEnabled and not samplingdate > DateTime(): datesampled = self.ulocalized_time(sample.getDateSampled()) if not datesampled: datesampled = self.ulocalized_time( DateTime(), long_format=1) item['class']['getDateSampled'] = 'provisional' sampler = sample.getSampler().strip() if sampler: item['replace']['getSampler'] = self.user_fullname(sampler) if 'Sampler' in member.getRoles() and not sampler: sampler = member.id item['class']['getSampler'] = 'provisional' else: datesampled = '' sampler = '' item['getDateSampled'] = datesampled item['getSampler'] = sampler # sampling workflow - inline edits for Sampler and Date Sampled checkPermission = self.context.portal_membership.checkPermission state = self.workflow.getInfoFor(obj, 'review_state') if state == 'to_be_sampled' \ and checkPermission(SampleSample, obj) \ and not samplingdate > DateTime(): item['required'] = ['getSampler', 'getDateSampled'] item['allow_edit'] = ['getSampler', 'getDateSampled'] samplers = getUsers(sample, ['Sampler', 'LabManager', 'Manager']) username = member.getUserName() users = [({'ResultValue': u, 'ResultText': samplers.getValue(u)}) for u in samplers] item['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' item['getSampler'] = Sampler # These don't exist on ARs # XXX This should be a list of preservers... item['getPreserver'] = '' item['getDatePreserved'] = '' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, obj): item['required'] = ['getPreserver', 'getDatePreserved'] item['allow_edit'] = ['getPreserver', 'getDatePreserved'] preservers = getUsers(obj, ['Preserver', 'LabManager', 'Manager']) username = member.getUserName() users = [({'ResultValue': u, 'ResultText': preservers.getValue(u)}) for u in preservers] item['choices'] = {'getPreserver': users} preserver = username in preservers.keys() and username or '' item['getPreserver'] = preserver item['getDatePreserved'] = self.ulocalized_time( DateTime(), long_format=1) item['class']['getPreserver'] = 'provisional' item['class']['getDatePreserved'] = 'provisional' # Submitting user may not verify results if item['review_state'] == 'to_be_verified' and \ not checkPermission(VerifyOwnResults, obj): self_submitted = False try: review_history = list(self.workflow.getInfoFor(obj, 'review_history')) review_history.reverse() for event in review_history: if event.get('action') == 'submit': if event.get('actor') == member.getId(): self_submitted = True break if self_submitted: item['after']['state_title'] = \ "<img src='++resource++bika.lims.images/submitted-by-current-user.png' title='%s'/>" % \ t(_("Cannot verify: Submitted by current user")) except Exception: pass return item
def folderitem(self, obj, item, index): # Additional info from AnalysisRequest to be added in the item generated # by default by bikalisting. # Call the folderitem method from the base class item = BikaListingView.folderitem(self, obj, item, index) if not item: return None member = self.mtool.getAuthenticatedMember() roles = member.getRoles() hideclientlink = ( "RegulatoryInspector" in roles and "Manager" not in roles and "LabManager" not in roles and "LabClerk" not in roles ) sample = obj.getSample() url = obj.absolute_url() if getSecurityManager().checkPermission(EditResults, obj): url += "/manage_results" item["Client"] = obj.aq_parent.Title() if hideclientlink == False: item["replace"]["Client"] = "<a href='%s'>%s</a>" % (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) item["Creator"] = self.user_fullname(obj.Creator()) item["getRequestID"] = obj.getRequestID() item["replace"]["getRequestID"] = "<a href='%s'>%s</a>" % (url, item["getRequestID"]) item["getSample"] = sample item["replace"]["getSample"] = "<a href='%s'>%s</a>" % (sample.absolute_url(), sample.Title()) item["replace"]["getProfilesTitle"] = ", ".join([p.Title() for p in obj.getProfiles()]) analysesnum = obj.getAnalysesNum() if analysesnum: item["getAnalysesNum"] = str(analysesnum[0]) + "/" + str(analysesnum[1]) else: item["getAnalysesNum"] = "" batch = obj.getBatch() if batch: item["BatchID"] = batch.getBatchID() item["replace"]["BatchID"] = "<a href='%s'>%s</a>" % (batch.absolute_url(), item["BatchID"]) else: item["BatchID"] = "" val = obj.Schema().getField("SubGroup").get(obj) item["SubGroup"] = val.Title() if val else "" samplingdate = obj.getSample().getSamplingDate() item["SamplingDate"] = self.ulocalized_time(samplingdate, long_format=1) item["getDateReceived"] = self.ulocalized_time(obj.getDateReceived()) item["getDatePublished"] = self.ulocalized_time(obj.getDatePublished()) deviation = sample.getSamplingDeviation() item["SamplingDeviation"] = deviation and deviation.Title() or "" priority = obj.getPriority() item["Priority"] = "" # priority.Title() item["getStorageLocation"] = sample.getStorageLocation() and sample.getStorageLocation().Title() or "" item["AdHoc"] = sample.getAdHoc() and True or "" after_icons = "" state = self.workflow.getInfoFor(obj, "worksheetanalysis_review_state") if state == "assigned": after_icons += "<img src='%s/++resource++bika.lims.images/worksheet.png' title='%s'/>" % ( self.portal_url, t(_("All analyses assigned")), ) if self.workflow.getInfoFor(obj, "review_state") == "invalid": after_icons += "<img src='%s/++resource++bika.lims.images/delete.png' title='%s'/>" % ( self.portal_url, t(_("Results have been withdrawn")), ) if obj.getLate(): after_icons += "<img src='%s/++resource++bika.lims.images/late.png' title='%s'>" % ( self.portal_url, t(_("Late Analyses")), ) if samplingdate > DateTime(): after_icons += "<img src='%s/++resource++bika.lims.images/calendar.png' title='%s'>" % ( self.portal_url, t(_("Future dated sample")), ) if obj.getInvoiceExclude(): after_icons += "<img src='%s/++resource++bika.lims.images/invoice_exclude.png' title='%s'>" % ( self.portal_url, t(_("Exclude from invoice")), ) if sample.getSampleType().getHazardous(): after_icons += "<img src='%s/++resource++bika.lims.images/hazardous.png' title='%s'>" % ( self.portal_url, t(_("Hazardous")), ) if after_icons: item["after"]["getRequestID"] = after_icons item["Created"] = self.ulocalized_time(obj.created()) contact = obj.getContact() if contact: item["ClientContact"] = contact.Title() item["replace"]["ClientContact"] = "<a href='%s'>%s</a>" % (contact.absolute_url(), contact.Title()) else: item["ClientContact"] = "" SamplingWorkflowEnabled = sample.getSamplingWorkflowEnabled() if SamplingWorkflowEnabled and not samplingdate > DateTime(): datesampled = self.ulocalized_time(sample.getDateSampled()) if not datesampled: datesampled = self.ulocalized_time(DateTime(), long_format=1) item["class"]["getDateSampled"] = "provisional" sampler = sample.getSampler().strip() if sampler: item["replace"]["getSampler"] = self.user_fullname(sampler) if "Sampler" in member.getRoles() and not sampler: sampler = member.id item["class"]["getSampler"] = "provisional" else: datesampled = "" sampler = "" item["getDateSampled"] = datesampled item["getSampler"] = sampler # sampling workflow - inline edits for Sampler and Date Sampled checkPermission = self.context.portal_membership.checkPermission state = self.workflow.getInfoFor(obj, "review_state") if state == "to_be_sampled" and checkPermission(SampleSample, obj) and not samplingdate > DateTime(): item["required"] = ["getSampler", "getDateSampled"] item["allow_edit"] = ["getSampler", "getDateSampled"] samplers = getUsers(sample, ["Sampler", "LabManager", "Manager"]) username = member.getUserName() users = [({"ResultValue": u, "ResultText": samplers.getValue(u)}) for u in samplers] item["choices"] = {"getSampler": users} Sampler = sampler and sampler or (username in samplers.keys() and username) or "" item["getSampler"] = Sampler # These don't exist on ARs # XXX This should be a list of preservers... item["getPreserver"] = "" item["getDatePreserved"] = "" # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, obj): item["required"] = ["getPreserver", "getDatePreserved"] item["allow_edit"] = ["getPreserver", "getDatePreserved"] preservers = getUsers(obj, ["Preserver", "LabManager", "Manager"]) username = member.getUserName() users = [({"ResultValue": u, "ResultText": preservers.getValue(u)}) for u in preservers] item["choices"] = {"getPreserver": users} preserver = username in preservers.keys() and username or "" item["getPreserver"] = preserver item["getDatePreserved"] = self.ulocalized_time(DateTime(), long_format=1) item["class"]["getPreserver"] = "provisional" item["class"]["getDatePreserved"] = "provisional" # Submitting user may not verify results if item["review_state"] == "to_be_verified" and not checkPermission(VerifyOwnResults, obj): self_submitted = False try: review_history = list(self.workflow.getInfoFor(obj, "review_history")) review_history.reverse() for event in review_history: if event.get("action") == "submit": if event.get("actor") == member.getId(): self_submitted = True break if self_submitted: item["after"]["state_title"] = ( "<img src='++resource++bika.lims.images/submitted-by-current-user.png' title='%s'/>" % t(_("Cannot verify: Submitted by current user")) ) except Exception: pass return item