コード例 #1
0
    def render(self):
        """ Mostly a copy of the render method in euphorie.client, but with
            some changes to also show unanswered risks and non-present risks.
            #1517 and #1518
        """
        document = report.createDocument(self.session)
        ss = document.StyleSheet

        # Define some more custom styles
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "RiskPriority",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=22,
                                    italic=True,
                                    colour=ss.Colours.Blue)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "MeasureField",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=18,
                                    underline=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        # XXX: This part is removed
        # self.addActionPlan(document)

        # XXX: and replaced with this part:
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])
        toc = createSection(document, self.context, self.request)

        body = Section()
        heading = t(
            _("header_oira_report_download",
              default=u"OiRA Report: \"${title}\"",
              mapping=dict(title=self.session.title)))

        toc.append(
            Paragraph(
                ss.ParagraphStyles.Heading1,
                ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER),
                heading,
            ))

        if self.session.report_comment:
            # Add comment. #5985
            normal_style = document.StyleSheet.ParagraphStyles.Normal
            toc.append(Paragraph(normal_style, self.session.report_comment))

        toc_props = ParagraphPropertySet()
        toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        p = Paragraph(ss.ParagraphStyles.Heading6, toc_props)
        txt = t(_("toc_header", default=u"Contents"))
        p.append(character.Text(txt))
        toc.append(p)

        headings = [
            t(
                _("header_present_risks",
                  default=u"Risks that have been identified, "
                  u"evaluated and have an Action Plan")),
            t(
                _("header_unevaluated_risks",
                  default=u"Risks that have been identified but "
                  u"do NOT have an Action Plan")),
            t(
                _("header_unanswered_risks",
                  default=u'Hazards/problems that have been "parked" '
                  u'and are still to be dealt with')),
            t(
                _("header_risks_not_present",
                  default=u"Hazards/problems that have been managed "
                  u"or are not present in your organisation"))
        ]
        nodes = [
            self.actioned_nodes,
            self.unactioned_nodes,
            self.unanswered_nodes,
            self.risk_not_present_nodes,
        ]

        for nodes, heading in zip(nodes, headings):
            if not nodes:
                continue
            self.addReportNodes(document, nodes, heading, toc, body)

        toc.append(Paragraph(LINE))
        body.append(Paragraph(LINE))
        self.addConsultationBox(body, document)
        document.Sections.append(body)
        # Until here...

        renderer = Renderer()
        output = StringIO()
        renderer.Write(document, output)

        filename = translate(
            _("filename_report_actionplan",
              default=u"Action plan ${title}",
              mapping=dict(title=self.session.title)),
            context=self.request,
        )
        self.request.response.setHeader(
            "Content-Disposition",
            "attachment; filename=\"%s.rtf\"" % filename.encode("utf-8"))
        self.request.response.setHeader("Content-Type", "application/rtf")
        return output.getvalue()
コード例 #2
0
    def render(self):
        """ Mostly a copy of the render method in OSHAActionPlanReportDownload, but with
            some changes to handle the special reqs of Italy
        """
        document = report.createDocument(self.session)
        ss = document.StyleSheet

        # Define some more custom styles
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "RiskPriority",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=22,
                                    italic=True,
                                    colour=ss.Colours.Blue)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "MeasureField",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=18,
                                    underline=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITTitle",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=36,
                                    italic=True,
                                    bold=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITSubtitle",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=32,
                                    italic=True,
                                    bold=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITSubSubtitle",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial,
                                    size=28,
                                    italic=True,
                                    bold=True)),
                ParagraphPropertySet(left_indent=300, right_indent=300)))
        ss.ParagraphStyles.append(
            ParagraphStyle(
                "ITNormalBold",
                TextStyle(
                    TextPropertySet(font=ss.Fonts.Arial, size=24, bold=True)),
                ParagraphPropertySet(left_indent=50, right_indent=50)))
        # XXX: This part is removed
        # self.addActionPlan(document)

        # XXX: and replaced with this part:
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])
        intro = createItalianIntro(document, self.context, self.request)
        toc = createSection(document,
                            self.context,
                            self.request,
                            first_page_number=2)

        body = Section()
        heading = t(
            _("header_oira_report_download",
              default=u"OiRA Report: \"${title}\"",
              mapping=dict(title=self.session.title)))

        toc.append(
            Paragraph(
                ss.ParagraphStyles.Heading1,
                ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER),
                heading,
            ))

        if self.session.report_comment:
            # Add comment. #5985
            normal_style = document.StyleSheet.ParagraphStyles.Normal
            toc.append(Paragraph(normal_style, self.session.report_comment))

        toc_props = ParagraphPropertySet()
        toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        p = Paragraph(ss.ParagraphStyles.Heading6, toc_props)
        txt = t(_("toc_header", default=u"Contents"))
        p.append(character.Text(txt))
        toc.append(p)

        headings = [
            t(u"Adempimenti/rischi identificati, valutati e gestiti con misure "
              "obbligatorie adottate ed eventuali misure di miglioramento"),
            t(u"Adempimenti/rischi non pertinenti"),
        ]
        nodes = [
            self.actioned_nodes,
            self.risk_not_present_nodes,
        ]

        for nodes, heading in zip(nodes, headings):
            if not nodes:
                continue
            self.addReportNodes(document, nodes, heading, toc, body)

        toc.append(Paragraph(LINE))
        body.append(Paragraph(LINE))
        document.Sections.append(body)
        # Until here...

        renderer = Renderer()
        output = StringIO()
        renderer.Write(document, output)

        # Custom filename
        filename = u"Documento di valutazione dei rischi {}".format(
            self.session.title)
        self.request.response.setHeader(
            "Content-Disposition",
            "attachment; filename=\"%s.rtf\"" % filename.encode("utf-8"))
        self.request.response.setHeader("Content-Type", "application/rtf")
        return output.getvalue()
