Beispiel #1
0
 def ar_analysis_values(self):
     ret = []
     analyses = self.context.getAnalyses(is_active=True)
     for proxy in analyses:
         analysis = proxy.getObject()
         if proxy.review_state == 'retracted':
             # these are scraped up when Retested analyses are found below.
             continue
         # things that are manually inserted into the analysis.
         # These things will be included even if they are not present in
         # include_fields in the request.
         method = analysis.getMethod()
         analysis_data = {
             "Uncertainty": analysis.getUncertainty(),
             "Method": method.Title() if method else '',
             "Unit": analysis.getUnit(),
         }
         # Place all schema fields ino the result.
         analysis_data.update(load_brain_metadata(proxy, []))
         # Place all schema fields ino the result.
         analysis_data.update(load_field_values(analysis, []))
         # call any adapters that care to modify the Analysis data.
         # adapters = getAdapters((analysis, ), IJSONReadExtender)
         # for name, adapter in adapters:
         #     adapter(request, analysis_data)
         if not self.include_fields or "transitions" in self.include_fields:
             analysis_data['transitions'] = get_workflow_actions(analysis)
         retest_of = analysis.getRetestOf()
         if retest_of:
             prevs = [{'created': str(retest_of.created()),
                       'Result': retest_of.getResult(),
                       'InterimFields': retest_of.getInterimFields()}]
             analysis_data['Previous Results'] = prevs
         ret.append(analysis_data)
     return ret
Beispiel #2
0
 def ar_analysis_values(self):
     ret = []
     analyses = self.context.getAnalyses(cancellation_state='active')
     for proxy in analyses:
         analysis = proxy.getObject()
         service = analysis.getService()
         if proxy.review_state == 'retracted':
             # these are scraped up when Retested analyses are found below.
             continue
         # things that are manually inserted into the analysis.
         # These things will be included even if they are not present in
         # include_fields in the request.
         method = analysis.getMethod()
         if not method:
             method = service.getMethod()
         service = analysis.getService()
         hs = hasattr(analysis, "specification")
         analysis_data = {
             "Uncertainty": service.getUncertainty(analysis.getResult()),
             "Method": method.Title() if method else '',
             "specification": analysis.specification if hs else {},
             "Unit": service.getUnit(),
         }
         # Place all schema fields ino the result.
         analysis_data.update(load_brain_metadata(proxy, []))
         # Place all schema fields ino the result.
         analysis_data.update(load_field_values(analysis, []))
         # call any adapters that care to modify the Analysis data.
         # adapters = getAdapters((analysis, ), IJSONReadExtender)
         # for name, adapter in adapters:
         #     adapter(request, analysis_data)
         if not self.include_fields or "transitions" in self.include_fields:
             analysis_data['transitions'] = get_workflow_actions(analysis)
         if analysis.getRetested():
             retracted = self.context.getAnalyses(review_state='retracted',
                                         title=analysis.Title(),
                                         full_objects=True)
             prevs = sorted(retracted, key=lambda item: item.created())
             prevs = [{'created': str(p.created()),
                       'Result': p.getResult(),
                       'InterimFields': p.getInterimFields()}
                      for p in prevs]
             analysis_data['Previous Results'] = prevs
         ret.append(analysis_data)
     return ret
