コード例 #1
0
ファイル: report.py プロジェクト: pombredanne/osha.oira
def createSection(document, survey, request):
    t = lambda txt: "".join(["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section(break_type=Section.PAGE, first_page_number=1)
    footer_txt = t(
        _(
            "report_survey_revision",
            default=u"This report was based on the OiRA Tool '${title}' " u"of revision date ${date}.",
            mapping={"title": survey.published[1], "date": formatDate(request, survey.published[2])},
        )
    )

    header = Table(4750, 4750)
    c1 = Cell(Paragraph(document.StyleSheet.ParagraphStyles.Footer, survey.published[1]))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props, formatDate(request, datetime.today()))
    )
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    # rtfng does not like unicode footers
    c1 = Cell(Paragraph(document.StyleSheet.ParagraphStyles.Footer, pp(alignment=pp.LEFT), footer_txt))

    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    document.Sections.append(section)
    return section
コード例 #2
0
    def set_session_title_row(self, data):

        request = self.request
        survey = self.context.aq_parent

        # Remove existing paragraphs
        for paragraph in self.template.paragraphs:
            delete_paragraph(paragraph)

        header = self.template.sections[0].header
        header_table = header.tables[0]
        header_table.cell(0, 0).paragraphs[0].text = data["title"]
        header_table.cell(0, 1).paragraphs[0].text = formatDate(
            request, date.today())

        footer_txt = self.t(
            _(
                "report_identification_revision",
                default="This document was based on the OiRA Tool '${title}' "
                "of revision date ${date}.",
                mapping={
                    "title": survey.published[1],
                    "date": formatDate(request, survey.published[2]),
                },
            ))

        footer = self.template.sections[0].footer
        paragraph = footer.tables[0].cell(0, 0).paragraphs[0]
        paragraph.style = "Footer"
        paragraph.text = footer_txt
コード例 #3
0
ファイル: report.py プロジェクト: pombredanne/osha.oira
def createIdentificationReportSection(document, survey, request):
    t = lambda txt: "".join(["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section()

    footer_txt = t(
        _(
            "report_identification_revision",
            default=u"This document was based on the OiRA Tool '${title}' of " u"revision date ${date}.",
            mapping={"title": survey.published[1], "date": formatDate(request, survey.published[2])},
        )
    )
    header = Table(4750, 4750)
    c1 = Cell(Paragraph(document.StyleSheet.ParagraphStyles.Footer, SessionManager.session.title))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props, formatDate(request, datetime.today()))
    )
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    c1 = Cell(Paragraph(document.StyleSheet.ParagraphStyles.Footer, pp(alignment=pp.LEFT), footer_txt))
    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    section.SetBreakType(section.PAGE)
    document.Sections.append(section)
    return section
コード例 #4
0
    def set_session_title_row(self, data):

        request = self.request
        doc = self.template

        # Remove existing paragraphs
        for paragraph in doc.paragraphs:
            delete_paragraph(paragraph)

        header = doc.sections[0].header
        h_table = header.tables[0]
        h_table.cell(0, 0).paragraphs[0].text = data["heading"]
        h_table.cell(0, 1).paragraphs[0].text = u"Datum download: {}".format(
            formatDate(request, date.today()))

        # doc.paragraphs[0].text = data['heading']

        survey = aq_parent(self.context)
        footer_txt = self.t(
            _(
                "report_survey_revision",
                default=u"This document was based on the OiRA Tool '${title}' "
                u"of revision date ${date}.",
                mapping={
                    "title": survey.published[1],
                    "date": formatDate(request, survey.published[2]),
                },
            ))
        footer = doc.sections[0].footer
        f_table = footer.tables[0]
        paragraph = f_table.cell(0, 0).paragraphs[0]
        paragraph.style = "Footer"
        paragraph.text = footer_txt
