def create_workbook(self): """Create an Excel workbook containing the all risks and measures.""" book = Workbook() sheet = book.worksheets[0] sheet.title = translate(_("report_timeline_title", default="Timeline"), context=self.request) survey = self.context.aq_parent for (column, (ntype, key, title)) in enumerate(self.columns): sheet.cell(row=1, column=column + 1).value = translate( title, context=self.request) row = 2 for (module, risk, measure) in self.get_measures(): if risk.identification in ["n/a", "yes"]: continue column = 1 if risk.is_custom_risk: zodb_node = None else: zodb_node = survey.restrictedTraverse( risk.zodb_path.split("/")) for (ntype, key, title) in self.columns: value = None if ntype == "measure": value = getattr(measure, key, None) elif ntype == "risk": value = getattr(risk, key, None) if key == "priority": value = self.priority_name(value) elif key == "title": if (getattr(zodb_node, "problem_description", None) 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 ntype == "module": if key == "title": if risk.is_custom_risk: value = utils.get_translated_custom_risks_title( self.request) else: value = module.title if value is not None: cell = sheet.cell(row=row, column=column) if key == "number": # force sting cell.set_explicit_value(value) else: cell.value = value column += 1 row += 1 return book
def addIdentificationResults(self, document): survey = self.request.survey section = createIdentificationReportSection( document, self.context, self.request) styles = document.StyleSheet.ParagraphStyles header_styles = { 0: styles.Heading2, 1: styles.Heading3, 2: styles.Heading4, 3: styles.Heading5, 4: styles.Heading6, } for node in self.getNodes(): section.append( Paragraph( header_styles.get(node.depth, styles.Heading6), u"%s %s" % (node.number, node.title)) ) if node.type != "risk": continue zodb_node = survey.restrictedTraverse(node.zodb_path.split("/")) section.append( Paragraph( styles.Normal, utils.html_unescape( htmllaundry.StripMarkup(zodb_node.description)) ) ) for i in range(0, 8): p = Paragraph(styles.Normal, " ") section.append(p) tabs = TabPropertySet( section.TwipsToRightMargin(), alignment=TabPropertySet.RIGHT, leader=getattr(TabPropertySet, 'UNDERLINE') ) p = Paragraph(styles.Normal, ParagraphPropertySet(tabs=[tabs])) p.append(TAB) section.append(p) if node.comment and node.comment.strip(): section.append(Paragraph(styles.Comment, node.comment))
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 = 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))) if getattr(node, "identification", None) == "no": body.append( Paragraph( styles.Normal, ParagraphPropertySet(left_indent=300, right_indent=300), t(_(utils.html_unescape(htmllaundry.StripMarkup(zodb_node.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)
def addIdentificationResults(self, document): survey = self.request.survey section = createIdentificationReportSection( document, self.context, self.request) lang = getattr(self.request, 'LANGUAGE', 'en') if "-" in lang: elems = lang.split("-") lang = "{0}_{1}".format(elems[0], elems[1].upper()) styles = document.StyleSheet.ParagraphStyles normal_style = document.StyleSheet.ParagraphStyles.Normal header_styles = { 0: styles.Heading2, 1: styles.Heading3, 2: styles.Heading4, 3: styles.Heading5, 4: styles.Heading6, } for node in self.getNodes(): section.append( Paragraph( header_styles.get(node.depth, styles.Heading6), u"%s %s" % (node.number, node.title)) ) if node.type != "risk": continue description = legal_reference = None if not getattr(node, 'is_custom_node', None): zope_node = survey.restrictedTraverse( node.zodb_path.split("/"), None) if zope_node is not None: description = getattr(zope_node, "description", None) legal_reference = getattr(zope_node, "legal_reference", None) if description and description.strip(): for el in report.HtmlToRtf(description, normal_style): section.append(el) if legal_reference and legal_reference.strip(): p = Paragraph(styles.Normal, "") section.append(p) section.append( Paragraph( styles.LegalHeading, translate(_( 'header_legal_references', default=u'Legal and policy references'), target_language=lang), ) ) p = Paragraph(styles.Normal, "") section.append(p) for el in report.HtmlToRtf(legal_reference, normal_style): section.append(el) tabs = TabPropertySet( section.TwipsToRightMargin(), alignment=TabPropertySet.RIGHT, leader=getattr(TabPropertySet, 'UNDERLINE') ) p = Paragraph(styles.Normal, ParagraphPropertySet(tabs=[tabs])) p.append(TAB) section.append(p) if node.comment and node.comment.strip(): section.append(Paragraph(styles.Comment, node.comment))
def addIdentificationResults(self, document): survey = self.request.survey section = createIdentificationReportSection(document, self.context, self.request) lang = getattr(self.request, 'LANGUAGE', 'en') if "-" in lang: elems = lang.split("-") lang = "{0}_{1}".format(elems[0], elems[1].upper()) styles = document.StyleSheet.ParagraphStyles normal_style = document.StyleSheet.ParagraphStyles.Normal header_styles = { 0: styles.Heading2, 1: styles.Heading3, 2: styles.Heading4, 3: styles.Heading5, 4: styles.Heading6, } for node in self.getNodes(): section.append( Paragraph(header_styles.get(node.depth, styles.Heading6), u"%s %s" % (node.number, node.title))) if node.type != "risk": continue description = legal_reference = None if not getattr(node, 'is_custom_node', None): zope_node = survey.restrictedTraverse( node.zodb_path.split("/"), None) if zope_node is not None: description = getattr(zope_node, "description", None) legal_reference = getattr(zope_node, "legal_reference", None) if description and description.strip(): for el in report.HtmlToRtf(description, normal_style): section.append(el) if legal_reference and legal_reference.strip(): p = Paragraph(styles.Normal, "") section.append(p) section.append( Paragraph( styles.LegalHeading, translate(_('header_legal_references', default=u'Legal and policy references'), target_language=lang), )) p = Paragraph(styles.Normal, "") section.append(p) for el in report.HtmlToRtf(legal_reference, normal_style): section.append(el) tabs = TabPropertySet(section.TwipsToRightMargin(), alignment=TabPropertySet.RIGHT, leader=getattr(TabPropertySet, 'UNDERLINE')) p = Paragraph(styles.Normal, ParagraphPropertySet(tabs=[tabs])) p.append(TAB) section.append(p) if node.comment and node.comment.strip(): section.append(Paragraph(styles.Comment, node.comment))
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)