def folderitems(self): """Returns an array of dictionaries, each dictionary represents an analysis row to be rendered in the list. The array returned is sorted in accordance with the layout positions set for the analyses this worksheet contains when the analyses were added in the worksheet. :returns: list of dicts with the items to be rendered in the list """ items = BaseView.folderitems(self) # Fill empty positions from the layout with fake rows. The worksheet # can be generated by making use of a WorksheetTemplate, so there is # the chance that some slots of this worksheet being empty. We need to # render a row still, at lest to display the slot number (Pos) self.fill_empty_slots(items) # Sort the items in accordance with the layout items = sorted(items, key=itemgetter("pos_sortkey")) # Fill the slot header cells (first cell of each row). Each slot # contains the analyses that belong to the same parent # (AnalysisRequest, ReferenceSample), so the information about the # parent must be displayed in the first cell of each slot. self.fill_slots_headers(items) return items
def folderitems(self): self.contentsMethod = self.context.getAnalyses items = AnalysesView.folderitems(self) for x in range(len(items)): if not items[x].has_key('obj'): continue obj = items[x]['obj'] ar = obj.aq_parent items[x]['replace']['Request'] = "<a href='%s'>%s</a>"%(ar.absolute_url(), ar.Title()) return items
def folderitems(self): self.contentsMethod = self.context.getAnalyses items = AnalysesView.folderitems(self) for x in range(len(items)): if not items[x].has_key('obj'): continue obj = items[x]['obj'] ar = obj.aq_parent items[x]['replace']['Request'] = \ "<a href='%s'>%s</a>"%(ar.absolute_url(), ar.Title()) return items
def folderitems(self): self.contentsMethod = self.context.getAnalyses items = AnalysesView.folderitems(self) for x in range(len(items)): if not items[x].has_key("obj"): continue obj = items[x]["obj"] ar = obj.aq_parent items[x]["replace"]["Request"] = "<a href='%s'>%s</a>" % (ar.absolute_url(), ar.Title()) items[x]["replace"]["Priority"] = " " # TODO this space is required for it to work return items
def folderitems(self): items = AnalysesView.folderitems(self) items.sort(key=itemgetter('CaptureDate'), reverse=True) for i in range(len(items)): obj = items[i]['obj'] imgtype = "" if obj.portal_type == 'ReferenceAnalysis': antype = QCANALYSIS_TYPES.getValue(obj.getReferenceType()) if obj.getReferenceType() == 'c': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/control.png'/> " % ( antype, self.context.absolute_url()) if obj.getReferenceType() == 'b': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/> " % ( antype, self.context.absolute_url()) items[i]['replace']['Partition'] = "<a href='%s'>%s</a>" % ( obj.aq_parent.absolute_url(), obj.aq_parent.id) elif obj.portal_type == 'DuplicateAnalysis': antype = QCANALYSIS_TYPES.getValue('d') imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/> " % ( antype, self.context.absolute_url()) items[i]['sortcode'] = '%s_%s' % ( obj.getSample().id, obj.getService().getKeyword()) else: items[i]['sortcode'] = '%s_%s' % ( obj.getSample().id, obj.getService().getKeyword()) items[i]['before']['Service'] = imgtype # Get retractions field pdf = obj.getRetractedAnalysesPdfReport() title = '' anchor = '' try: if pdf: filesize = 0 title = _('Retractions') anchor = "<a class='pdf' target='_blank' href='%s/at_download/RetractedAnalysesPdfReport'>%s</a>" % \ (obj.absolute_url(), _("Retractions")) filesize = pdf.get_size() filesize = filesize / 1024 if filesize > 0 else 0 except: # POSKeyError: 'No blob file' # Show the record, but not the link title = _('Retraction report unavailable') anchor = title items[i]['Retractions'] = title items[i]['replace']['Retractions'] = anchor # Create json qcid = obj.aq_parent.id serviceref = "%s (%s)" % (items[i]['Service'], items[i]['Keyword']) trows = self.anjson.get(serviceref, {}) anrows = trows.get(qcid, []) anid = '%s.%s' % (items[i]['getReferenceAnalysesGroupID'], items[i]['id']) rr = obj.aq_parent.getResultsRangeDict() uid = obj.getServiceUID() if uid in rr: specs = rr[uid] try: smin = float(specs.get('min', 0)) smax = float(specs.get('max', 0)) error = float(specs.get('error', 0)) target = float(specs.get('result', 0)) result = float(items[i]['Result']) error_amount = ((target / 100) * error) if target > 0 else 0 upper = smax + error_amount lower = smin - error_amount anrow = { 'date': items[i]['CaptureDate'], 'min': smin, 'max': smax, 'target': target, 'error': error, 'erroramount': error_amount, 'upper': upper, 'lower': lower, 'result': result, 'unit': items[i]['Unit'], 'id': items[i]['uid'] } anrows.append(anrow) trows[qcid] = anrows self.anjson[serviceref] = trows except: pass return items
def folderitems(self): items = AnalysesView.folderitems(self) items.sort(key=itemgetter('CaptureDate'), reverse=True) for i in range(len(items)): obj = items[i]['obj'] imgtype = "" if obj.portal_type == 'ReferenceAnalysis': antype = QCANALYSIS_TYPES.getValue(obj.getReferenceType()) if obj.getReferenceType() == 'c': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/control.png'/> " % (antype, self.context.absolute_url()) if obj.getReferenceType() == 'b': imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/blank.png'/> " % (antype, self.context.absolute_url()) items[i]['replace']['Partition'] = "<a href='%s'>%s</a>" % (obj.aq_parent.absolute_url(), obj.aq_parent.id) elif obj.portal_type == 'DuplicateAnalysis': antype = QCANALYSIS_TYPES.getValue('d') imgtype = "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/> " % (antype, self.context.absolute_url()) items[i]['sortcode'] = '%s_%s' % (obj.getSample().id, obj.getService().getKeyword()) else: items[i]['sortcode'] = '%s_%s' % (obj.getSample().id, obj.getService().getKeyword()) items[i]['before']['Service'] = imgtype # Get retractions field pdf = obj.getRetractedAnalysesPdfReport() title = '' anchor = '' try: if pdf: filesize = 0 title = _('Retractions') anchor = "<a class='pdf' target='_blank' href='%s/at_download/RetractedAnalysesPdfReport'>%s</a>" % \ (obj.absolute_url(), _("Retractions")) filesize = pdf.get_size() filesize = filesize / 1024 if filesize > 0 else 0 except: # POSKeyError: 'No blob file' # Show the record, but not the link title = _('Retraction report unavailable') anchor = title items[i]['Retractions'] = title items[i]['replace']['Retractions'] = anchor # Create json qcid = obj.aq_parent.id; serviceref = "%s (%s)" % (items[i]['Service'], items[i]['Keyword']) trows = self.anjson.get(serviceref, {}); anrows = trows.get(qcid, []); anid = '%s.%s' % (items[i]['getReferenceAnalysesGroupID'], items[i]['id']) rr = obj.aq_parent.getResultsRangeDict() uid = obj.getServiceUID() if uid in rr: specs = rr[uid]; try: smin = float(specs.get('min', 0)) smax = float(specs.get('max', 0)) error = float(specs.get('error', 0)) target = float(specs.get('result', 0)) result = float(items[i]['Result']) error_amount = ((target / 100) * error) if target > 0 else 0 upper = smax + error_amount lower = smin - error_amount anrow = { 'date': items[i]['CaptureDate'], 'min': smin, 'max': smax, 'target': target, 'error': error, 'erroramount': error_amount, 'upper': upper, 'lower': lower, 'result': result, 'unit': items[i]['Unit'], 'id': items[i]['uid'] } anrows.append(anrow); trows[qcid] = anrows; self.anjson[serviceref] = trows except: pass return items
def folderitems(self): self.analyst = self.context.getAnalyst().strip() self.instrument = self.context.getInstrument() items = BaseView.folderitems(self) layout = self.context.getLayout() highest_position = 0 new_items = [] for x, item in enumerate(items): obj = item['obj'].getObject() pos = [ slot['position'] for slot in layout if slot['analysis_uid'] == obj.UID() ][0] # compensate for possible bad data (dbw#104) if type(pos) in (list, tuple): pos = pos[0] if pos == 'new': continue pos = int(pos) highest_position = max(highest_position, pos) items[x]['Pos'] = pos items[x]['colspan'] = {'Pos': 1} method = obj.getMethod() items[x]['Service'] = obj.Title() #items[x]['Method'] = method and method.Title() or '' items[x]['class']['Service'] = 'service_title' items[x]['Category'] = obj.getCategoryTitle() if obj.portal_type == "ReferenceAnalysis": items[x]['DueDate'] = self.ulocalized_time( obj.aq_parent.getExpiryDate(), long_format=0) else: items[x]['DueDate'] = self.ulocalized_time(obj.getDueDate()) items[x]['Order'] = '' # instrument = obj.getInstrument() #items[x]['Instrument'] = instrument and instrument.Title() or '' new_items.append(item) items = new_items # insert placeholder row items in the gaps # This is done badly to compensate for possible bad data (dbw#104) empties = [] used = [] for slot in layout: position = slot['position'] if type(position) in (list, tuple): position = position[0] if position == 'new': continue position = int(position) used.append(position) for pos in range(1, highest_position + 1): if pos not in used: empties.append(pos) item = {} item.update({ 'obj': self.context, 'id': self.context.id, 'uid': self.context.UID(), 'title': self.context.Title(), 'type_class': 'blank-worksheet-row', 'url': self.context.absolute_url(), 'relative_url': self.context.absolute_url(), 'view_url': self.context.absolute_url(), 'path': "/".join(self.context.getPhysicalPath()), 'before': {}, 'after': {}, 'choices': {}, 'class': {}, 'state_class': 'state-empty', 'allow_edit': [], 'colspan': { 'Pos': len(self.columns) + len(self.interim_fields) }, 'rowspan': { 'Pos': 1 }, 'Pos': pos, 'Service': '', 'Attachments': '', 'state_title': 's', }) item['replace'] = { 'Pos': "<table width='100%' cellpadding='0' cellspacing='0'>" + \ "<tr><td class='pos'>%s</td>" % pos + \ "<td align='right'> </td></tr></table>", 'select_column': '', } items.append(item) items = sorted(items, key=itemgetter('Service')) try: items = sorted(items, key=itemgetter('Pos')) except: pass slot_items = {} # pos:[item_nrs] for x in range(len(items)): p = items[x]['Pos'] if p in slot_items: slot_items[p].append(x) else: slot_items[p] = [ x, ] actual_table_position = -1 # The first item in items[this position] gets a rowspan for it's # "Position" column, which spans all other table rows in this position. for pos, pos_items in slot_items.items(): actual_table_position += 1 x = pos_items[0] if pos in empties: continue # set Pos column for this row, to have a rowspan # Analysis Remarks only allowed for Analysis types # Needs to look inside all slot analyses, cause some of them can # have remarks entered and can have different analysis statuses rowspan = len(pos_items) remarksenabled = self.context.bika_setup.getEnableAnalysisRemarks() for pos_subitem in pos_items: subitem = items[pos_subitem] isanalysis = subitem['obj'].portal_type == 'Analysis' hasremarks = True if subitem.get('Remarks', '') else False remarksedit = remarksenabled and 'Remarks' in subitem.get( 'allow_edit', []) if isanalysis and (hasremarks or remarksedit): rowspan += 1 items[x]['rowspan'] = {'Pos': rowspan} # TODO-performance: getting the object here... obj = items[x]['obj'].getObject() # fill the rowspan with a little table # parent is either an AR, a Worksheet, or a # ReferenceSample (analysis parent). parent = obj.aq_parent if parent.aq_parent.portal_type == "WorksheetFolder": # we're a duplicate; get original object's client client = obj.getAnalysis().aq_parent.aq_parent elif parent.aq_parent.portal_type == "Supplier": # we're a reference sample; get reference definition client = obj.getReferenceDefinition() else: client = parent.aq_parent pos_text = "<table class='worksheet-position' width='100%%' cellpadding='0' cellspacing='0' style='padding-bottom:5px;'><tr>" + \ "<td class='pos' rowspan='3'>%s</td>" % pos if obj.portal_type == 'ReferenceAnalysis': pos_text += "<td class='pos_top'>%s</td>" % obj.getReferenceAnalysesGroupID( ) elif obj.portal_type == 'DuplicateAnalysis' and \ obj.getAnalysis().portal_type == 'ReferenceAnalysis': pos_text += "<td class='pos_top'><a href='%s'>%s</a></td>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.id) elif client: pos_text += "<td class='pos_top'><a href='%s'>%s</a></td>" % \ (client.absolute_url(), client.Title()) else: pos_text += "<td class='pos_top'> </td>" pos_text += "<td class='pos_top_icons' rowspan='3'>" if obj.portal_type == 'DuplicateAnalysis': pos_text += "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/>" % ( _("Duplicate").encode('utf-8'), self.context.absolute_url()) pos_text += "<br/>" elif obj.portal_type == 'ReferenceAnalysis' and obj.ReferenceType == 'b': pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/blank.png'></a>" % ( parent.absolute_url(), parent.Title()) pos_text += "<br/>" elif obj.portal_type == 'ReferenceAnalysis' and obj.ReferenceType == 'c': pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/control.png'></a>" % ( parent.absolute_url(), parent.Title()) pos_text += "<br/>" if parent.portal_type == 'AnalysisRequest': sample = parent.getSample() pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/sample.png'></a>" % ( sample.absolute_url(), sample.Title()) pos_text += "</td></tr>" pos_text += "<tr><td>" if parent.portal_type == 'AnalysisRequest': pos_text += "<a href='%s'>%s</a>" % (parent.absolute_url(), parent.Title()) elif parent.portal_type == 'ReferenceSample': pos_text += "<a href='%s'>%s</a>" % (parent.absolute_url(), parent.Title()) elif obj.portal_type == 'DuplicateAnalysis': pos_text += "<a style='white-space:nowrap' href='%s'>%s</a>" % ( obj.getAnalysis().aq_parent.absolute_url(), obj.getReferenceAnalysesGroupID()) elif parent.portal_type == 'Worksheet': parent = obj.getAnalysis().aq_parent pos_text += "<a href='%s'>(%s)</a>" % (parent.absolute_url(), parent.Title()) pos_text += "</td></tr>" # sampletype pos_text += "<tr><td>" if obj.portal_type == 'Analysis': pos_text += obj.aq_parent.getSample().getSampleType().Title() elif obj.portal_type == 'ReferenceAnalysis' or \ (obj.portal_type == 'DuplicateAnalysis' and \ obj.getAnalysis().portal_type == 'ReferenceAnalysis'): pos_text += "" #obj.aq_parent.getReferenceDefinition().Title() elif obj.portal_type == 'DuplicateAnalysis': pos_text += obj.getAnalysis().aq_parent.getSample( ).getSampleType().Title() pos_text += "</td></tr>" # samplingdeviation if obj.portal_type == 'Analysis': deviation = obj.aq_parent.getSample().getSamplingDeviation() if deviation: pos_text += "<tr><td> </td>" pos_text += "<td colspan='2'>" pos_text += deviation.Title() pos_text += "</td></tr>" ## # barcode ## barcode = parent.id.replace("-", "") ## if obj.portal_type == 'DuplicateAnalysis': ## barcode += "D" ## pos_text += "<tr><td class='barcode' colspan='3'><div id='barcode_%s'></div>" % barcode + \ ## "<script type='text/javascript'>$('#barcode_%s').barcode('%s', 'code128', {'barHeight':15, addQuietZone:false, showHRI: false })</script>" % (barcode, barcode) + \ ## "</td></tr>" pos_text += "</table>" items[x]['replace']['Pos'] = pos_text for k, v in self.columns.items(): self.columns[k]['sortable'] = False return items
def folderitems(self): self.analyst = self.context.getAnalyst().strip() self.instrument = self.context.getInstrument() self.contentsMethod = self.context.getFolderContents items = AnalysesView.folderitems(self) layout = self.context.getLayout() highest_position = 0 for x, item in enumerate(items): obj = item['obj'] pos = [int(slot['position']) for slot in layout if slot['analysis_uid'] == obj.UID()][0] highest_position = max(highest_position, pos) items[x]['Pos'] = pos items[x]['colspan'] = {'Pos':1} service = obj.getService() method = service.getMethod() items[x]['Service'] = service.Title() items[x]['Method'] = method and method.Title() or '' items[x]['class']['Service'] = 'service_title' items[x]['Category'] = service.getCategory().Title() if obj.portal_type == "ReferenceAnalysis": items[x]['DueDate'] = '' else: items[x]['DueDate'] = self.ulocalized_time(obj.getDueDate()) items[x]['Order'] = '' # insert placeholder row items in the gaps empties = [] used = [int(slot['position']) for slot in layout] for pos in range(1, highest_position + 1): if pos not in used: empties.append(pos) item = {} item.update({ 'obj': self.context, 'id': self.context.id, 'uid': self.context.UID(), 'title': self.context.Title(), 'type_class': 'blank-worksheet-row', 'url': self.context.absolute_url(), 'relative_url': self.context.absolute_url(), 'view_url': self.context.absolute_url(), 'path': "/".join(self.context.getPhysicalPath()), 'before': {}, 'after': {}, 'choices': {}, 'class': {}, 'state_class': 'state-empty', 'allow_edit': [], 'colspan': {'Pos':len(self.columns) + len(self.interim_fields)}, 'rowspan': {'Pos':1}, 'Pos': pos, 'Service': '', 'Attachments': '', 'state_title': 's'}) item['replace'] = { 'Pos': "<table width='100%' cellpadding='0' cellspacing='0'>" + \ "<tr><td class='pos'>%s</td>" % pos + \ "<td align='right'> </td></tr></table>", 'select_column': '', } items.append(item) items = sorted(items, key = itemgetter('Service')) items = sorted(items, key = itemgetter('Pos')) slot_items = {} # pos:[item_nrs] for x in range(len(items)): p = items[x]['Pos'] if p in slot_items: slot_items[p].append(x) else: slot_items[p] = [x, ] actual_table_position = -1 # The first item in items[this position] gets a rowspan for it's # "Position" column, which spans all other table rows in this position. for pos, pos_items in slot_items.items(): actual_table_position += 1 x = pos_items[0] if pos in empties: continue # set Pos column for this row, to have a rowspan items[x]['rowspan'] = {'Pos': len(pos_items)} # fill the rowspan with a little table obj = items[x]['obj'] # parent is either an AR, a Worksheet, or a # ReferenceSample (analysis parent). parent = obj.aq_parent if parent.aq_parent.portal_type == "WorksheetFolder": # we're a duplicate; get original object's client client = obj.getAnalysis().aq_parent.aq_parent elif parent.aq_parent.portal_type == "ReferenceSupplier": # we're a reference sample; get reference definition client = obj.getReferenceDefinition() else: client = parent.aq_parent pos_text = "<table class='worksheet-position' width='100%%' cellpadding='0' cellspacing='0' style='padding-bottom:5px;'><tr>" + \ "<td class='pos' rowspan='3'>%s</td>" % pos pos_text += "<td class='pos_top'><a href='%s'>%s</a></td>" % \ (client.absolute_url(), client.Title()) pos_text += "<td class='pos_top_icons' rowspan='3'>" if obj.portal_type == 'DuplicateAnalysis': pos_text += "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/>" % (_("Duplicate"), self.context.absolute_url()) pos_text += "<br/>" elif obj.portal_type == 'ReferenceAnalysis' and obj.ReferenceType == 'b': pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/blank.png'></a>" % (parent.absolute_url(), parent.Title()) pos_text += "<br/>" elif obj.portal_type == 'ReferenceAnalysis' and obj.ReferenceType == 'c': pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/control.png'></a>" % (parent.absolute_url(), parent.Title()) pos_text += "<br/>" if parent.portal_type == 'AnalysisRequest': sample = parent.getSample() pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/sample.png'></a>" % (sample.absolute_url(), sample.Title()) pos_text += "</td></tr>" pos_text += "<tr><td>" if parent.portal_type == 'AnalysisRequest': pos_text += "<a href='%s'>%s</a>" % (parent.absolute_url(), parent.Title()) elif parent.portal_type == 'ReferenceSample': pos_text += "<a href='%s'>%s</a>" % (parent.absolute_url(), parent.Title()) elif parent.portal_type == 'Worksheet': parent = obj.getAnalysis().aq_parent pos_text += "<a href='%s'>(%s)</a>" % (parent.absolute_url(), parent.Title()) pos_text += "</td></tr>" # sampletype pos_text += "<tr><td>" if obj.portal_type == 'Analysis': pos_text += obj.aq_parent.getSample().getSampleType().Title() elif obj.portal_type == 'ReferenceAnalysis': pos_text += "" #obj.aq_parent.getReferenceDefinition().Title() elif obj.portal_type == 'DuplicateAnalysis': pos_text += obj.getAnalysis().aq_parent.getSample().getSampleType().Title() pos_text += "</td></tr>" # samplingdeviation if obj.portal_type == 'Analysis': deviation = obj.aq_parent.getSample().getSamplingDeviation() if deviation: pos_text += "<tr><td>" pos_text += deviation.Title() pos_text += "</td></tr>" ## # barcode ## barcode = parent.id.replace("-", "") ## if obj.portal_type == 'DuplicateAnalysis': ## barcode += "D" ## pos_text += "<tr><td class='barcode' colspan='3'><div id='barcode_%s'></div>" % barcode + \ ## "<script type='text/javascript'>$('#barcode_%s').barcode('%s', 'code39', {'barHeight':15, addQuietZone:false, showHRI: false })</script>" % (barcode, barcode) + \ ## "</td></tr>" pos_text += "</table>" items[x]['replace']['Pos'] = pos_text for k,v in self.columns.items(): self.columns[k]['sortable'] = False return items
def folderitems(self): items = AnalysesView.folderitems(self) items = sorted(items, key = itemgetter('getReferenceAnalysesGroupID')) items.reverse() return items
def folderitems(self): self.analyst = self.context.getAnalyst().strip() self.instrument = self.context.getInstrument() self.contentsMethod = self.context.getFolderContents items = BaseView.folderitems(self) layout = self.context.getLayout() highest_position = 0 new_items = [] for x, item in enumerate(items): obj = item['obj'] pos = [slot['position'] for slot in layout if slot['analysis_uid'] == obj.UID()][0] # compensate for possible bad data (dbw#104) if type(pos) in (list, tuple): pos = pos[0] if pos == 'new': continue pos = int(pos) highest_position = max(highest_position, pos) items[x]['Pos'] = pos items[x]['colspan'] = {'Pos':1} service = obj.getService() method = service.getMethod() items[x]['Service'] = service.Title() items[x]['Priority'] = '' #items[x]['Method'] = method and method.Title() or '' items[x]['class']['Service'] = 'service_title' items[x]['Category'] = service.getCategory() and service.getCategory().Title() or '' if obj.portal_type == "ReferenceAnalysis": items[x]['DueDate'] = self.ulocalized_time(obj.aq_parent.getExpiryDate(), long_format=0) else: items[x]['DueDate'] = self.ulocalized_time(obj.getDueDate()) items[x]['Order'] = '' instrument = obj.getInstrument() #items[x]['Instrument'] = instrument and instrument.Title() or '' new_items.append(item) items = new_items # insert placeholder row items in the gaps # This is done badly to compensate for possible bad data (dbw#104) empties = [] used = [] for slot in layout: position = slot['position'] if type(position) in (list, tuple): position = position[0] if position == 'new': continue position = int(position) used.append(position) for pos in range(1, highest_position + 1): if pos not in used: empties.append(pos) item = {} item.update({ 'obj': self.context, 'id': self.context.id, 'uid': self.context.UID(), 'title': self.context.Title(), 'type_class': 'blank-worksheet-row', 'url': self.context.absolute_url(), 'relative_url': self.context.absolute_url(), 'view_url': self.context.absolute_url(), 'path': "/".join(self.context.getPhysicalPath()), 'before': {}, 'after': {}, 'choices': {}, 'class': {}, 'state_class': 'state-empty', 'allow_edit': [], 'colspan': {'Pos':len(self.columns) + len(self.interim_fields)}, 'rowspan': {'Pos':1}, 'Pos': pos, 'Service': '', 'Attachments': '', 'state_title': 's',}) item['replace'] = { 'Pos': "<table width='100%' cellpadding='0' cellspacing='0'>" + \ "<tr><td class='pos'>%s</td>" % pos + \ "<td align='right'> </td></tr></table>", 'select_column': '', } items.append(item) items = sorted(items, key = itemgetter('Service')) try: items = sorted(items, key = itemgetter('Pos')) except: pass slot_items = {} # pos:[item_nrs] for x in range(len(items)): p = items[x]['Pos'] if p in slot_items: slot_items[p].append(x) else: slot_items[p] = [x, ] actual_table_position = -1 # The first item in items[this position] gets a rowspan for it's # "Position" column, which spans all other table rows in this position. for pos, pos_items in slot_items.items(): actual_table_position += 1 x = pos_items[0] if pos in empties: continue # set Pos column for this row, to have a rowspan # Analysis Remarks only allowed for Analysis types # Needs to look inside all slot analyses, cause some of them can # have remarks entered and can have different analysis statuses rowspan = len(pos_items) remarksenabled = self.context.bika_setup.getEnableAnalysisRemarks() for pos_subitem in pos_items: subitem = items[pos_subitem] isanalysis = subitem['obj'].portal_type == 'Analysis' hasremarks = True if subitem.get('Remarks', '') else False remarksedit = remarksenabled and 'Remarks' in subitem.get('allow_edit', []) if isanalysis and (hasremarks or remarksedit): rowspan += 1 items[x]['rowspan'] = {'Pos': rowspan} obj = items[x]['obj'] # fill the rowspan with a little table # parent is either an AR, a Worksheet, or a # ReferenceSample (analysis parent). parent = obj.aq_parent if parent.aq_parent.portal_type == "WorksheetFolder": # we're a duplicate; get original object's client client = obj.getAnalysis().aq_parent.aq_parent elif parent.aq_parent.portal_type == "Supplier": # we're a reference sample; get reference definition client = obj.getReferenceDefinition() else: client = parent.aq_parent pos_text = "<table class='worksheet-position' width='100%%' cellpadding='0' cellspacing='0' style='padding-bottom:5px;'><tr>" + \ "<td class='pos' rowspan='3'>%s</td>" % pos if obj.portal_type == 'ReferenceAnalysis': pos_text += "<td class='pos_top'>%s</td>" % obj.getReferenceAnalysesGroupID() elif obj.portal_type == 'DuplicateAnalysis' and \ obj.getAnalysis().portal_type == 'ReferenceAnalysis': pos_text += "<td class='pos_top'><a href='%s'>%s</a></td>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.id) elif client: pos_text += "<td class='pos_top'><a href='%s'>%s</a></td>" % \ (client.absolute_url(), client.Title()) else: pos_text += "<td class='pos_top'> </td>" pos_text += "<td class='pos_top_icons' rowspan='3'>" if obj.portal_type == 'DuplicateAnalysis': pos_text += "<img title='%s' src='%s/++resource++bika.lims.images/duplicate.png'/>" % (_("Duplicate").encode('utf-8'), self.context.absolute_url()) pos_text += "<br/>" elif obj.portal_type == 'ReferenceAnalysis' and obj.ReferenceType == 'b': pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/blank.png'></a>" % (parent.absolute_url(), parent.Title()) pos_text += "<br/>" elif obj.portal_type == 'ReferenceAnalysis' and obj.ReferenceType == 'c': pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/control.png'></a>" % (parent.absolute_url(), parent.Title()) pos_text += "<br/>" if parent.portal_type == 'AnalysisRequest': sample = parent.getSample() pos_text += "<a href='%s'><img title='%s' src='++resource++bika.lims.images/sample.png'></a>" % (sample.absolute_url(), sample.Title()) pos_text += "</td></tr>" pos_text += "<tr><td>" if parent.portal_type == 'AnalysisRequest': pos_text += "<a href='%s'>%s</a>" % (parent.absolute_url(), parent.Title()) elif parent.portal_type == 'ReferenceSample': pos_text += "<a href='%s'>%s</a>" % (parent.absolute_url(), parent.Title()) elif obj.portal_type == 'DuplicateAnalysis': pos_text += "<a style='white-space:nowrap' href='%s'>%s</a>" % (obj.getAnalysis().aq_parent.absolute_url(), obj.getReferenceAnalysesGroupID()) elif parent.portal_type == 'Worksheet': parent = obj.getAnalysis().aq_parent pos_text += "<a href='%s'>(%s)</a>" % (parent.absolute_url(), parent.Title()) pos_text += "</td></tr>" # sampletype pos_text += "<tr><td>" if obj.portal_type == 'Analysis': pos_text += obj.aq_parent.getSample().getSampleType().Title() elif obj.portal_type == 'ReferenceAnalysis' or \ (obj.portal_type == 'DuplicateAnalysis' and \ obj.getAnalysis().portal_type == 'ReferenceAnalysis'): pos_text += "" #obj.aq_parent.getReferenceDefinition().Title() elif obj.portal_type == 'DuplicateAnalysis': pos_text += obj.getAnalysis().aq_parent.getSample().getSampleType().Title() pos_text += "</td></tr>" # samplingdeviation if obj.portal_type == 'Analysis': deviation = obj.aq_parent.getSample().getSamplingDeviation() if deviation: pos_text += "<tr><td> </td>" pos_text += "<td colspan='2'>" pos_text += deviation.Title() pos_text += "</td></tr>" ## # barcode ## barcode = parent.id.replace("-", "") ## if obj.portal_type == 'DuplicateAnalysis': ## barcode += "D" ## pos_text += "<tr><td class='barcode' colspan='3'><div id='barcode_%s'></div>" % barcode + \ ## "<script type='text/javascript'>$('#barcode_%s').barcode('%s', 'code128', {'barHeight':15, addQuietZone:false, showHRI: false })</script>" % (barcode, barcode) + \ ## "</td></tr>" pos_text += "</table>" items[x]['replace']['Pos'] = pos_text items[x]['getPriority'] = '' #Icon get added by adapter for k,v in self.columns.items(): self.columns[k]['sortable'] = False return items