コード例 #5
0
ファイル: report.py プロジェクト: pombredanne/osha.oira
    def addMeasure(self, document, heading, section, measure):
        """ Requirements for how the measure section should be displayed are
            in #2611
        """
        t = lambda txt: "".join(["\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)])
        ss = document.StyleSheet
        styles = ss.ParagraphStyles

        table = Table(9500)
        thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE)
        no_edge = BorderPropertySet(width=0, colour=ss.Colours.White)
        p = Paragraph(
            styles.MeasureHeading,
            ParagraphPropertySet(left_indent=300, right_indent=300),
            t(_("header_measure_single", default=u"Measure")),
        )
        c = Cell(p, FramePropertySet(thin_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        ss = document.StyleSheet
        styles = document.StyleSheet.ParagraphStyles
        headings = [
            t(_("label_measure_action_plan", default=u"General approach (to " u"eliminate or reduce the risk)")),
            t(
                _(
                    "label_measure_prevention_plan",
                    default=u"Specific action(s) " u"required to implement this approach",
                )
            ),
            t(_("label_measure_requirements", default=u"Level of expertise " u"and/or requirements needed")),
            t(_("label_action_plan_responsible", default=u"Who is " u"responsible?")),
            t(_("label_action_plan_budget", default=u"Budget")),
            t(_("label_action_plan_start", default=u"Planning start")),
            t(_("label_action_plan_end", default=u"Planning end")),
        ]
        m = measure
        values = [
            m.action_plan,
            m.prevention_plan,
            m.requirements,
            m.responsible,
            m.budget and str(m.budget) or "",
            m.planning_start and formatDate(self.request, m.planning_start) or "",
            m.planning_end and formatDate(self.request, m.planning_end) or "",
        ]
        for heading, value in zip(headings, values):
            p = Paragraph(styles.MeasureField, heading)
            c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge))
            table.AddRow(c)

            if headings.index(heading) == len(headings) - 1:
                frame = FramePropertySet(no_edge, thin_edge, thin_edge, thin_edge)
            else:
                frame = FramePropertySet(no_edge, thin_edge, no_edge, thin_edge)

            p = Paragraph(styles.Normal, ParagraphPropertySet(left_indent=600, right_indent=600), value)
            c = Cell(p, frame)
            table.AddRow(c)

        section.append(table)
コード例 #6
0
ファイル: report.py プロジェクト: pombredanne/Euphorie
def createSection(document, survey, survey_session, request):
    t = lambda txt: translate(txt, context=request)
    footer = t(_(
        "report_survey_revision",
        default=u"This report was based on the survey '${title}' of revision "
                u"date ${date}.",
        mapping={"title": survey.published[1],
                 "date": formatDate(request, survey.published[2])}))
    # rtfng does not like unicode footers
    footer = Paragraph(
        document.StyleSheet.ParagraphStyles.Footer,
        "".join(["\u%s?" % str(ord(e)) for e in footer]))

    section = Section()
    page_header = []
    for part in t(_(u'Page ${number} of ${total}')).split():
        if part == '${number}':
            page_header.append(PAGE_NUMBER)
        elif part == '${total}':
            page_header.append(TOTAL_PAGES)
        else:
            page_header.append(part)
        page_header.append(' ')
    section.Header.append(Paragraph(
        document.StyleSheet.ParagraphStyles.Footer, survey_session.title))
    section.Header.append(Paragraph(
        document.StyleSheet.ParagraphStyles.PageNumber, *page_header))
    section.Footer.append(footer)
    section.SetBreakType(section.PAGE)
    document.Sections.append(section)
    return section
コード例 #7
0
    def add_measure(self, doc, heading, measure, implemented=False):
        doc.add_paragraph(heading, style="Measure Heading")
        headings = [
            self.t(
                _(
                    "label_measure_action_plan",
                    default="General approach (to "
                    "eliminate or reduce the risk)",
                ))
        ]
        if not implemented:
            headings = headings + [
                self.t(
                    _(
                        "label_measure_requirements",
                        default="Level of expertise and/or requirements needed",
                    )),
                self.t(
                    _("label_action_plan_responsible",
                      default="Who is responsible?")),
                self.t(_("label_action_plan_budget", default="Budget")),
                self.t(_("label_action_plan_start", default="Planning start")),
                self.t(_("label_action_plan_end", default="Planning end")),
            ]

        m = measure
        values = [_simple_breaks(m.action or "")]
        if not implemented:
            values = values + [
                _simple_breaks(m.requirements or ""),
                m.responsible,
                m.budget and str(m.budget) or "",
                m.planning_start and formatDate(self.request, m.planning_start)
                or "",
                m.planning_end and formatDate(self.request, m.planning_end)
                or "",
            ]
        for heading, value in zip(headings, values):
            doc.add_paragraph(heading, style="MeasureField")
            doc = HtmlToWord(value, doc, style="MeasureText")
コード例 #8
0
    def set_session_title_row(self, data):
        """This fills the workspace activity run with some text

        The run is empirically determined by studying the template.
        This is in a paragraph structure before the first table.
        Tou may want to change this if you change the template.
        Be aware that the paragraph is the 2nd only
        after this class is initialized.
        We have 2 fields to fill, all following the same principle
        """

        data["today"] = formatDate(self.request, date.today())

        for row, values in self.session_title_lookup.items():
            for num, settings in values.items():
                self.template.paragraphs[
                    self.paragraphs_offset +
                    row].runs[num].text = api.portal.translate(
                        settings["title"])
                _r = self.template.paragraphs[self.paragraphs_offset + row +
                                              1].runs[num]
                # This run should be set in two paragraphs (which appear clones)
                # One is inside a mc:Choice and the other is inside a mc:Fallback
                for subpar in _r._element.findall(".//%s" % qn("w:p")):
                    subpar.clear_content()
                    subrun = subpar.add_r()
                    subrun.text = data.get(settings.get("fname", ""), "") or ""
                    subrpr = subrun.get_or_add_rPr()
                    subrpr.get_or_add_rFonts()
                    subrpr.get_or_add_rFonts().set(qn("w:ascii"), "CorpoS")
                    subrpr.get_or_add_rFonts().set(qn("w:hAnsi"), "CorpoS")
                    subrpr.get_or_add_sz().set(qn("w:val"), "28")
                    szCs = OxmlElement("w:szCs")
                    szCs.attrib[qn("w:val")] = "14"
                    subrpr.append(szCs)

        if data["comment"]:
            self.template.paragraphs[self.paragraphs_offset + row +
                                     2].insert_paragraph_before(
                                         data["comment"])

        header = self.template.sections[self.sections_offset].header
        header.paragraphs[1].text = "{title}{extra}".format(
            title=data["survey_title"], extra=self.title_extra.strip())

        # And now we handle the document footer
        footer = self.template.sections[self.sections_offset].footer
        # The footer contains a table with 3 columns:
        # left we have a logo, center for text, right for the page numbers
        cell1, cell2, cell3 = footer.tables[0].row_cells(0)
        cell2.paragraphs[0].text = "{}".format(
            date.today().strftime("%d.%m.%Y"))
コード例 #9
0
    def set_session_title_row(self, data):
        """This fills the workspace activity run with some text"""
        request = self.request
        self.template.paragraphs[self.paragraphs_offset].text = data["heading"]
        txt = self.t(_("toc_header", default="Contents"))
        par_contents = self.template.paragraphs[self.paragraphs_offset + 1]
        par_contents.text = txt
        par_toc = self.template.paragraphs[self.paragraphs_offset + 2]
        for nodes, heading in zip(data["nodes"], data["section_headings"]):
            if not nodes:
                continue
            par_toc.insert_paragraph_before(heading, style="TOC Heading 1")

        if data.get("comment"):
            par_toc.insert_paragraph_before("")
            par_toc.insert_paragraph_before(data["comment"])

        survey = self.context.aq_parent

        header = self.template.sections[self.sections_offset].header
        header_table = header.tables[0]
        header_table.cell(0, 0).paragraphs[0].text = data["title"]
        header_table.cell(0, 1).paragraphs[0].text = formatDate(
            request, date.today())

        footer_txt = self.t(
            _(
                "report_survey_revision",
                default="This document was based on the OiRA Tool '${title}' "
                "of revision date ${date}.",
                mapping={
                    "title": survey.published[1],
                    "date": formatDate(request, survey.published[2]),
                },
            ))
        footer = self.template.sections[self.sections_offset].footer
        paragraph = footer.tables[0].cell(0, 0).paragraphs[0]
        paragraph.style = "Footer"
        paragraph.text = footer_txt
コード例 #10
0
def createIdentificationReportSection(document, survey, request):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section()

    footer_txt = t(
        _("report_identification_revision",
          default=u"This document was based on the OiRA Tool '${title}' of "
          u"revision date ${date}.",
          mapping={
              "title": survey.published[1],
              "date": formatDate(request, survey.published[2])
          }))
    header = Table(4750, 4750)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  SessionManager.session.title))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props,
                  formatDate(request, datetime.today())))
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  pp(alignment=pp.LEFT), footer_txt))
    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    section.SetBreakType(section.PAGE)
    document.Sections.append(section)
    return section