コード例 #3
0
    def addReportNodes(self, document, nodes, heading, toc, body):
        """ """
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])
        ss = document.StyleSheet
        toc_props = ParagraphPropertySet()
        toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1)
        p = Paragraph(ss.ParagraphStyles.Heading6, toc_props)
        p.append(character.Text(heading, TextPropertySet(italic=True)))
        toc.append(p)

        body.append(Paragraph(ss.ParagraphStyles.Heading1, heading))

        survey = self.request.survey
        styles = ss.ParagraphStyles
        header_styles = {
            0: styles.Heading2,
            1: styles.Heading3,
            2: styles.Heading4,
            3: styles.Heading5,
            4: styles.Heading6,
        }
        for node in nodes:
            zodb_node = None
            if node.zodb_path == 'custom-risks':
                title = self.title_custom_risks
            elif getattr(node, 'is_custom_risk', None):
                title = node.title
            else:
                zodb_node = survey.restrictedTraverse(
                    node.zodb_path.split("/"))
                title = node_title(node, zodb_node)

            thin_edge = BorderPropertySet(width=20,
                                          style=BorderPropertySet.SINGLE)

            if node.depth == 1:
                p = Paragraph(
                    header_styles.get(node.depth, styles.Heading6),
                    FramePropertySet(thin_edge, thin_edge, thin_edge,
                                     thin_edge),
                    u"%s %s" % (node.number, title))
            else:
                p = Paragraph(header_styles.get(node.depth, styles.Heading6),
                              u"%s %s" % (node.number, title))
            body.append(p)

            if node.type != "risk":
                continue

            if node.priority:
                if node.priority == "low":
                    level = _("risk_priority_low", default=u"low")
                elif node.priority == "medium":
                    level = _("risk_priority_medium", default=u"medium")
                elif node.priority == "high":
                    level = _("risk_priority_high", default=u"high")

                msg = _("risk_priority",
                        default="This is a ${priority_value} priority risk.",
                        mapping={'priority_value': level})
                body.append(Paragraph(styles.RiskPriority, t(msg)))

            # In the report for Italy, don't print the description
            if (getattr(node, 'identification', None) == 'no'
                    and not IOSHAItalyReportPhaseSkinLayer.providedBy(
                        self.request)):
                if zodb_node is None:
                    description = node.title
                else:
                    description = zodb_node.description

                body.append(
                    Paragraph(
                        styles.Normal,
                        ParagraphPropertySet(left_indent=300,
                                             right_indent=300),
                        t(
                            _(
                                utils.html_unescape(
                                    htmllaundry.StripMarkup(description))))))
                body.append(Paragraph(""))

            if node.comment and node.comment.strip():
                body.append(Paragraph(styles.Comment, node.comment))

            for (idx, measure) in enumerate(node.action_plans):
                if not measure.action_plan:
                    continue

                if len(node.action_plans) == 1:
                    heading = t(_("header_measure_single", default=u"Measure"))
                else:
                    heading = t(
                        _("header_measure",
                          default=u"Measure ${index}",
                          mapping={"index": idx + 1}))

                self.addMeasure(document, heading, body, measure)