Beispiel #3
0
    def __call__(self):
        form = self.request.form
        plone.protect.CheckAuthenticator(form)
        self.context = aq_inner(self.context)
        workflow = getToolByName(self.context, 'portal_workflow')
        bc = getToolByName(self.context, 'bika_catalog')
        rc = getToolByName(self.context, REFERENCE_CATALOG)
        translate = self.context.translate
        checkPermission = self.context.portal_membership.checkPermission

        # use came_from to decide which UI action was clicked.
        # "workflow_action" is the action name specified in the
        # portal_workflow transition url.
        came_from = "workflow_action"
        action = form.get(came_from, '')
        if not action and not form.get('bika_listing_filter_bar_submit', ''):
            # workflow_action_button is the action name specified in
            # the bika_listing_view table buttons.
            came_from = "workflow_action_button"
            action = form.get('workflow_action_id', '')
            if not action:
                if self.destination_url == "":
                    self.destination_url = self.request.get_header(
                        "referer", self.context.absolute_url())
                self.request.response.redirect(self.destination_url)
                return

        if action == "sample":
            message = None
            objects = AnalysisRequestWorkflowAction._get_selected_items(self)
            transitioned = {'to_be_preserved': [], 'sample_due': []}
            for obj_uid, obj in objects.items():
                if obj.portal_type == "AnalysisRequest":
                    ar = obj
                    sample = obj.getSample()
                else:
                    sample = obj
                    ar = sample.aq_parent
                # can't transition inactive items
                if workflow.getInfoFor(sample, 'inactive_state',
                                       '') == 'inactive':
                    message = _('Sample %s is inactive' % sample.Title())
                    self.context.plone_utils.addPortalMessage(message, 'error')
                    continue
                transitions = [a['id'] for a in get_workflow_actions(sample)]
                if 'sample' not in transitions:
                    message = _('"Sample" is not a valid action for %s' % \
                                                                sample.Title())
                    self.context.plone_utils.addPortalMessage(message, 'error')
                    continue

                # grab this object's Sampler and DateSampled from the form
                # (if the columns are available and edit controls exist)
                if 'getSampler' in form and 'getDateSampled' in form:
                    Sampler = ''
                    if len(form['getSampler']) > 0 \
                            and form['getSampler'][0].get(obj_uid):
                        Sampler = form['getSampler'][0][obj_uid].strip()
                    DateSampled = ''
                    if len(form['getDateSampled']) > 0 \
                            and form['getDateSampled'][0].get(obj_uid):
                        DateSampled = form['getDateSampled'][0][obj_uid].strip(
                        )
                else:
                    continue

                # write them to the sample
                if Sampler:
                    sample.setSampler(Sampler)
                else:
                    Sampler = sample.getSampler()
                if DateSampled:
                    sample.setDateSampled(DateSampled)
                else:
                    DateSampled = sample.getDateSampled()
                sample.reindexObject()
                ars = sample.getAnalysisRequests()
                # Analyses and AnalysisRequets have calculated fields
                # that are indexed; re-index all these objects.
                for ar in ars:
                    ar.reindexObject()
                    analyses = sample.getAnalyses(
                        {'review_state': 'to_be_sampled'})
                    for a in analyses:
                        a.getObject().reindexObject()

                if Sampler and DateSampled:
                    workflow.doActionFor(sample, action)
                    new_state = workflow.getInfoFor(sample, 'review_state')
                    doActionFor(ar, action)
                    transitioned[new_state].append(sample.Title())
                else:
                    message = _('Both Sampler and Date Sampled are required')
                    self.context.plone_utils.addPortalMessage(message, 'error')

            for state in transitioned:
                tlist = transitioned[state]
                if len(tlist) > 1:
                    if state == 'to_be_preserved':
                        message = _('${items} are waiting for preservation.',
                                    mapping={'items': ', '.join(tlist)})
                    else:
                        message = _('${items} are waiting to be received.',
                                    mapping={'items': ', '.join(tlist)})
                    self.context.plone_utils.addPortalMessage(message, 'info')
                elif len(tlist) == 1:
                    if state == 'to_be_preserved':
                        message = _('${item} is waiting for preservation.',
                                    mapping={'item': ', '.join(tlist)})
                    else:
                        message = _('${item} is waiting to be received.',
                                    mapping={'item': ', '.join(tlist)})
                    self.context.plone_utils.addPortalMessage(message, 'info')
            if not message:
                message = _('No changes made.')
                self.context.plone_utils.addPortalMessage(message, 'info')
            self.destination_url = self.request.get_header(
                "referer", self.context.absolute_url())
            self.request.response.redirect(self.destination_url)

        elif action == "preserve":
            objects = AnalysisRequestWorkflowAction._get_selected_items(self)
            transitioned = {}
            not_transitioned = []
            Preserver = str()
            DatePreserved = str()
            for obj_uid, obj in objects.items():
                if obj.portal_type == "AnalysisRequest":
                    ar = obj
                    sample = obj.getSample()
                else:
                    sample = obj
                    ar = sample.aq_parent
                # can't transition inactive items
                if workflow.getInfoFor(sample, 'inactive_state',
                                       '') == 'inactive':
                    continue
                if not checkPermission(PreserveSample, sample):
                    continue

                # grab this object's Preserver and DatePreserved from the form
                # (if the columns are available and edit controls exist)
                if 'getPreserver' in form and 'getDatePreserved' in form:
                    try:
                        Preserver = form['getPreserver'][0][obj_uid].strip()
                        DatePreserved = form['getDatePreserved'][0][
                            obj_uid].strip()
                    except KeyError:
                        continue
                    Preserver = Preserver and Preserver or ''
                    DatePreserved = DatePreserved and DateTime(
                        DatePreserved) or ''
                else:
                    continue

                for sp in sample.objectValues("SamplePartition"):
                    if workflow.getInfoFor(
                            sp, 'review_state') == 'to_be_preserved':
                        sp.setDatePreserved(DatePreserved)
                        sp.setPreserver(Preserver)
                for sp in sample.objectValues("SamplePartition"):
                    if workflow.getInfoFor(
                            sp, 'review_state') == 'to_be_preserved':
                        if Preserver and DatePreserved:
                            doActionFor(sp, action)
                            transitioned[sp.aq_parent.Title()] = sp.Title()
                        else:
                            not_transitioned.append(sp)

            if len(transitioned.keys()) > 1:
                message = _('${items}: partitions are waiting to be received.',
                            mapping={'items': ', '.join(transitioned.keys())})
            else:
                message = _('${item}: ${part} is waiting to be received.',
                            mapping={
                                'item': ', '.join(transitioned.keys()),
                                'part': ', '.join(transitioned.values()),
                            })
            self.context.plone_utils.addPortalMessage(message, 'info')

            # And then the sample itself
            if Preserver and DatePreserved and not not_transitioned:
                doActionFor(sample, action)
                #message = _('${item} is waiting to be received.',
                #            mapping = {'item': sample.Title()})
                #message = t(message)
                #self.context.plone_utils.addPortalMessage(message, 'info')

            self.destination_url = self.request.get_header(
                "referer", self.context.absolute_url())
            self.request.response.redirect(self.destination_url)

        elif action in ('prepublish', 'publish', 'republish'):
            # We pass a list of AR objects to Publish.
            # it returns a list of AR IDs which were actually published.
            objects = AnalysisRequestWorkflowAction._get_selected_items(self)
            its = []
            for uid, obj in objects.items():
                if isActive(obj):
                    its.append(uid)
            its = ",".join(its)
            q = "/publish?items=" + its
            dest = self.portal_url + "/analysisrequests" + q
            self.request.response.redirect(dest)

        else:
            AnalysisRequestWorkflowAction.__call__(self)