コード例 #11
0
def createSection(document, survey, request, first_page_number=1):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section(break_type=Section.PAGE,
                      first_page_number=first_page_number)
    footer_txt = t(
        _("report_survey_revision",
            default=u"This report was based on the OiRA Tool '${title}' "\
                    u"of revision date ${date}.",
            mapping={"title": survey.published[1],
                    "date": formatDate(request, survey.published[2])}))

    header = Table(4750, 4750)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  survey.published[1]))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props,
                  formatDate(request, datetime.today())))
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    # rtfng does not like unicode footers
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  pp(alignment=pp.LEFT), footer_txt))

    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    document.Sections.append(section)
    return section
コード例 #12
0
ファイル: survey.py プロジェクト: euphorie/Euphorie
    def set_session_title_row(self, data):

        request = self.request

        # Remove existing paragraphs
        for paragraph in self.template.paragraphs:
            delete_paragraph(paragraph)

        header = self.template.sections[0].header
        header_table = header.tables[0]
        header_table.cell(0, 0).paragraphs[0].text = data["title"]
        header_table.cell(0, 1).paragraphs[0].text = formatDate(
            request, date.today())

        if getattr(self.context, "published"):
            footer_txt = "This OiRA tool was last published {date}.".format(
                date=self.context.published.strftime("%Y/%m/%d"))
        else:
            footer_txt = "This OiRA tool is currently not published."

        footer = self.template.sections[0].footer
        paragraph = footer.tables[0].cell(0, 0).paragraphs[0]
        paragraph.style = "Footer"
        paragraph.text = footer_txt
