def getAnalysts(self): analysts = getUsers(self.context, ['Manager', 'LabManager', 'Analyst']) analysts = analysts.sortedByKey() ret = [] for a in analysts: ret.append({'ResultValue': a, 'ResultText': analysts.getValue(a)}) return ret
def __call__(self): self.selection_macros = SelectionMacrosView(self.context, self.request) self.icon = self.portal_url + "/++resource++bika.lims.images/report_big.png" self.getAnalysts = getUsers(self.context, ['Manager', 'LabManager', 'Analyst']) self.additional_reports = [] adapters = getAdapters((self.context, ), IProductivityReport) for name, adapter in adapters: report_dict = adapter(self.context, self.request) report_dict['id'] = name self.additional_reports.append(report_dict) return self.template()
def select_user(self, allow_blank=True, style=None): self.style = style self.allow_blank = allow_blank self.users = getUsers(self.context, None, allow_blank) return self.select_user_pt()
def __init__(self, context, request): super(WorksheetFolderListingView, self).__init__(context, request) self.catalog = 'bika_catalog' self.contentFilter = { 'portal_type': 'Worksheet', 'review_state':['open', 'to_be_verified', 'verified', 'rejected'], 'sort_on':'id', 'sort_order': 'reverse'} self.context_actions = {_('Add'): {'url': 'worksheet_add', 'icon': '++resource++bika.lims.images/add.png', 'class': 'worksheet_add'}} self.show_table_only = False self.show_sort_column = False self.show_select_row = False self.show_select_all_checkbox = True self.show_select_column = True self.pagesize = 25 self.restrict_results = False request.set('disable_border', 1) self.icon = self.portal_url + "/++resource++bika.lims.images/worksheet_big.png" self.title = self.context.translate(_("Worksheets")) self.description = "" pm = getToolByName(context, "portal_membership") # this is a property of self, because self.getAnalysts returns it self.analysts = getUsers(self, ['Manager', 'LabManager', 'Analyst']) self.analysts = self.analysts.sortedByKey() bsc = getToolByName(context, 'bika_setup_catalog') templates = [t for t in bsc(portal_type = 'WorksheetTemplate', inactive_state = 'active')] self.templates = [(t.UID, t.Title) for t in templates] self.templates.sort(lambda x, y: cmp(x[1], y[1])) self.instruments = [(i.UID, i.Title) for i in bsc(portal_type = 'Instrument', inactive_state = 'active')] self.instruments.sort(lambda x, y: cmp(x[1], y[1])) self.templateinstruments = {} for t in templates: i = t.getObject().getInstrument() if i: self.templateinstruments[t.UID] = i.UID() else: self.templateinstruments[t.UID] = '' self.columns = { 'Title': {'title': _('Worksheet'), 'index': 'sortable_title'}, 'Priority': {'title': _('Priority'), 'index':'Priority', 'toggle': True}, 'Analyst': {'title': _('Analyst'), 'index':'getAnalyst', 'toggle': True}, 'Template': {'title': _('Template'), 'toggle': True}, 'Services': {'title': _('Services'), 'sortable':False, 'toggle': False}, 'SampleTypes': {'title': _('Sample Types'), 'sortable':False, 'toggle': False}, 'Instrument': {'title': _('Instrument'), 'sortable':False, 'toggle': False}, 'QC': {'title': _('QC'), 'sortable':False, 'toggle': False}, 'QCTotals': {'title': _('QC Samples(Analyses)'), 'sortable':False, 'toggle': False}, 'RoutineTotals': {'title': _('Routine Samples(Analyses)'), 'sortable':False, 'toggle': False}, 'CreationDate': {'title': PMF('Date Created'), 'toggle': True, 'index': 'created'}, 'state_title': {'title': _('State'), 'index': 'review_state'}, } self.review_states = [ {'id':'default', 'title': _('All'), 'contentFilter': {'portal_type': 'Worksheet', 'review_state':['open', 'to_be_verified', 'verified', 'rejected'], 'sort_on':'id', 'sort_order': 'reverse'}, 'transitions':[{'id':'retract'}, {'id':'verify'}, {'id':'reject'}], 'columns':['Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title']}, # getAuthenticatedMember does not work in __init__ # so 'mine' is configured further in 'folderitems' below. {'id':'mine', 'title': _('Mine'), 'contentFilter': {'portal_type': 'Worksheet', 'review_state':['open', 'to_be_verified', 'verified', 'rejected'], 'sort_on':'id', 'sort_order': 'reverse'}, 'transitions':[{'id':'retract'}, {'id':'verify'}, {'id':'reject'}], 'columns':['Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title']}, {'id':'open', 'title': _('Open'), 'contentFilter': {'portal_type': 'Worksheet', 'review_state':'open', 'sort_on':'id', 'sort_order': 'reverse'}, 'transitions':[], 'columns':['Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title']}, {'id':'to_be_verified', 'title': _('To be verified'), 'contentFilter': {'portal_type': 'Worksheet', 'review_state':'to_be_verified', 'sort_on':'id', 'sort_order': 'reverse'}, 'transitions':[{'id':'retract'}, {'id':'verify'}, {'id':'reject'}], 'columns':['Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title']}, {'id':'verified', 'title': _('Verified'), 'contentFilter': {'portal_type': 'Worksheet', 'review_state':'verified', 'sort_on':'id', 'sort_order': 'reverse'}, 'transitions':[], 'columns':['Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title']}, ]
def folderitems(self, full_objects=False): workflow = getToolByName(self.context, "portal_workflow") items = BikaListingView.folderitems(self) mtool = getToolByName(self.context, 'portal_membership') member = mtool.getAuthenticatedMember() roles = member.getRoles() hideclientlink = 'RegulatoryInspector' in roles \ and 'Manager' not in roles \ and 'LabManager' not in roles \ and 'LabClerk' not in roles for x in range(len(items)): if 'obj' not in items[x]: continue obj = items[x]['obj'] sample = obj.getSample() if getSecurityManager().checkPermission(EditResults, obj): url = obj.absolute_url() + "/manage_results" else: url = obj.absolute_url() items[x]['Client'] = obj.aq_parent.Title() if (hideclientlink is False): items[x]['replace']['Client'] = "<a href='%s'>%s</a>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) items[x]['Creator'] = self.user_fullname(obj.Creator()) items[x]['getRequestID'] = obj.getRequestID() items[x]['replace']['getRequestID'] = "<a href='%s'>%s</a>" % \ (url, items[x]['getRequestID']) items[x]['getSample'] = sample items[x]['replace']['getSample'] = \ "<a href='%s'>%s</a>" % (sample.absolute_url(), sample.Title()) if obj.getAnalysesNum(): items[x]['getAnalysesNum'] = str( obj.getAnalysesNum()[0]) + '/' + str( obj.getAnalysesNum()[1]) else: items[x]['getAnalysesNum'] = '' batch = obj.getBatch() if batch: items[x]['BatchID'] = batch.getBatchID() items[x]['replace']['BatchID'] = "<a href='%s'>%s</a>" % \ (batch.absolute_url(), items[x]['BatchID']) else: items[x]['BatchID'] = '' val = obj.Schema().getField('SubGroup').get(obj) items[x]['SubGroup'] = val.Title() if val else '' samplingdate = obj.getSample().getSamplingDate() items[x]['SamplingDate'] = self.ulocalized_time(samplingdate, long_format=1) items[x]['getDateReceived'] = self.ulocalized_time( obj.getDateReceived()) items[x]['getDatePublished'] = self.ulocalized_time( obj.getDatePublished()) deviation = sample.getSamplingDeviation() items[x]['SamplingDeviation'] = deviation and deviation.Title( ) or '' priority = obj.getPriority() items[x]['Priority'] = '' # priority.Title() items[x]['getStorageLocation'] = sample.getStorageLocation( ) and sample.getStorageLocation().Title() or '' items[x]['AdHoc'] = sample.getAdHoc() and True or '' after_icons = "" state = 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 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: items[x]['after']['getRequestID'] = after_icons items[x]['Created'] = self.ulocalized_time(obj.created()) contact = obj.getContact() if contact: items[x]['ClientContact'] = contact.Title() items[x]['replace']['ClientContact'] = "<a href='%s'>%s</a>" % \ (contact.absolute_url(), contact.Title()) else: items[x]['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) items[x]['class']['getDateSampled'] = 'provisional' sampler = sample.getSampler().strip() if sampler: items[x]['replace']['getSampler'] = self.user_fullname( sampler) if 'Sampler' in member.getRoles() and not sampler: sampler = member.id items[x]['class']['getSampler'] = 'provisional' else: datesampled = '' sampler = '' items[x]['getDateSampled'] = datesampled items[x]['getSampler'] = sampler # sampling workflow - inline edits for Sampler and Date Sampled checkPermission = self.context.portal_membership.checkPermission state = workflow.getInfoFor(obj, 'review_state') if state == 'to_be_sampled' \ and checkPermission(SampleSample, obj) \ and not samplingdate > DateTime(): items[x]['required'] = ['getSampler', 'getDateSampled'] items[x]['allow_edit'] = ['getSampler', 'getDateSampled'] samplers = getUsers(sample, ['Sampler', 'LabManager', 'Manager']) username = member.getUserName() users = [({ 'ResultValue': u, 'ResultText': samplers.getValue(u) }) for u in samplers] items[x]['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' items[x]['getSampler'] = Sampler # These don't exist on ARs # XXX This should be a list of preservers... items[x]['getPreserver'] = '' items[x]['getDatePreserved'] = '' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, obj): items[x]['required'] = ['getPreserver', 'getDatePreserved'] items[x]['allow_edit'] = ['getPreserver', 'getDatePreserved'] preservers = getUsers(obj, ['Preserver', 'LabManager', 'Manager']) username = member.getUserName() users = [({ 'ResultValue': u, 'ResultText': preservers.getValue(u) }) for u in preservers] items[x]['choices'] = {'getPreserver': users} preserver = username in preservers.keys() and username or '' items[x]['getPreserver'] = preserver items[x]['getDatePreserved'] = self.ulocalized_time( DateTime(), long_format=1) items[x]['class']['getPreserver'] = 'provisional' items[x]['class']['getDatePreserved'] = 'provisional' # Submitting user may not verify results if items[x]['review_state'] == 'to_be_verified' and \ not checkPermission(VerifyOwnResults, obj): self_submitted = False try: review_history = list( 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: items[x]['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 # Hide Preservation/Sampling workflow actions if the edit columns # are not displayed. toggle_cols = self.get_toggle_cols() new_states = [] for i, state in enumerate(self.review_states): if state['id'] == self.review_state: if 'getSampler' not in toggle_cols \ or 'getDateSampled' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('sample') else: state['hide_transitions'] = [ 'sample', ] if 'getPreserver' not in toggle_cols \ or 'getDatePreserved' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('preserve') else: state['hide_transitions'] = [ 'preserve', ] new_states.append(state) self.review_states = new_states return items
def folderitems(self, full_objects=False): mtool = getToolByName(self.context, 'portal_membership') workflow = getToolByName(self.context, 'portal_workflow') checkPermission = mtool.checkPermission edit_states = [ 'sample_registered', 'to_be_sampled', 'sampled', 'to_be_preserved', 'sample_due', 'attachment_due', 'sample_received', 'to_be_verified' ] if self.context.portal_type == 'AnalysisRequest': self.sample = self.context.getSample() else: self.sample = self.context self.allow_edit = checkPermission(EditSamplePartition, self.sample) \ and workflow.getInfoFor(self.sample, 'review_state') in edit_states \ and workflow.getInfoFor(self.sample, 'cancellation_state') == 'active' self.show_select_column = self.allow_edit if self.allow_edit == False: self.review_states[0]['custom_actions'] = [] bsc = getToolByName(self.context, 'bika_setup_catalog') containers = [({ 'ResultValue': o.UID, 'ResultText': o.title }) for o in bsc(portal_type="Container", inactive_state="active")] preservations = [({ 'ResultValue': o.UID, 'ResultText': o.title }) for o in bsc(portal_type="Preservation", inactive_state="active")] parts = [ p for p in self.sample.objectValues() if p.portal_type == 'SamplePartition' ] items = [] for part in parts: # this folderitems doesn't subclass from the bika_listing.py # so we create items from scratch item = { 'obj': part, 'id': part.id, 'uid': part.UID(), 'title': part.Title(), 'type_class': 'contenttype-SamplePartition', 'url': part.aq_parent.absolute_url(), 'relative_url': part.aq_parent.absolute_url(), 'view_url': part.aq_parent.absolute_url(), 'created': self.ulocalized_time(part.created()), 'replace': {}, 'before': {}, 'after': {}, 'choices': {}, 'class': {}, 'allow_edit': [], 'required': [], } state = workflow.getInfoFor(part, 'review_state') item['state_class'] = 'state-' + state item['state_title'] = _(state) item['PartTitle'] = part.getId() container = part.getContainer() if self.allow_edit: item['getContainer'] = container and container.UID() or '' else: item['getContainer'] = container and container.Title() or '' preservation = part.getPreservation() if self.allow_edit: item['getPreservation'] = preservation and preservation.UID( ) or '' else: item['getPreservation'] = preservation and preservation.Title( ) or '' ## sampler = part.getSampler().strip() ## item['getSampler'] = \ ## sampler and self.user_fullname(sampler) or '' ## datesampled = part.getDateSampled() ## item['getDateSampled'] = \ ## datesampled and self.ulocalized_time(datesampled) or '' preserver = part.getPreserver().strip() item['getPreserver'] = \ preserver and self.user_fullname(preserver) or '' datepreserved = part.getDatePreserved() item['getDatePreserved'] = \ datepreserved and self.ulocalized_time(datepreserved, long_format=False) or '' disposaldate = part.getDisposalDate() item['getDisposalDate'] = \ disposaldate and self.ulocalized_time(disposaldate, long_format=False) or '' # inline edits for Container and Preservation if self.allow_edit: item['allow_edit'] = ['getContainer', 'getPreservation'] item['choices']['getPreservation'] = preservations item['choices']['getContainer'] = containers # inline edits for Sampler and Date Sampled ## checkPermission = self.context.portal_membership.checkPermission ## if checkPermission(SampleSample, part) \ ## and not samplingdate > DateTime(): ## item['required'] += ['getSampler', 'getDateSampled'] ## item['allow_edit'] += ['getSampler', 'getDateSampled'] ## samplers = getUsers(part, ['Sampler', 'LabManager', 'Manager']) ## getAuthenticatedMember = part.portal_membership.getAuthenticatedMember ## username = getAuthenticatedMember().getUserName() ## users = [({'ResultValue': u, 'ResultText': samplers.getValue(u)}) ## for u in samplers] ## item['choices']['getSampler'] = users ## item['getSampler'] = sampler and sampler or \ ## (username in samplers.keys() and username) or '' ## item['getDateSampled'] = item['getDateSampled'] \ ## or DateTime().strftime(self.date_format_short) ## item['class']['getSampler'] = 'provisional' ## item['class']['getDateSampled'] = 'provisional' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, part): item['required'] += ['getPreserver', 'getDatePreserved'] if self.allow_edit: item['allow_edit'] += ['getPreserver', 'getDatePreserved'] preservers = getUsers(part, ['Preserver', 'LabManager', 'Manager']) getAuthenticatedMember = part.portal_membership.getAuthenticatedMember username = getAuthenticatedMember().getUserName() users = [({ 'ResultValue': u, 'ResultText': preservers.getValue(u) }) for u in preservers] item['choices']['getPreserver'] = users item['getPreserver'] = preserver and preserver or \ (username in preservers.keys() and username) or '' item['getDatePreserved'] = item['getDatePreserved'] \ or DateTime().strftime(self.date_format_short) item['class']['getPreserver'] = 'provisional' item['class']['getDatePreserved'] = 'provisional' items.append(item) items = sorted(items, key=itemgetter('id')) return items
def folderitems(self, full_objects=False): workflow = getToolByName(self.context, "portal_workflow") items = BikaListingView.folderitems(self) mtool = getToolByName(self.context, 'portal_membership') member = mtool.getAuthenticatedMember() translate = self.context.translate roles = member.getRoles() hideclientlink = 'RegulatoryInspector' in roles \ and 'Manager' not in roles \ and 'LabManager' not in roles \ and 'LabClerk' not in roles for x in range(len(items)): if not items[x].has_key('obj'): continue obj = items[x]['obj'] items[x]['replace']['getSampleID'] = "<a href='%s'>%s</a>" % \ (items[x]['url'], obj.getSampleID()) items[x]['replace']['Requests'] = ",".join([ "<a href='%s'>%s</a>" % (o.absolute_url(), o.Title()) for o in obj.getAnalysisRequests() ]) items[x]['Client'] = obj.aq_parent.Title() if hideclientlink == False: items[x]['replace']['Client'] = "<a href='%s'>%s</a>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) items[x]['Creator'] = self.user_fullname(obj.Creator()) items[x]['DateReceived'] = self.ulocalized_time( obj.getDateReceived()) deviation = obj.getSamplingDeviation() items[x]['SamplingDeviation'] = deviation and deviation.Title( ) or '' items[x]['getStorageLocation'] = obj.getStorageLocation( ) and obj.getStorageLocation().Title() or '' items[x]['AdHoc'] = obj.getAdHoc() and True or '' items[x]['Created'] = self.ulocalized_time(obj.created()) samplingdate = obj.getSamplingDate() items[x]['getSamplingDate'] = self.ulocalized_time(samplingdate, long_format=1) after_icons = '' if obj.getSampleType().getHazardous(): after_icons += "<img title='%s' " \ "src='%s/++resource++bika.lims.images/hazardous.png'>" % \ (t(_("Hazardous")), self.portal_url) if obj.getSamplingDate() > DateTime(): after_icons += "<img title='%s' " \ "src='%s/++resource++bika.lims.images/calendar.png' >" % \ (t(_("Future dated sample")), self.portal_url) if after_icons: items[x]['after']['getSampleID'] = after_icons SamplingWorkflowEnabled =\ self.context.bika_setup.getSamplingWorkflowEnabled() if not samplingdate > DateTime() \ and SamplingWorkflowEnabled: datesampled = self.ulocalized_time(obj.getDateSampled()) if not datesampled: datesampled = self.ulocalized_time(DateTime()) items[x]['class']['getDateSampled'] = 'provisional' sampler = obj.getSampler().strip() if sampler: items[x]['replace']['getSampler'] = self.user_fullname( sampler) if 'Sampler' in member.getRoles() and not sampler: sampler = member.id items[x]['class']['getSampler'] = 'provisional' else: datesampled = '' sampler = '' items[x]['getDateSampled'] = datesampled items[x]['getSampler'] = sampler # sampling workflow - inline edits for Sampler and Date Sampled checkPermission = self.context.portal_membership.checkPermission state = workflow.getInfoFor(obj, 'review_state') if state == 'to_be_sampled' \ and checkPermission(SampleSample, obj) \ and not samplingdate > DateTime(): items[x]['required'] = ['getSampler', 'getDateSampled'] items[x]['allow_edit'] = ['getSampler', 'getDateSampled'] samplers = getUsers(obj, ['Sampler', 'LabManager', 'Manager']) getAuthenticatedMember = self.context.portal_membership.getAuthenticatedMember username = getAuthenticatedMember().getUserName() users = [({ 'ResultValue': u, 'ResultText': samplers.getValue(u) }) for u in samplers] items[x]['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' items[x]['getSampler'] = Sampler # These don't exist on samples # the columns exist just to set "preserve" transition from lists. # XXX This should be a list of preservers... items[x]['getPreserver'] = '' items[x]['getDatePreserved'] = '' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, obj): items[x]['required'] = ['getPreserver', 'getDatePreserved'] items[x]['allow_edit'] = ['getPreserver', 'getDatePreserved'] preservers = getUsers(obj, ['Preserver', 'LabManager', 'Manager']) getAuthenticatedMember = self.context.portal_membership.getAuthenticatedMember username = getAuthenticatedMember().getUserName() users = [({ 'ResultValue': u, 'ResultText': preservers.getValue(u) }) for u in preservers] items[x]['choices'] = {'getPreserver': users} preserver = username in preservers.keys() and username or '' items[x]['getPreserver'] = preserver items[x]['getDatePreserved'] = self.ulocalized_time(DateTime()) items[x]['class']['getPreserver'] = 'provisional' items[x]['class']['getDatePreserved'] = 'provisional' # Hide Preservation/Sampling workflow actions if the edit columns # are not displayed. toggle_cols = self.get_toggle_cols() new_states = [] for i, state in enumerate(self.review_states): if state['id'] == self.review_state: if 'getSampler' not in toggle_cols \ or 'getDateSampled' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('sample') else: state['hide_transitions'] = [ 'sample', ] if 'getPreserver' not in toggle_cols \ or 'getDatePreserved' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('preserve') else: state['hide_transitions'] = [ 'preserve', ] new_states.append(state) self.review_states = new_states return items
def select_analyst(self, allow_blank=False, style=None): self.style = style self.analysts = getUsers(self.context, ['Manager', 'Analyst', 'LabManager'], allow_blank) return self.select_analyst_pt()
def getSamplers(self): return getUsers(self, ['LabManager', 'Sampler'])
def getSamplers(self): return getUsers(self, ["LabManager", "Sampler"])
def folderitems(self, full_objects=False): workflow = getToolByName(self.context, "portal_workflow") items = BikaListingView.folderitems(self) mtool = getToolByName(self.context, 'portal_membership') member = mtool.getAuthenticatedMember() roles = member.getRoles() hideclientlink = 'RegulatoryInspector' in roles \ and 'Manager' not in roles \ and 'LabManager' not in roles \ and 'LabClerk' not in roles for x in range(len(items)): if 'obj' not in items[x]: continue obj = items[x]['obj'] sample = obj.getSample() if getSecurityManager().checkPermission(EditResults, obj): url = obj.absolute_url() + "/manage_results" else: url = obj.absolute_url() items[x]['Client'] = obj.aq_parent.Title() if (hideclientlink is False): items[x]['replace']['Client'] = "<a href='%s'>%s</a>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) items[x]['Creator'] = self.user_fullname(obj.Creator()) items[x]['getRequestID'] = obj.getRequestID() items[x]['replace']['getRequestID'] = "<a href='%s'>%s</a>" % \ (url, items[x]['getRequestID']) items[x]['getSample'] = sample items[x]['replace']['getSample'] = \ "<a href='%s'>%s</a>" % (sample.absolute_url(), sample.Title()) if obj.getAnalysesNum(): items[x]['getAnalysesNum'] = str(obj.getAnalysesNum()[0]) + '/' + str(obj.getAnalysesNum()[1]) else: items[x]['getAnalysesNum'] = '' batch = obj.getBatch() if batch: items[x]['BatchID'] = batch.getBatchID() items[x]['replace']['BatchID'] = "<a href='%s'>%s</a>" % \ (batch.absolute_url(), items[x]['BatchID']) else: items[x]['BatchID'] = '' val = obj.Schema().getField('SubGroup').get(obj) items[x]['SubGroup'] = val.Title() if val else '' samplingdate = obj.getSample().getSamplingDate() items[x]['SamplingDate'] = self.ulocalized_time(samplingdate, long_format=1) items[x]['getDateReceived'] = self.ulocalized_time(obj.getDateReceived()) items[x]['getDatePublished'] = self.ulocalized_time(obj.getDatePublished()) deviation = sample.getSamplingDeviation() items[x]['SamplingDeviation'] = deviation and deviation.Title() or '' priority = obj.getPriority() items[x]['Priority'] = '' # priority.Title() items[x]['getStorageLocation'] = sample.getStorageLocation() and sample.getStorageLocation().Title() or '' items[x]['AdHoc'] = sample.getAdHoc() and True or '' after_icons = "" state = 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 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: items[x]['after']['getRequestID'] = after_icons items[x]['Created'] = self.ulocalized_time(obj.created()) contact = obj.getContact() if contact: items[x]['ClientContact'] = contact.Title() items[x]['replace']['ClientContact'] = "<a href='%s'>%s</a>" % \ (contact.absolute_url(), contact.Title()) else: items[x]['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) items[x]['class']['getDateSampled'] = 'provisional' sampler = sample.getSampler().strip() if sampler: items[x]['replace']['getSampler'] = self.user_fullname(sampler) if 'Sampler' in member.getRoles() and not sampler: sampler = member.id items[x]['class']['getSampler'] = 'provisional' else: datesampled = '' sampler = '' items[x]['getDateSampled'] = datesampled items[x]['getSampler'] = sampler # sampling workflow - inline edits for Sampler and Date Sampled checkPermission = self.context.portal_membership.checkPermission state = workflow.getInfoFor(obj, 'review_state') if state == 'to_be_sampled' \ and checkPermission(SampleSample, obj) \ and not samplingdate > DateTime(): items[x]['required'] = ['getSampler', 'getDateSampled'] items[x]['allow_edit'] = ['getSampler', 'getDateSampled'] samplers = getUsers(sample, ['Sampler', 'LabManager', 'Manager']) username = member.getUserName() users = [({'ResultValue': u, 'ResultText': samplers.getValue(u)}) for u in samplers] items[x]['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' items[x]['getSampler'] = Sampler # These don't exist on ARs # XXX This should be a list of preservers... items[x]['getPreserver'] = '' items[x]['getDatePreserved'] = '' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, obj): items[x]['required'] = ['getPreserver', 'getDatePreserved'] items[x]['allow_edit'] = ['getPreserver', 'getDatePreserved'] preservers = getUsers(obj, ['Preserver', 'LabManager', 'Manager']) username = member.getUserName() users = [({'ResultValue': u, 'ResultText': preservers.getValue(u)}) for u in preservers] items[x]['choices'] = {'getPreserver': users} preserver = username in preservers.keys() and username or '' items[x]['getPreserver'] = preserver items[x]['getDatePreserved'] = self.ulocalized_time( DateTime(), long_format=1) items[x]['class']['getPreserver'] = 'provisional' items[x]['class']['getDatePreserved'] = 'provisional' # Submitting user may not verify results if items[x]['review_state'] == 'to_be_verified' and \ not checkPermission(VerifyOwnResults, obj): self_submitted = False try: review_history = list(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: items[x]['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 # Hide Preservation/Sampling workflow actions if the edit columns # are not displayed. toggle_cols = self.get_toggle_cols() new_states = [] for i, state in enumerate(self.review_states): if state['id'] == self.review_state: if 'getSampler' not in toggle_cols \ or 'getDateSampled' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('sample') else: state['hide_transitions'] = ['sample', ] if 'getPreserver' not in toggle_cols \ or 'getDatePreserved' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('preserve') else: state['hide_transitions'] = ['preserve', ] new_states.append(state) self.review_states = new_states return items
def __init__(self, context, request): super(WorksheetFolderListingView, self).__init__(context, request) self.catalog = 'bika_catalog' self.contentFilter = { 'portal_type': 'Worksheet', 'review_state': ['open', 'to_be_verified', 'verified', 'rejected'], 'sort_on': 'id', 'sort_order': 'reverse' } self.context_actions = { _('Add'): { 'url': 'worksheet_add', 'icon': '++resource++bika.lims.images/add.png', 'class': 'worksheet_add' } } self.show_table_only = False self.show_sort_column = False self.show_select_row = False self.show_select_all_checkbox = True self.show_select_column = True self.pagesize = 25 self.restrict_results = False request.set('disable_border', 1) self.icon = self.portal_url + "/++resource++bika.lims.images/worksheet_big.png" self.title = self.context.translate(_("Worksheets")) self.description = "" pm = getToolByName(context, "portal_membership") # this is a property of self, because self.getAnalysts returns it self.analysts = getUsers(self, ['Manager', 'LabManager', 'Analyst']) self.analysts = self.analysts.sortedByKey() bsc = getToolByName(context, 'bika_setup_catalog') templates = [ t for t in bsc(portal_type='WorksheetTemplate', inactive_state='active') ] self.templates = [(t.UID, t.Title) for t in templates] self.templates.sort(lambda x, y: cmp(x[1], y[1])) self.instruments = [ (i.UID, i.Title) for i in bsc(portal_type='Instrument', inactive_state='active') ] self.instruments.sort(lambda x, y: cmp(x[1], y[1])) self.templateinstruments = {} for t in templates: i = t.getObject().getInstrument() if i: self.templateinstruments[t.UID] = i.UID() else: self.templateinstruments[t.UID] = '' self.columns = { 'Title': { 'title': _('Worksheet'), 'index': 'sortable_title' }, 'Priority': { 'title': _('Priority'), 'index': 'Priority', 'toggle': True }, 'Analyst': { 'title': _('Analyst'), 'index': 'getAnalyst', 'toggle': True }, 'Template': { 'title': _('Template'), 'toggle': True }, 'Services': { 'title': _('Services'), 'sortable': False, 'toggle': False }, 'SampleTypes': { 'title': _('Sample Types'), 'sortable': False, 'toggle': False }, 'Instrument': { 'title': _('Instrument'), 'sortable': False, 'toggle': False }, 'QC': { 'title': _('QC'), 'sortable': False, 'toggle': False }, 'QCTotals': { 'title': _('QC Samples(Analyses)'), 'sortable': False, 'toggle': False }, 'RoutineTotals': { 'title': _('Routine Samples(Analyses)'), 'sortable': False, 'toggle': False }, 'CreationDate': { 'title': PMF('Date Created'), 'toggle': True, 'index': 'created' }, 'state_title': { 'title': _('State'), 'index': 'review_state' }, } self.review_states = [ { 'id': 'default', 'title': _('All'), 'contentFilter': { 'portal_type': 'Worksheet', 'review_state': ['open', 'to_be_verified', 'verified', 'rejected'], 'sort_on': 'id', 'sort_order': 'reverse' }, 'transitions': [{ 'id': 'retract' }, { 'id': 'verify' }, { 'id': 'reject' }], 'columns': [ 'Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title' ] }, # getAuthenticatedMember does not work in __init__ # so 'mine' is configured further in 'folderitems' below. { 'id': 'mine', 'title': _('Mine'), 'contentFilter': { 'portal_type': 'Worksheet', 'review_state': ['open', 'to_be_verified', 'verified', 'rejected'], 'sort_on': 'id', 'sort_order': 'reverse' }, 'transitions': [{ 'id': 'retract' }, { 'id': 'verify' }, { 'id': 'reject' }], 'columns': [ 'Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title' ] }, { 'id': 'open', 'title': _('Open'), 'contentFilter': { 'portal_type': 'Worksheet', 'review_state': 'open', 'sort_on': 'id', 'sort_order': 'reverse' }, 'transitions': [], 'columns': [ 'Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title' ] }, { 'id': 'to_be_verified', 'title': _('To be verified'), 'contentFilter': { 'portal_type': 'Worksheet', 'review_state': 'to_be_verified', 'sort_on': 'id', 'sort_order': 'reverse' }, 'transitions': [{ 'id': 'retract' }, { 'id': 'verify' }, { 'id': 'reject' }], 'columns': [ 'Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title' ] }, { 'id': 'verified', 'title': _('Verified'), 'contentFilter': { 'portal_type': 'Worksheet', 'review_state': 'verified', 'sort_on': 'id', 'sort_order': 'reverse' }, 'transitions': [], 'columns': [ 'Title', 'Priority', 'Analyst', 'Template', 'Services', 'SampleTypes', 'Instrument', 'QC', 'QCTotals', 'RoutineTotals', 'CreationDate', 'state_title' ] }, ]
def folderitems(self, full_objects = False): workflow = getToolByName(self.context, "portal_workflow") items = BikaListingView.folderitems(self) mtool = getToolByName(self.context, 'portal_membership') member = mtool.getAuthenticatedMember() translate = self.context.translate roles = member.getRoles() hideclientlink = 'RegulatoryInspector' in roles \ and 'Manager' not in roles \ and 'LabManager' not in roles \ and 'LabClerk' not in roles for x in range(len(items)): if not items[x].has_key('obj'): continue obj = items[x]['obj'] items[x]['replace']['getSampleID'] = "<a href='%s'>%s</a>" % \ (items[x]['url'], obj.getSampleID()) items[x]['replace']['Requests'] = ",".join( ["<a href='%s'>%s</a>" % (o.absolute_url(), o.Title()) for o in obj.getAnalysisRequests()]) items[x]['Client'] = obj.aq_parent.Title() if hideclientlink == False: items[x]['replace']['Client'] = "<a href='%s'>%s</a>" % \ (obj.aq_parent.absolute_url(), obj.aq_parent.Title()) items[x]['Creator'] = self.user_fullname(obj.Creator()) items[x]['DateReceived'] = self.ulocalized_time(obj.getDateReceived()) deviation = obj.getSamplingDeviation() items[x]['SamplingDeviation'] = deviation and deviation.Title() or '' items[x]['getStorageLocation'] = obj.getStorageLocation() and obj.getStorageLocation().Title() or '' items[x]['AdHoc'] = obj.getAdHoc() and True or '' items[x]['Created'] = self.ulocalized_time(obj.created()) samplingdate = obj.getSamplingDate() items[x]['getSamplingDate'] = self.ulocalized_time(samplingdate, long_format=1) after_icons = '' if obj.getSampleType().getHazardous(): after_icons += "<img title='%s' " \ "src='%s/++resource++bika.lims.images/hazardous.png'>" % \ (t(_("Hazardous")), self.portal_url) if obj.getSamplingDate() > DateTime(): after_icons += "<img title='%s' " \ "src='%s/++resource++bika.lims.images/calendar.png' >" % \ (t(_("Future dated sample")), self.portal_url) if after_icons: items[x]['after']['getSampleID'] = after_icons SamplingWorkflowEnabled =\ self.context.bika_setup.getSamplingWorkflowEnabled() if not samplingdate > DateTime() \ and SamplingWorkflowEnabled: datesampled = self.ulocalized_time(obj.getDateSampled()) if not datesampled: datesampled = self.ulocalized_time(DateTime()) items[x]['class']['getDateSampled'] = 'provisional' sampler = obj.getSampler().strip() if sampler: items[x]['replace']['getSampler'] = self.user_fullname(sampler) if 'Sampler' in member.getRoles() and not sampler: sampler = member.id items[x]['class']['getSampler'] = 'provisional' else: datesampled = '' sampler = '' items[x]['getDateSampled'] = datesampled items[x]['getSampler'] = sampler # sampling workflow - inline edits for Sampler and Date Sampled checkPermission = self.context.portal_membership.checkPermission state = workflow.getInfoFor(obj, 'review_state') if state == 'to_be_sampled' \ and checkPermission(SampleSample, obj) \ and not samplingdate > DateTime(): items[x]['required'] = ['getSampler', 'getDateSampled'] items[x]['allow_edit'] = ['getSampler', 'getDateSampled'] samplers = getUsers(obj, ['Sampler', 'LabManager', 'Manager']) getAuthenticatedMember = self.context.portal_membership.getAuthenticatedMember username = getAuthenticatedMember().getUserName() users = [({'ResultValue': u, 'ResultText': samplers.getValue(u)}) for u in samplers] items[x]['choices'] = {'getSampler': users} Sampler = sampler and sampler or \ (username in samplers.keys() and username) or '' items[x]['getSampler'] = Sampler # These don't exist on samples # the columns exist just to set "preserve" transition from lists. # XXX This should be a list of preservers... items[x]['getPreserver'] = '' items[x]['getDatePreserved'] = '' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, obj): items[x]['required'] = ['getPreserver', 'getDatePreserved'] items[x]['allow_edit'] = ['getPreserver', 'getDatePreserved'] preservers = getUsers(obj, ['Preserver', 'LabManager', 'Manager']) getAuthenticatedMember = self.context.portal_membership.getAuthenticatedMember username = getAuthenticatedMember().getUserName() users = [({'ResultValue': u, 'ResultText': preservers.getValue(u)}) for u in preservers] items[x]['choices'] = {'getPreserver': users} preserver = username in preservers.keys() and username or '' items[x]['getPreserver'] = preserver items[x]['getDatePreserved'] = self.ulocalized_time(DateTime()) items[x]['class']['getPreserver'] = 'provisional' items[x]['class']['getDatePreserved'] = 'provisional' # Hide Preservation/Sampling workflow actions if the edit columns # are not displayed. toggle_cols = self.get_toggle_cols() new_states = [] for i,state in enumerate(self.review_states): if state['id'] == self.review_state: if 'getSampler' not in toggle_cols \ or 'getDateSampled' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('sample') else: state['hide_transitions'] = ['sample',] if 'getPreserver' not in toggle_cols \ or 'getDatePreserved' not in toggle_cols: if 'hide_transitions' in state: state['hide_transitions'].append('preserve') else: state['hide_transitions'] = ['preserve',] new_states.append(state) self.review_states = new_states return items
def folderitems(self, full_objects = False): mtool = getToolByName(self.context, 'portal_membership') workflow = getToolByName(self.context, 'portal_workflow') checkPermission = mtool.checkPermission edit_states = ['sample_registered', 'to_be_sampled', 'sampled', 'to_be_preserved', 'sample_due', 'attachment_due', 'sample_received', 'to_be_verified'] if self.context.portal_type == 'AnalysisRequest': self.sample = self.context.getSample() else: self.sample = self.context self.allow_edit = checkPermission(EditSamplePartition, self.sample) \ and workflow.getInfoFor(self.sample, 'review_state') in edit_states \ and workflow.getInfoFor(self.sample, 'cancellation_state') == 'active' self.show_select_column = self.allow_edit if self.allow_edit == False: self.review_states[0]['custom_actions'] = [] bsc = getToolByName(self.context, 'bika_setup_catalog') containers = [({'ResultValue':o.UID, 'ResultText':o.title}) for o in bsc(portal_type="Container", inactive_state="active")] preservations = [({'ResultValue':o.UID, 'ResultText':o.title}) for o in bsc(portal_type="Preservation", inactive_state="active")] parts = [p for p in self.sample.objectValues() if p.portal_type == 'SamplePartition'] items = [] for part in parts: # this folderitems doesn't subclass from the bika_listing.py # so we create items from scratch item = { 'obj': part, 'id': part.id, 'uid': part.UID(), 'title': part.Title(), 'type_class': 'contenttype-SamplePartition', 'url': part.aq_parent.absolute_url(), 'relative_url': part.aq_parent.absolute_url(), 'view_url': part.aq_parent.absolute_url(), 'created': self.ulocalized_time(part.created()), 'replace': {}, 'before': {}, 'after': {}, 'choices': {}, 'class': {}, 'allow_edit': [], 'required': [], } state = workflow.getInfoFor(part, 'review_state') item['state_class'] = 'state-'+state item['state_title'] = _(state) item['PartTitle'] = part.getId() container = part.getContainer() if self.allow_edit: item['getContainer'] = container and container.UID() or '' else: item['getContainer'] = container and container.Title() or '' preservation = part.getPreservation() if self.allow_edit: item['getPreservation'] = preservation and preservation.UID() or '' else: item['getPreservation'] = preservation and preservation.Title() or '' ## sampler = part.getSampler().strip() ## item['getSampler'] = \ ## sampler and self.user_fullname(sampler) or '' ## datesampled = part.getDateSampled() ## item['getDateSampled'] = \ ## datesampled and self.ulocalized_time(datesampled) or '' preserver = part.getPreserver().strip() item['getPreserver'] = \ preserver and self.user_fullname(preserver) or '' datepreserved = part.getDatePreserved() item['getDatePreserved'] = \ datepreserved and self.ulocalized_time(datepreserved, long_format=False) or '' disposaldate = part.getDisposalDate() item['getDisposalDate'] = \ disposaldate and self.ulocalized_time(disposaldate, long_format=False) or '' # inline edits for Container and Preservation if self.allow_edit: item['allow_edit'] = ['getContainer', 'getPreservation'] item['choices']['getPreservation'] = preservations item['choices']['getContainer'] = containers # inline edits for Sampler and Date Sampled ## checkPermission = self.context.portal_membership.checkPermission ## if checkPermission(SampleSample, part) \ ## and not samplingdate > DateTime(): ## item['required'] += ['getSampler', 'getDateSampled'] ## item['allow_edit'] += ['getSampler', 'getDateSampled'] ## samplers = getUsers(part, ['Sampler', 'LabManager', 'Manager']) ## getAuthenticatedMember = part.portal_membership.getAuthenticatedMember ## username = getAuthenticatedMember().getUserName() ## users = [({'ResultValue': u, 'ResultText': samplers.getValue(u)}) ## for u in samplers] ## item['choices']['getSampler'] = users ## item['getSampler'] = sampler and sampler or \ ## (username in samplers.keys() and username) or '' ## item['getDateSampled'] = item['getDateSampled'] \ ## or DateTime().strftime(self.date_format_short) ## item['class']['getSampler'] = 'provisional' ## item['class']['getDateSampled'] = 'provisional' # inline edits for Preserver and Date Preserved checkPermission = self.context.portal_membership.checkPermission if checkPermission(PreserveSample, part): item['required'] += ['getPreserver', 'getDatePreserved'] if self.allow_edit: item['allow_edit'] += ['getPreserver', 'getDatePreserved'] preservers = getUsers(part, ['Preserver', 'LabManager', 'Manager']) getAuthenticatedMember = part.portal_membership.getAuthenticatedMember username = getAuthenticatedMember().getUserName() users = [({'ResultValue': u, 'ResultText': preservers.getValue(u)}) for u in preservers] item['choices']['getPreserver'] = users item['getPreserver'] = preserver and preserver or \ (username in preservers.keys() and username) or '' item['getDatePreserved'] = item['getDatePreserved'] \ or DateTime().strftime(self.date_format_short) item['class']['getPreserver'] = 'provisional' item['class']['getDatePreserved'] = 'provisional' items.append(item) items = sorted(items, key=itemgetter('id')) return items