Esempio n. 1
0
    def __call__(self):
        if not(getSecurityManager().checkPermission(EditWorksheet, self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        form = self.request.form
        if 'submitted' in form:
            rc = getToolByName(self.context, REFERENCE_CATALOG)
            # parse request
            service_uids = form['selected_service_uids'].split(",")
            position = form['position']
            reference_uid = form['reference_uid']
            reference = rc.lookupObject(reference_uid)
            self.request['context_uid'] = self.context.UID()
            ref_analyses = self.context.addReferences(position, reference, service_uids)
            self.request.response.redirect(self.context.absolute_url() + "/manage_results")
        else:
            self.Services = ServicesView(self.context, self.request)
            self.Services.view_url = self.Services.base_url + "/add_blank"
            return self.template()
Esempio n. 2
0
    def __call__(self):
        if not (getSecurityManager().checkPermission(EditWorksheet,
                                                     self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        form = self.request.form
        if 'submitted' in form:
            rc = getToolByName(self.context, REFERENCE_CATALOG)
            # parse request
            service_uids = form['selected_service_uids'].split(",")
            position = form['position']
            reference_uid = form['reference_uid']
            reference = rc.lookupObject(reference_uid)
            self.request['context_uid'] = self.context.UID()
            ref_analyses = self.context.addReferences(position, reference,
                                                      service_uids)
            self.request.response.redirect(self.context.absolute_url() +
                                           "/manage_results")
        else:
            self.Services = ServicesView(self.context, self.request)
            self.Services.view_url = self.Services.base_url + "/add_blank"
            return self.template()
Esempio n. 3
0
    def __call__(self):
        if not (getSecurityManager().checkPermission(EditWorksheet,
                                                     self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        form = self.request.form
        if 'submitted' in form:
            ar_uid = self.request.get('ar_uid', '')
            src_slot = [
                slot['position'] for slot in self.context.getLayout()
                if slot['container_uid'] == ar_uid and slot['type'] == 'a'
            ][0]
            self.request['context_uid'] = self.context.UID()
            self.context.addDuplicateAnalyses(src_slot)
            self.request.response.redirect(self.context.absolute_url() +
                                           "/manage_results")
        else:
            self.ARs = AnalysisRequestsView(self.context, self.request)
            return self.template()
Esempio n. 4
0
    def __call__(self):
        # TODO: Refactor this function call
        showRejectionMessage(self.context)

        # Save the results layout
        rlayout = self.request.get("resultslayout", "")
        if rlayout and rlayout in WORKSHEET_LAYOUT_OPTIONS.keys() \
           and rlayout != self.context.getResultsLayout():
            self.context.setResultsLayout(rlayout)
            message = _("Changes saved.")
            self.context.plone_utils.addPortalMessage(message, "info")

        # Classic/Transposed View Switch
        if self.context.getResultsLayout() == "1":
            view = "analyses_classic_view"
            self.Analyses = api.get_view(
                view, context=self.context, request=self.request)
        else:
            view = "analyses_transposed_view"
            self.Analyses = api.get_view(
                view, context=self.context, request=self.request)

        self.analystname = self.context.getAnalystName()
        self.instrumenttitle = self.get_instrument_title()

        # Check if the instruments used are valid
        self.checkInstrumentsValidity()

        return self.template()
Esempio n. 5
0
    def __call__(self):
        super(AddAnalysesView, self).__call__()

        # TODO: Refactor Worfklow
        grant = self.is_edit_allowed() and self.is_manage_allowed()
        if not grant:
            redirect_url = api.get_url(self.context)
            return self.request.response.redirect(redirect_url)

        # TODO: Refactor this function call
        showRejectionMessage(self.context)

        # Handle form submission
        if self.request.form.get("submitted"):
            CheckAuthenticator(self.request)
            success = self.handle_submit()
            if success:
                self.add_status_message(_("Changes saved."))
                redirect_url = "{}/{}".format(api.get_url(self.context),
                                              "manage_results")
                self.request.response.redirect(redirect_url)
            else:
                self.add_status_message(
                    _("No analyses were added to this worksheet."),
                    level="warning")
            return self.template()

        # handle subpath calls
        if len(self.traverse_subpath) > 0:
            return self.handle_subpath()

        return self.template()
Esempio n. 6
0
    def __call__(self):

        # Deny access to foreign analysts
        if checkUserAccess(self.context, self.request) is False:
            return []

        showRejectionMessage(self.context)

        self.icon = self.portal_url + "/++resource++bika.lims.images/worksheet_big.png"

        # Save the results layout
        rlayout = self.request.get('resultslayout', '')
        if rlayout and rlayout in WORKSHEET_LAYOUT_OPTIONS.keys() \
           and rlayout != self.context.getResultsLayout():
            self.context.setResultsLayout(rlayout)
            message = _("Changes saved.")
            self.context.plone_utils.addPortalMessage(message, 'info')

        # Here we create an instance of WorksheetAnalysesView
        if self.context.getResultsLayout() == '2':
            # Transposed view
            self.Analyses = AnalysesTransposedView(self.context, self.request)
        else:
            # Classic view
            self.Analyses = AnalysesView(self.context, self.request)

        self.analystname = self.context.getAnalystName()
        self.instrumenttitle = self.context.getInstrument() and self.context.getInstrument().Title() or ''

        # Check if the instruments used are valid
        self.checkInstrumentsValidity()

        return self.template()
Esempio n. 7
0
    def __call__(self):
        if not(getSecurityManager().checkPermission(EditWorksheet, self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        form = self.request.form
        rc = getToolByName(self.context, REFERENCE_CATALOG)
        if 'submitted' in form:
            if 'getWorksheetTemplate' in form and form['getWorksheetTemplate']:
                layout = self.context.getLayout()
                wst = rc.lookupObject(form['getWorksheetTemplate'])
                self.request['context_uid'] = self.context.UID()
                self.context.applyWorksheetTemplate(wst)
                if len(self.context.getLayout()) != len(layout):
                    self.context.plone_utils.addPortalMessage(
                        PMF("Changes saved."))
                    self.request.RESPONSE.redirect(self.context.absolute_url() +
                                                   "/manage_results")
                else:
                    self.context.plone_utils.addPortalMessage(
                        _("No analyses were added to this worksheet."))
                    self.request.RESPONSE.redirect(self.context.absolute_url() +
                                                   "/add_analyses")
            elif (
                'FilterByCategory' in form or
                'FilterByService' in form or
                'FilterByClient' in form
                    ):
                # Apply filter elements
                # Note that the name of those fields is '..Title', but we
                # are getting their UID.
                category = form.get('FilterByCategory', '')
                if category:
                    self.contentFilter['getCategoryUID'] = category

                service = form.get('FilterByService', '')
                if service:
                    self.contentFilter['getServiceUID'] = service

                client = form.get('FilterByClient', '')
                if client:
                    self.contentFilter['getClientUID'] = client

        self._process_request()

        if self.request.get('table_only', '') == self.form_id or \
                self.request.get('rows_only', '') == self.form_id:
            return self.contents_table()
        else:
            return self.template()
Esempio n. 8
0
    def __call__(self):
        if not (getSecurityManager().checkPermission(EditWorksheet,
                                                     self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        form = self.request.form
        rc = getToolByName(self.context, REFERENCE_CATALOG)
        if 'submitted' in form:
            if 'getWorksheetTemplate' in form and form['getWorksheetTemplate']:
                layout = self.context.getLayout()
                wst = rc.lookupObject(form['getWorksheetTemplate'])
                self.request['context_uid'] = self.context.UID()
                self.context.applyWorksheetTemplate(wst)
                if len(self.context.getLayout()) != len(layout):
                    self.context.plone_utils.addPortalMessage(
                        PMF("Changes saved."))
                    self.request.RESPONSE.redirect(
                        self.context.absolute_url() + "/manage_results")
                else:
                    self.context.plone_utils.addPortalMessage(
                        _("No analyses were added to this worksheet."))
                    self.request.RESPONSE.redirect(
                        self.context.absolute_url() + "/add_analyses")

        filter_mapping = {
            "FilterByCategory": "getCategoryUID",
            "FilterByService": "getServiceUID",
            "FilterByClient": "getClientUID",
        }

        for filter_key, cat_index in filter_mapping.items():
            form_key = "{}_{}".format(self.form_id, filter_key)
            value = form.get(form_key)
            if value is None:
                continue
            self.contentFilter[cat_index] = value

        self.update()

        if self.request.get('table_only', '') == self.form_id or \
                self.request.get('rows_only', '') == self.form_id:
            return self.contents_table()
        else:
            return self.template()
Esempio n. 9
0
 def __call__(self):
     template = super(AddDuplicateView, self).__call__()
     # TODO: Refactor Worfklow
     grant = self.is_edit_allowed() and self.is_manage_allowed()
     if not grant:
         redirect_url = api.get_url(self.context)
         return self.request.response.redirect(redirect_url)
     # TODO: Refactor this function call
     showRejectionMessage(self.context)
     # Handle form submission
     if self.request.form.get("submitted"):
         CheckAuthenticator(self.request)
         self.handle_submit()
     return template
Esempio n. 10
0
    def __call__(self):
        if not (getSecurityManager().checkPermission(EditWorksheet,
                                                     self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        translate = self.context.translate

        form_id = self.form_id
        form = self.request.form
        rc = getToolByName(self.context, REFERENCE_CATALOG)
        if 'submitted' in form:
            if 'getWorksheetTemplate' in form and form['getWorksheetTemplate']:
                layout = self.context.getLayout()
                wst = rc.lookupObject(form['getWorksheetTemplate'])
                client_title = form.get('client', 'any')
                self.request['context_uid'] = self.context.UID()
                self.context.applyWorksheetTemplate(wst,
                                                    client_title=client_title)
                if len(self.context.getLayout()) != len(layout):
                    self.context.plone_utils.addPortalMessage(
                        PMF("Changes saved."))
                    self.request.RESPONSE.redirect(
                        self.context.absolute_url() + "/manage_results")
                else:
                    self.context.plone_utils.addPortalMessage(
                        _("No analyses were added to this worksheet."))
                    self.request.RESPONSE.redirect(
                        self.context.absolute_url() + "/add_analyses")

        self._process_request()

        if self.request.get('table_only', '') == self.form_id:
            return self.contents_table()
        elif self.request.get('rows_only', '') == self.form_id:
            return self.contents_table()
        else:
            return self.template()
Esempio n. 11
0
    def __call__(self):
        if not(getSecurityManager().checkPermission(EditWorksheet, self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        translate = self.context.translate

        form_id = self.form_id
        form = self.request.form
        rc = getToolByName(self.context, REFERENCE_CATALOG)
        if 'submitted' in form:
            if 'getWorksheetTemplate' in form and form['getWorksheetTemplate']:
                layout = self.context.getLayout()
                wst = rc.lookupObject(form['getWorksheetTemplate'])
                client_title = form.get('client', 'any')
                self.request['context_uid'] = self.context.UID()
                self.context.applyWorksheetTemplate(
                    wst, client_title=client_title)
                if len(self.context.getLayout()) != len(layout):
                    self.context.plone_utils.addPortalMessage(
                        PMF("Changes saved."))
                    self.request.RESPONSE.redirect(self.context.absolute_url() +
                                                   "/manage_results")
                else:
                    self.context.plone_utils.addPortalMessage(
                        _("No analyses were added to this worksheet."))
                    self.request.RESPONSE.redirect(self.context.absolute_url() +
                                                   "/add_analyses")

        self._process_request()

        if self.request.get('table_only', '') == self.form_id:
            return self.contents_table()
        elif self.request.get('rows_only', '') == self.form_id:
            return self.contents_table()
        else:
            return self.template()
Esempio n. 12
0
    def __call__(self):
        if not(getSecurityManager().checkPermission(EditWorksheet, self.context)):
            self.request.response.redirect(self.context.absolute_url())
            return

        # Deny access to foreign analysts
        if checkUserManage(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        form = self.request.form
        if 'submitted' in form:
            ar_uid = self.request.get('ar_uid', '')
            src_slot = [slot['position'] for slot in self.context.getLayout() if
                        slot['container_uid'] == ar_uid and slot['type'] == 'a'][0]
            self.request['context_uid'] = self.context.UID()
            self.context.addDuplicateAnalyses(src_slot)
            self.request.response.redirect(self.context.absolute_url() + "/manage_results")
        else:
            self.ARs = AnalysisRequestsView(self.context, self.request)
            return self.template()
Esempio n. 13
0
    def __call__(self):
        # Deny access to foreign analysts
        if checkUserAccess(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        self.icon = self.portal_url + "/++resource++bika.lims.images/worksheet_big.png"

        # Worksheet Attachmemts
        # the expandable form is handled here.
        if "AttachmentFile_file" in self.request:
            this_file = self.request['AttachmentFile_file']
            if 'analysis_uid' in self.request:
                analysis_uid = self.request['analysis_uid']
            else:
                analysis_uid = None
            if 'Service' in self.request:
                service_uid = self.request['Service']
            else:
                service_uid = None

            ws = self.context
            tool = getToolByName(self.context, REFERENCE_CATALOG)
            if analysis_uid:
                analysis = tool.lookupObject(analysis_uid)
                attachment = _createObjectByType("Attachment", ws, tmpID())
                attachment.edit(AttachmentFile=this_file,
                                AttachmentType=self.request.get(
                                    'AttachmentType', ''),
                                AttachmentKeys=self.request['AttachmentKeys'])
                attachment.reindexObject()

                others = analysis.getAttachment()
                attachments = []
                for other in others:
                    attachments.append(other.UID())
                attachments.append(attachment.UID())
                analysis.setAttachment(attachments)

            if service_uid:
                workflow = getToolByName(self.context, 'portal_workflow')
                for analysis in self.context.getAnalyses():
                    if analysis.portal_type not in ('Analysis',
                                                    'DuplicateAnalysis'):
                        continue
                    if not analysis.getServiceUID() == service_uid:
                        continue
                    review_state = workflow.getInfoFor(analysis,
                                                       'review_state', '')
                    if not review_state in [
                            'assigned', 'sample_received', 'to_be_verified'
                    ]:
                        continue

                    attachment = _createObjectByType("Attachment", ws, tmpID())
                    attachment.edit(
                        AttachmentFile=this_file,
                        AttachmentType=self.request.get('AttachmentType', ''),
                        AttachmentKeys=self.request['AttachmentKeys'])
                    attachment.processForm()
                    attachment.reindexObject()

                    others = analysis.getAttachment()
                    attachments = []
                    for other in others:
                        attachments.append(other.UID())
                    attachments.append(attachment.UID())
                    analysis.setAttachment(attachments)

        # Save the results layout
        rlayout = self.request.get('resultslayout', '')
        if rlayout and rlayout in WORKSHEET_LAYOUT_OPTIONS.keys() \
            and rlayout != self.context.getResultsLayout():
            self.context.setResultsLayout(rlayout)
            message = _("Changes saved.")
            self.context.plone_utils.addPortalMessage(message, 'info')

        # Here we create an instance of WorksheetAnalysesView
        if self.context.getResultsLayout() == '2':
            # Transposed view
            self.Analyses = AnalysesTransposedView(self.context, self.request)
        else:
            # Classic view
            self.Analyses = AnalysesView(self.context, self.request)

        self.analystname = self.context.getAnalystName()
        self.instrumenttitle = self.context.getInstrument(
        ) and self.context.getInstrument().Title() or ''

        # Check if the instruments used are valid
        self.checkInstrumentsValidity()

        return self.template()
Esempio n. 14
0
    def __call__(self):
        # Deny access to foreign analysts
        if checkUserAccess(self.context, self.request) == False:
            return []

        showRejectionMessage(self.context)

        self.icon = self.portal_url + "/++resource++bika.lims.images/worksheet_big.png"

        # Worksheet Attachmemts
        # the expandable form is handled here.
        if "AttachmentFile_file" in self.request:
            this_file =  self.request['AttachmentFile_file']
            if 'analysis_uid' in self.request:
                analysis_uid = self.request['analysis_uid']
            else:
                analysis_uid = None
            if 'Service' in self.request:
                service_uid = self.request['Service']
            else:
                service_uid = None

            ws = self.context
            tool = getToolByName(self.context, REFERENCE_CATALOG)
            if analysis_uid:
                analysis = tool.lookupObject(analysis_uid)
                attachment = _createObjectByType("Attachment", ws, tmpID())
                attachment.edit(
                    AttachmentFile=this_file,
                    AttachmentType=self.request.get('AttachmentType', ''),
                    AttachmentKeys=self.request['AttachmentKeys'])
                attachment.reindexObject()

                others = analysis.getAttachment()
                attachments = []
                for other in others:
                    attachments.append(other.UID())
                attachments.append(attachment.UID())
                analysis.setAttachment(attachments)

            if service_uid:
                workflow = getToolByName(self.context, 'portal_workflow')
                for analysis in self.context.getAnalyses():
                    if analysis.portal_type not in ('Analysis', 'DuplicateAnalysis'):
                        continue
                    if not analysis.getServiceUID() == service_uid:
                        continue
                    review_state = workflow.getInfoFor(analysis, 'review_state', '')
                    if not review_state in ['assigned', 'sample_received', 'to_be_verified']:
                        continue

                    attachment = _createObjectByType("Attachment", ws, tmpID())
                    attachment.edit(
                        AttachmentFile = this_file,
                        AttachmentType = self.request.get('AttachmentType', ''),
                        AttachmentKeys = self.request['AttachmentKeys'])
                    attachment.processForm()
                    attachment.reindexObject()

                    others = analysis.getAttachment()
                    attachments = []
                    for other in others:
                        attachments.append(other.UID())
                    attachments.append(attachment.UID())
                    analysis.setAttachment(attachments)

        # Save the results layout
        rlayout = self.request.get('resultslayout', '')
        if rlayout and rlayout in WORKSHEET_LAYOUT_OPTIONS.keys() \
            and rlayout != self.context.getResultsLayout():
            self.context.setResultsLayout(rlayout)
            message = _("Changes saved.")
            self.context.plone_utils.addPortalMessage(message, 'info')

        # Here we create an instance of WorksheetAnalysesView
        if self.context.getResultsLayout() == '2':
            # Transposed view
            self.Analyses = AnalysesTransposedView(self.context, self.request)
        else:
            # Classic view
            self.Analyses = AnalysesView(self.context, self.request)

        self.analystname = self.context.getAnalystName()
        self.instrumenttitle = self.context.getInstrument() and self.context.getInstrument().Title() or ''

        # Check if the instruments used are valid
        self.checkInstrumentsValidity()

        return self.template()