コード例 #13
0
ファイル: report.py プロジェクト: euphorie/osha.oira
    def create_workbook(self):
        """Create an Excel workbook containing the all risks and measures."""
        t = lambda txt: translate(txt, context=self.request)  # noqa: E731
        survey = self.webhelpers._survey
        book = Workbook()
        ws1 = book.active
        ws1.title = t(_("report_timeline_title", default="Timeline"))

        header_text = "{title}{extra} - {action_plan}".format(
            title=survey.title,
            extra=self.title_extra.strip(),
            action_plan=t(_("label_action_plan", default="Action Plan")),
        )
        ws1["A1"] = header_text

        font_basic = ws1["A1"].font
        font_large = copy(font_basic)
        font_large.size = 18
        ws1["A1"].font = font_large

        image_filename = resource_filename("osha.oira.client",
                                           "resources/oira-logo-colour.png")
        logo = Image(image_filename)
        ws1.add_image(logo, "K1")
        ws1.row_dimensions[1].height = 70
        ws1.merge_cells("A1:K1")

        font_bold = copy(font_basic)
        font_bold.bold = True

        alignment_basic = ws1["A1"].alignment.copy()
        alignment_basic.wrap_text = True
        alignment_basic.vertical = "center"
        alignment_basic.horizontal = "left"
        alignment_header = copy(alignment_basic)
        alignment_header.horizontal = "center"

        ws1.cell(row=1, column=1).alignment = alignment_basic

        b_thin = Side(border_style="thin", color="000000")
        b_double = Side(border_style="medium", color="000000")

        ws1["A2"] = t(_("label_title", default="Title"))
        ws1["A2"].font = font_bold
        ws1["B2"] = self.session.title
        ws1["B2"].fill = PatternFill("solid", fgColor="DDDDDD")
        ws1.merge_cells("B2:C2")
        ws1["E2"] = t(_("label_report_date", default="Date of editing"))
        ws1["E2"].font = font_bold
        ws1["F2"] = formatDate(self.request, self.session.modified)
        ws1["F2"].fill = PatternFill("solid", fgColor="DDDDDD")
        for cell in tuple(ws1.iter_rows(2, 2))[0]:
            cell.alignment = alignment_basic
        ws1.row_dimensions[2].height = 30

        for (column, (type, key, title)) in enumerate(self.columns, 1):
            if key in self.combine_keys:
                continue
            cell = ws1.cell(row=3, column=column)
            cell.value = t(title)
            cell.font = font_bold
            cell.alignment = alignment_header
            # Light baby blue background color
            cell.fill = PatternFill("solid", fgColor="97CDDD")
            cell.border = Border(top=b_double,
                                 left=b_double,
                                 right=b_double,
                                 bottom=b_double)
            letter = get_column_letter(column)
            if title in ("report_timeline_measure",
                         "report_timeline_risk_title"):
                ws1.column_dimensions[letter].width = len(cell.value) + 50
            elif title in ("label_risk_number", ):
                ws1.column_dimensions[letter].width = len(cell.value)
            else:
                ws1.column_dimensions[letter].width = len(cell.value) + 5
        ws1.row_dimensions[3].height = 60

        for (row, (module, risk,
                   measure)) in enumerate(self.get_measures(), 4):
            column = 1

            if not getattr(risk, "is_custom_risk", None):
                zodb_node = self.context.restrictedTraverse(
                    risk.zodb_path.split("/"))
            else:
                zodb_node = None

            for (type, key, title) in self.columns + self.extra_cols:
                value = None
                if type == "measure":
                    value = getattr(measure, key, None)
                elif type == "risk":
                    value = getattr(risk, key, None)
                    if key == "priority":
                        value = self.priority_name(value)
                    elif key == "title":
                        if zodb_node is None:
                            value = getattr(risk, key, None)
                        elif (zodb_node.problem_description
                              and zodb_node.problem_description.strip()):
                            value = zodb_node.problem_description
                    elif key == "number":
                        if risk.is_custom_risk:
                            num_elems = value.split(".")
                            value = ".".join(["Ω"] + num_elems[1:])

                elif type == "module":
                    if key == "title" and module.depth > 1:
                        titles = []
                        m = module
                        while m:
                            title = getattr(m, "title", None)
                            if title:
                                titles.append(m.title)
                            m = m.parent
                        titles.reverse()
                        value = ", ".join(titles)
                    else:
                        if module.zodb_path == "custom-risks":
                            lang = getattr(self.request, "LANGUAGE", "en")
                            if "-" in lang:
                                elems = lang.split("-")
                                lang = "{0}_{1}".format(
                                    elems[0], elems[1].upper())
                            value = translate(
                                _("Custom risks", default="Custom risks"),
                                target_language=lang,
                            )
                        else:
                            value = getattr(module, key, None)
                if key in self.combine_keys:
                    if value is not None:
                        # osha wants to combine action_plan (col 5 / E),
                        # and requirements in one cell
                        if not ws1.cell(row=row, column=5).value:
                            ws1.cell(row=row, column=5).value = ""
                        ws1.cell(row=row, column=5).value += "\r\n" + value
                else:
                    cell = ws1.cell(row=row, column=column)
                    if value is not None:
                        if key == "number":
                            # force string
                            cell.set_explicit_value(value)
                        else:
                            cell.value = value
                        if key == "budget":
                            cell.style = "Comma"
                    cell.alignment = alignment_basic
                    cell.border = Border(top=b_thin,
                                         left=b_thin,
                                         right=b_thin,
                                         bottom=b_thin)

                    column += 1
        ws1.freeze_panes = "A4"
        ws1.set_printer_settings(paper_size=ws1.PAPERSIZE_A4,
                                 orientation="landscape")
        return book
