Example #1
0
    def make_paraIndents():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append(
            'The paragraphs below demonstrate the flexibility , the following is all at the '
            'same indent level and the one after it has the first line at a '
            'different indent to the rest. The third has the first line '
            'going in the other direction and is also separated by a page '
            'break. Note that the FirstLineIndent is defined as being the '
            'difference from the LeftIndent.')
        creditURL = 'http://www.shakespeare-online.com/plots/1kh4ps.html'
        section.append('(Paragraph text from %s.)' % creditURL)

        sampleParagraph = """The play opens one year after the death of Richard
            II, and King Henry is making plans for a crusade to the
            Holy Land to cleanse himself of the guilt he feels over the
            usurpation of Richard's crown. But the crusade must be postponed
            when Henry learns that Welsh rebels, led by Owen Glendower, have
            defeated and captured Mortimer. Although the brave Henry Percy,
            nicknamed Hotspur, has quashed much of the uprising, there is still
            much trouble in Scotland. King Henry has a deep admiration for
            Hotspur and he longs for his own son, Prince Hal, to
            display some of Hotspur's noble qualities. Hal is more comfortable
            in a tavern than on the battlefield, and he spends his days
            carousing with riff-raff in London. But King Henry also has his
            problems with the headstrong Hotspur, who refuses to turn over his
            prisoners to the state as he has been so ordered.
            Westmoreland tells King Henry that Hotspur has many of
            the traits of his uncle, Thomas Percy, the Earl of Worcester, and
            defying authority runs in the family."""
        sampleParagraph = re.sub('\s+', ' ', sampleParagraph)
        para_props = ParagraphPropertySet()
        para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3)
        p = Paragraph(styles.ParagraphStyles.Normal, para_props)
        p.append(sampleParagraph)
        section.append(p)

        para_props = ParagraphPropertySet()
        para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH * -2)
        para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3)
        p = Paragraph(styles.ParagraphStyles.Normal, para_props)
        p.append(sampleParagraph)
        section.append(p)

        para_props = ParagraphPropertySet()
        para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH)
        para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH)
        p = Paragraph(styles.ParagraphStyles.Normal, para_props)
        p.append(sampleParagraph)
        section.append(p)
        return doc
    section.append(p)
    p = Paragraph(ss.ParagraphStyles.Heading4)
    p. append(name)
    section.append(p)

    if len(person['grants']) > 0:
        for grant in person['grants']:
            try:
                print 'grant',\
                      int(grant['start_date']['date']['year']), int(year)
            except:
                continue
            if int(grant['start_date']['date']['year']) >= int(year):
                para_props = ParagraphPropertySet()
                para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH*-1)
                para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH*2)
                p = Paragraph(ss.ParagraphStyles.Normal, para_props)
                p.append(vt.string_from_grant(grant))
                section.append(p)

    if len(person['publications']) > 0:
        for publication in person['publications']:
            try:
                print 'pub', int(publication['date']['year']), int(year)
            except:
                continue
            if int(publication['date']['year']) >= int(year):
                para_props = ParagraphPropertySet()
                para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH*-1)
                para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH*2)
                p = Paragraph(ss.ParagraphStyles.Normal, para_props)
Example #3
0
        key = position['start_date']['date']['year'] + position[
            'position_label']
        positions[key] = position
last_position = min(20, len(positions))
npos = 0
for key in sorted(positions.keys(), reverse=True):
    npos = npos + 1
    if npos > last_position:
        break
    position = positions[key]
    para_props = ParagraphPropertySet(
        tabs=[TabPropertySet(550),
              TabPropertySet(125),
              TabPropertySet(600)])
    para_props.SetFirstLineIndent(-1275)
    para_props.SetLeftIndent(1275)
    p = Paragraph(ss.ParagraphStyles.Normal, para_props)
    if 'end_date' in position:
        p.append(position['start_date']['date']['year'], TAB, '-', TAB,
                 position['end_date']['date']['year'], TAB,
                 position['position_label'], ', ', position['org_name'])
    else:
        p.append(position['start_date']['date']['year'], TAB, '-', TAB, TAB,
                 position['position_label'], ', ', position['org_name'])
    section.append(p)

# Section C -- Selected Peer-reviewed Publications

p = Paragraph(ss.ParagraphStyles.Heading3)
p.append("C.", TAB, "Selected Peer-reviewed Publications")
section.append(p)
Example #4
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()
Example #5
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()
Example #6
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)