Beispiel #4
0
    def __call__(self):
        form = self.request.form
        plone.protect.CheckAuthenticator(form)
        self.context = aq_inner(self.context)
        workflow = getToolByName(self.context, 'portal_workflow')
        bc = getToolByName(self.context, 'bika_catalog')
        rc = getToolByName(self.context, REFERENCE_CATALOG)
        translate = self.context.translate
        checkPermission = self.context.portal_membership.checkPermission

        # use came_from to decide which UI action was clicked.
        # "workflow_action" is the action name specified in the
        # portal_workflow transition url.
        came_from = "workflow_action"
        action = form.get(came_from, '')
        if not action and not form.get('bika_listing_filter_bar_submit', ''):
            # workflow_action_button is the action name specified in
            # the bika_listing_view table buttons.
            came_from = "workflow_action_button"
            action = form.get('workflow_action_id', '')
            if not action:
                if self.destination_url == "":
                    self.destination_url = self.request.get_header("referer",
                                           self.context.absolute_url())
                self.request.response.redirect(self.destination_url)
                return

        if action == "sample":
            message = None
            objects = AnalysisRequestWorkflowAction._get_selected_items(self)
            transitioned = {'to_be_preserved':[], 'sample_due':[]}
            for obj_uid, obj in objects.items():
                if obj.portal_type == "AnalysisRequest":
                    ar = obj
                    sample = obj.getSample()
                else:
                    sample = obj
                    ar = sample.aq_parent
                # can't transition inactive items
                if workflow.getInfoFor(sample, 'inactive_state', '') == 'inactive':
                    message = _('Sample %s is inactive' % sample.Title())
                    self.context.plone_utils.addPortalMessage(message, 'error')
                    continue
                transitions = [a['id'] for a in get_workflow_actions(sample)]
                if 'sample' not in transitions:
                    message = _('"Sample" is not a valid action for %s' % \
                                                                sample.Title())
                    self.context.plone_utils.addPortalMessage(message, 'error')
                    continue

                # grab this object's Sampler and DateSampled from the form
                # (if the columns are available and edit controls exist)
                Sampler = ''
                DateSampled = ''
                if 'getSampler' in form and 'getDateSampled' in form:
                    if len(form['getSampler']) > 0 \
                            and form['getSampler'][0].get(obj_uid):
                        Sampler = form['getSampler'][0][obj_uid].strip()
                    if len(form['getDateSampled']) > 0 \
                            and form['getDateSampled'][0].get(obj_uid):
                        DateSampled = form['getDateSampled'][0][obj_uid].strip()

                elif 'sample' in transitions \
                        or 'getSampler' not in form \
                        or 'getDateSampled' not in form:
                    message = _('''Please display both Sampler and Date Sampled
                                 columns''')
                    self.context.plone_utils.addPortalMessage(message, 'error')

                else:
                    continue

                # write them to the sample
                if Sampler:
                    sample.setSampler(Sampler)
                else:
                    Sampler = sample.getSampler()
                if DateSampled:
                    sample.setDateSampled(DateSampled)
                else:
                    DateSampled = sample.getDateSampled()
                sample.reindexObject()
                ars = sample.getAnalysisRequests()
                # Analyses and AnalysisRequets have calculated fields
                # that are indexed; re-index all these objects.
                for ar in ars:
                    ar.reindexObject()
                    analyses = sample.getAnalyses(
                            {'review_state':'to_be_sampled'})
                    for a in analyses:
                        a.getObject().reindexObject()

                if Sampler and DateSampled:
                    workflow.doActionFor(sample, action)
                    new_state = workflow.getInfoFor(sample, 'review_state')
                    doActionFor(ar, action)
                    transitioned[new_state].append(sample.Title())
                else:
                    message = _('Both Sampler and Date Sampled are required')
                    self.context.plone_utils.addPortalMessage(message, 'error')

            for state in transitioned:
                tlist = transitioned[state]
                if len(tlist) > 1:
                    if state == 'to_be_preserved':
                        message = _('${items} are waiting for preservation.',
                                    mapping = {'items': ', '.join(tlist)})
                    else:
                        message = _('${items} are waiting to be received.',
                                    mapping = {'items': ', '.join(tlist)})
                    self.context.plone_utils.addPortalMessage(message, 'info')
                elif len(tlist) == 1:
                    if state == 'to_be_preserved':
                        message = _('${item} is waiting for preservation.',
                                    mapping = {'item': ', '.join(tlist)})
                    else:
                        message = _('${item} is waiting to be received.',
                                    mapping = {'item': ', '.join(tlist)})
                    self.context.plone_utils.addPortalMessage(message, 'info')
            if not message:
                message = _('No changes made.')
                self.context.plone_utils.addPortalMessage(message, 'info')
            self.destination_url = self.request.get_header("referer",
                                   self.context.absolute_url())
            self.request.response.redirect(self.destination_url)

        elif action == "preserve":
            objects = AnalysisRequestWorkflowAction._get_selected_items(self)
            transitioned = {}
            not_transitioned = []
            Preserver = str()
            DatePreserved = str()
            for obj_uid, obj in objects.items():
                if obj.portal_type == "AnalysisRequest":
                    ar = obj
                    sample = obj.getSample()
                else:
                    sample = obj
                    ar = sample.aq_parent
                # can't transition inactive items
                if workflow.getInfoFor(sample, 'inactive_state', '') == 'inactive':
                    continue
                if not checkPermission(PreserveSample, sample):
                    continue

                # grab this object's Preserver and DatePreserved from the form
                # (if the columns are available and edit controls exist)
                if 'getPreserver' in form and 'getDatePreserved' in form:
                    try:
                        Preserver = form['getPreserver'][0][obj_uid].strip()
                        DatePreserved = form['getDatePreserved'][0][obj_uid].strip()
                    except KeyError:
                        continue
                    Preserver = Preserver and Preserver or ''
                    DatePreserved = DatePreserved and DateTime(DatePreserved) or ''
                else:
                    continue

                for sp in sample.objectValues("SamplePartition"):
                    if workflow.getInfoFor(sp, 'review_state') == 'to_be_preserved':
                        sp.setDatePreserved(DatePreserved)
                        sp.setPreserver(Preserver)
                for sp in sample.objectValues("SamplePartition"):
                    if workflow.getInfoFor(sp, 'review_state') == 'to_be_preserved':
                        if Preserver and DatePreserved:
                            doActionFor(sp, action)
                            transitioned[sp.aq_parent.Title()] = sp.Title()
                        else:
                            not_transitioned.append(sp)

            if len(transitioned.keys()) > 1:
                message = _('${items}: partitions are waiting to be received.',
                        mapping = {'items': ', '.join(transitioned.keys())})
            else:
                message = _('${item}: ${part} is waiting to be received.',
                        mapping = {'item': ', '.join(transitioned.keys()),
                                   'part': ', '.join(transitioned.values()),})
            self.context.plone_utils.addPortalMessage(message, 'info')

            # And then the sample itself
            if Preserver and DatePreserved and not not_transitioned:
                doActionFor(sample, action)
                #message = _('${item} is waiting to be received.',
                #            mapping = {'item': sample.Title()})
                #message = t(message)
                #self.context.plone_utils.addPortalMessage(message, 'info')

            self.destination_url = self.request.get_header(
                "referer", self.context.absolute_url())
            self.request.response.redirect(self.destination_url)

        elif action in ('prepublish', 'publish', 'republish'):
            # We pass a list of AR objects to Publish.
            # it returns a list of AR IDs which were actually published.
            objects = AnalysisRequestWorkflowAction._get_selected_items(self)
            its = []
            for uid, obj in objects.items():
                if isActive(obj):
                    its.append(uid);
            its = ",".join(its)
            q = "/publish?items=" + its
            dest = self.portal_url+"/analysisrequests" + q
            self.request.response.redirect(dest)

        else:
            AnalysisRequestWorkflowAction.__call__(self)