コード例 #14
0
ファイル: report.py プロジェクト: pombredanne/Euphorie
    def addMeasure(self, document, section, measure):
        normal_style = document.StyleSheet.ParagraphStyles.Normal
        t = lambda txt: translate(txt, context=self.request)

        table = Table(TabPropertySet.DEFAULT_WIDTH * 5,
                      TabPropertySet.DEFAULT_WIDTH * 8)
        if measure.action_plan:
            table.append(
                Cell(Paragraph(
                    normal_style,
                    t(_("report_measure_actionplan",
                        default=u"Action plan:")))),
                Cell(Paragraph(normal_style, measure.action_plan)))
        if measure.prevention_plan:
            table.append(
                Cell(Paragraph(normal_style,
                     t(_("report_measure_preventionplan",
                         default=u"Prevention plan:")))),
                Cell(Paragraph(normal_style, measure.prevention_plan)))
        if measure.requirements:
            table.append(
                Cell(Paragraph(
                    normal_style,
                    t(_("report_measure_requirements",
                        default=u"Requirements:")))),
                Cell(Paragraph(normal_style, measure.requirements)))
        if table.Rows:
            section.append(table)

        if measure.responsible and not \
                (measure.planning_start or measure.planning_end):
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_responsible",
                    default=u"${responsible} is responsible for this task.",
                    mapping={"responsible": measure.responsible}))))
        elif measure.responsible and measure.planning_start and \
                not measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_responsible_and_start",
                    default=u"${responsible} is responsible for this task "
                            u"which starts on ${start}.",
                    mapping={"responsible": measure.responsible,
                             "start": formatDate(self.request,
                                                 measure.planning_start)}))))
        elif measure.responsible and \
                not measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_responsible_and_end",
                    default=u"${responsible} is responsible for this task "
                            u"which ends on ${end}.",
                    mapping={"responsible": measure.responsible,
                             "end": formatDate(self.request,
                                               measure.planning_end)}))))
        elif measure.responsible and \
                measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_full",
                    default=u"${responsible} is responsible for this task "
                            u"which starts on ${start} and ends on ${end}.",
                    mapping={"responsible": measure.responsible,
                             "start": formatDate(self.request,
                                                 measure.planning_start),
                             "end": formatDate(self.request,
                                               measure.planning_end)}))))
        elif not measure.responsible and \
                measure.planning_start and not measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_start_only",
                    default=u"This task starts on ${start}.",
                    mapping={"start": formatDate(
                        self.request,
                        measure.planning_start)}))))
        elif not measure.responsible and \
                not measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_end_only",
                    default=u"This task ends on ${end}.",
                    mapping={"end": formatDate(self.request,
                                               measure.planning_end)}))))
        elif not measure.responsible \
                and measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_start_and_stop",
                    default=u"This task starts on ${start} and ends on "
                            u"${end}.",
                    mapping={"start": formatDate(self.request,
                                                 measure.planning_start),
                            "end": formatDate(self.request,
                                              measure.planning_end)}))))
        if measure.budget:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_budget",
                    default=u"There is a budget of ${amount} for "
                            u"this measure.",
                    mapping={"amount": measure.budget}))))
コード例 #15
0
ファイル: tools.py プロジェクト: euphorie/NuPlone
 def formatDate(self, date, length="long"):
     return utils.formatDate(self.request, date, length)
コード例 #16
0
ファイル: report.py プロジェクト: euphorie/tno.euphorie
    def addCompanyInformation(self, document):
        request=self.request
        company=self.session.dutch_company
        t=lambda txt: translate(txt, context=request)
        section = createSection(document, self.context, self.session,
                self.request)
        normal_style=document.StyleSheet.ParagraphStyles.Normal
        missing=t(eu_("missing_data", default=u"Not provided"))

        section.append(Paragraph(
            document.StyleSheet.ParagraphStyles.Heading1,
            t(eu_("plan_report_company_header", default=u"Company details"))))

        table=Table(TabPropertySet.DEFAULT_WIDTH*3, TabPropertySet.DEFAULT_WIDTH*8)

        field=DutchCompanySchema["title"]
        table.append(
                Cell(Paragraph(normal_style, str(field.title))),
                Cell(Paragraph(normal_style, company.title if company.title else missing)))

        address=formatAddress(company.address_visit_address,
                company.address_visit_postal, company.address_visit_city)
        table.append(
                Cell(Paragraph(normal_style, "Bezoekadres bedrijf")),
                Cell(Paragraph(normal_style, address if address else missing)))

        address=formatAddress(company.address_postal_address,
                company.address_postal_postal, company.address_postal_city)
        table.append(
                Cell(Paragraph(normal_style, "Postadres bedrijf")),
                Cell(Paragraph(normal_style, address if address else missing)))

        for key in ["email", "phone", "activity", "submitter_name",
                      "submitter_function", "department", "location"]:
            field=DutchCompanySchema[key]
            value=getattr(company, key, None)
            table.append(
                    Cell(Paragraph(normal_style, field.title)),
                    Cell(Paragraph(normal_style, value if value else missing))),

        formatDecimal=request.locale.numbers.getFormatter("decimal").format
        field=DutchCompanySchema["absentee_percentage"]
        table.append(
                Cell(Paragraph(normal_style, field.title)),
                Cell(Paragraph(normal_style, u"%s %%" % formatDecimal(company.absentee_percentage) if company.absentee_percentage else missing)))

        for key in [ "accidents", "incapacitated_workers"]:
            field=DutchCompanySchema[key]
            value=getattr(company, key, None)
            table.append(
                    Cell(Paragraph(normal_style, field.title)),
                    Cell(Paragraph(normal_style, "%d" % value if value is not None else missing)))

        field=DutchCompanySchema["submit_date"]
        table.append(
                Cell(Paragraph(normal_style, field.title)),
                Cell(Paragraph(normal_style, formatDate(request, company.submit_date) if company.submit_date else missing)))

        field=DutchCompanySchema["employees"]
        table.append(
                Cell(Paragraph(normal_style, field.title)),
                Cell(Paragraph(normal_style, field.vocabulary.getTerm(company.employees).title if company.employees else missing)))

        field=DutchCompanySchema["arbo_expert"]
        table.append(
                Cell(Paragraph(normal_style, str(field.title))),
                Cell(Paragraph(normal_style, company.arbo_expert if company.arbo_expert else missing)))

        section.append(table)
コード例 #17
0
ファイル: tools.py プロジェクト: jean/NuPlone
 def formatDate(self, date, length="long"):
     return utils.formatDate(self.request, date, length)
コード例 #18
0
    def set_session_title_row(self, data):
        """This fills the workspace activity run with some text"""
        request = self.request
        doc = self.template
        header = doc.sections[0].header
        h_table = header.tables[0]

        h_table.cell(0, 0).paragraphs[0].text = data["heading"]
        h_table.cell(0, 1).paragraphs[0].text = u"Datum download: {}".format(
            formatDate(request, date.today()))

        doc.paragraphs[0].text = data["heading"]

        heading1 = self.t(
            _("plan_report_intro_header", default=u"Introduction"))
        intro = self.t(
            _(
                "plan_report_intro_1",
                default=u"By filling in the list of questions, you have "
                u"completed a risk assessment. This assessment is used to "
                u"draw up an action plan. The progress of this action "
                u"plan must be discussed annually and a small report must "
                u"be written on the progress. Certain subjects might have "
                u"been completed and perhaps new subjects need to be "
                u"added.",
            ))

        doc.add_paragraph(heading1, style="Heading 1")
        doc.add_paragraph(intro)

        survey = aq_parent(self.context)
        footer_txt = self.t(
            _(
                "report_survey_revision",
                default=u"This document was based on the OiRA Tool '${title}' "
                u"of revision date ${date}.",
                mapping={
                    "title": survey.published[1],
                    "date": formatDate(request, survey.published[2]),
                },
            ))
        footer = doc.sections[0].footer
        f_table = footer.tables[0]
        paragraph = f_table.cell(0, 0).paragraphs[0]

        # Example code for inserting image (into a newly created table)
        # width = header_table.cell(0, 0).width + header_table.cell(0, 1).width
        # table = footer.add_table(rows=1, cols=2, width=width)
        # wh = self.context.restrictedTraverse('webhelpers')
        # image = wh.get_sector_logo
        # img = image.data._blob.open()
        # from docx.shared import Cm
        # paragraph = table.cell(0, 1).paragraphs[0]
        # paragraph.add_run().add_picture(img, width=Cm(1))
        # paragraph = table.cell(0, 0).paragraphs[0]

        paragraph.style = "Footer"
        paragraph.text = footer_txt

        doc.add_page_break()
        doc.add_paragraph(
            self.t(_("plan_report_company_header",
                     default=u"Company details")),
            style="Heading 1",
        )
        missing = self.t(_("missing_data", default=u"Not provided"))
        company = self.session.dutch_company
        table = doc.add_table(rows=1, cols=2)
        total_width = table.columns[0].width + table.columns[1].width
        table.columns[0].width = int(total_width * 0.20)
        table.columns[1].width = int(total_width * 0.80)

        field = DutchCompanySchema["title"]
        row_cells = table.rows[0].cells
        row_cells[0].text = str(field.title)
        row_cells[
            1].text = company.title if company and company.title else missing

        row_cells = table.add_row().cells
        address = (formatAddress(
            company.address_visit_address,
            company.address_visit_postal,
            company.address_visit_city,
        ) if company else None)

        row_cells[0].text = "Bezoekadres bedrijf"
        row_cells[1].text = address if address else missing
        row_cells = table.add_row().cells

        address = (formatAddress(
            company.address_postal_address,
            company.address_postal_postal,
            company.address_postal_city,
        ) if company else None)
        row_cells[0].text = "Postadres bedrijf"
        row_cells[1].text = address if address else missing

        for key in [
                "email",
                "phone",
                "activity",
                "submitter_name",
                "submitter_function",
                "department",
                "location",
        ]:
            field = DutchCompanySchema[key]
            value = getattr(company, key, None)
            row_cells = table.add_row().cells
            row_cells[0].text = str(field.title)
            row_cells[1].text = value if value else missing

        formatDecimal = request.locale.numbers.getFormatter("decimal").format
        field = DutchCompanySchema["absentee_percentage"]
        row_cells = table.add_row().cells
        row_cells[0].text = str(field.title)
        row_cells[1].text = (u"%s %%" %
                             formatDecimal(company.absentee_percentage)
                             if company and company.absentee_percentage else
                             missing)

        for key in ["accidents", "incapacitated_workers"]:
            field = DutchCompanySchema[key]
            value = getattr(company, key, None)
            row_cells = table.add_row().cells
            row_cells[0].text = str(field.title)
            row_cells[1].text = "%d" % value if value else missing

        field = DutchCompanySchema["submit_date"]
        row_cells = table.add_row().cells
        row_cells[0].text = str(field.title)
        row_cells[1].text = (formatDate(request, company.submit_date)
                             if company and company.submit_date else missing)

        field = DutchCompanySchema["employees"]
        row_cells = table.add_row().cells
        row_cells[0].text = str(field.title)
        row_cells[1].text = (field.vocabulary.getTerm(company.employees).title
                             if company and company.employees else missing)

        field = DutchCompanySchema["arbo_expert"]
        row_cells = table.add_row().cells
        row_cells[0].text = str(field.title)
        row_cells[1].text = (company.arbo_expert
                             if company and company.arbo_expert else missing)

        doc.add_page_break()
コード例 #19
0
    def addMeasure(self, document, heading, section, measure):
        """ Requirements for how the measure section should be displayed are
            in #2611
        """
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])
        ss = document.StyleSheet
        styles = ss.ParagraphStyles

        table = Table(9500)
        thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE)
        no_edge = BorderPropertySet(width=0, colour=ss.Colours.White)
        p = Paragraph(styles.MeasureHeading,
                      ParagraphPropertySet(left_indent=300, right_indent=300),
                      t(_("header_measure_single", default=u"Measure")))
        c = Cell(p, FramePropertySet(thin_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        ss = document.StyleSheet
        styles = document.StyleSheet.ParagraphStyles
        headings = [
            t(
                _("label_measure_action_plan",
                  default=u"General approach (to "
                  u"eliminate or reduce the risk)")),
            t(
                _("label_measure_prevention_plan",
                  default=u"Specific action(s) "
                  u"required to implement this approach")),
            t(
                _("label_measure_requirements",
                  default=u"Level of expertise "
                  u"and/or requirements needed")),
            t(
                _("label_action_plan_responsible",
                  default=u"Who is "
                  u"responsible?")),
            t(_("label_action_plan_budget", default=u"Budget")),
            t(_("label_action_plan_start", default=u"Planning start")),
            t(_("label_action_plan_end", default=u"Planning end")),
        ]
        m = measure
        values = [
            m.action_plan,
            m.prevention_plan,
            m.requirements,
            m.responsible,
            m.budget and str(m.budget) or '',
            m.planning_start and formatDate(self.request, m.planning_start)
            or '',
            m.planning_end and formatDate(self.request, m.planning_end) or '',
        ]
        for heading, value in zip(headings, values):
            p = Paragraph(styles.MeasureField, heading)
            c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge,
                                         thin_edge))
            table.AddRow(c)

            if headings.index(heading) == len(headings) - 1:
                frame = FramePropertySet(no_edge, thin_edge, thin_edge,
                                         thin_edge)
            else:
                frame = FramePropertySet(no_edge, thin_edge, no_edge,
                                         thin_edge)

            p = Paragraph(
                styles.Normal,
                ParagraphPropertySet(left_indent=600, right_indent=600), value)
            c = Cell(p, frame)
            table.AddRow(c)

        section.append(table)