Skip to content

Commit

Permalink
Merge pull request #521 from euphorie/report-short
Browse files Browse the repository at this point in the history
New short report
  • Loading branch information
reinhardt committed Mar 27, 2023
2 parents b5577a7 + e3f612c commit c841177
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 39 deletions.
164 changes: 125 additions & 39 deletions src/euphorie/client/docx/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,14 @@ def set_cell_risk(self, cell, risk):
title, descripton, comment, measures in place
"""
self.set_cell_risk_title(cell, risk)
self.set_cell_risk_comment(cell, risk)
self.set_cell_risk_description(cell, risk)
self.set_cell_risk_measures(cell, risk)

cell.add_paragraph(style="Risk Normal")

def set_cell_risk_title(self, cell, risk):
paragraph = cell.paragraphs[0]
paragraph.style = "Risk Bold List"
paragraph.text = risk["title"]
Expand All @@ -650,10 +658,15 @@ def set_cell_risk(self, cell, risk):
)
paragraph.runs[0].italic = True

def set_cell_risk_comment(self, cell, risk):
if risk["comment"] and risk["comment"].strip():
self.compiler(risk["comment"], cell, style="Risk Normal")

def set_cell_risk_description(self, cell, risk):
if self.show_risk_descriptions:
self.compiler(risk["description"], cell)

def set_cell_risk_measures(self, cell, risk):
if risk["measures"]:
if self.show_risk_descriptions:
cell.add_paragraph()
Expand All @@ -669,55 +682,63 @@ def set_cell_risk(self, cell, risk):
)
for measure in risk["measures"]:
self.compiler(_simple_breaks(measure), cell, style="Risk Italics List")
paragraph = cell.add_paragraph(style="Risk Normal")

def set_cell_actions(self, cell, risk):
"""Take the risk and add the appropriate text:
planned measures
"""
paragraph = cell.paragraphs[0]
for idx, action in enumerate(risk["actions"]):
if idx != 0:
paragraph = cell.add_paragraph()
self.compiler(_simple_breaks(action["text"]), cell, style="Measure List")
if action.get("requirements", None):
paragraph = cell.add_paragraph(style="Measure Indent")
run = paragraph.add_run()
run.text = api.portal.translate(
_("report_competences", default="Required expertise:")
)
run.underline = True
run = paragraph.add_run()
run.text = " "
run = paragraph.add_run()
run.text = (_simple_breaks(action["requirements"]),)
cell.add_paragraph()
self.set_cell_action_text(cell, action)
self.set_cell_action_responsible(cell, action)
self.set_cell_action_date(cell, action)

def set_cell_action_text(self, cell, action):
self.compiler(_simple_breaks(action["text"]), cell, style="Measure List")

def set_cell_action_requirements(self, cell, action):
if action.get("requirements", None):
paragraph = cell.add_paragraph(style="Measure Indent")
run = paragraph.add_run()
run.text = api.portal.translate(
_("report_competences", default="Required expertise:")
)
run.underline = True
run = paragraph.add_run()
run.text = " "
run = paragraph.add_run()
run.text = (_simple_breaks(action["requirements"]),)

def set_cell_action_responsible(self, cell, action):
if action.get("responsible", None):
paragraph = cell.add_paragraph(
api.portal.translate(
_(
"report_responsible",
default="Responsible: ${responsible_name}",
mapping={"responsible_name": action["responsible"]},
)
),
style="Measure Indent",
)
paragraph.runs[0].italic = True

if action.get("responsible", None):
paragraph = cell.add_paragraph(
api.portal.translate(
_(
"report_responsible",
default="Responsible: ${responsible_name}",
mapping={"responsible_name": action["responsible"]},
)
),
style="Measure Indent",
)
paragraph.runs[0].italic = True
if action.get("planning_end", None):
paragraph = cell.add_paragraph(
api.portal.translate(
_(
"report_end_date",
default="To be done by: ${date}",
mapping={"date": action["planning_end"]},
)
),
style="Measure Indent",
)
def set_cell_action_date(self, cell, action):
if action.get("planning_end", None):
paragraph = cell.add_paragraph(
api.portal.translate(
_(
"report_end_date",
default="To be done by: ${date}",
mapping={"date": action["planning_end"]},
)
),
style="Measure Indent",
)

paragraph.runs[0].italic = True
paragraph.runs[0].italic = True

def merge_module_rows(self, row_module, row_risk):
"""This merges the the first cell of the given rows, the one containing
Expand Down Expand Up @@ -940,3 +961,68 @@ def compile(self, data):
skip_planned_measures=False,
use_solutions=True,
)


class DocxCompilerShort(DocxCompilerFullTable):
_base_filename = "oira_short.docx"

justifiable_map = {"yes": "✅", "no": "❌"}

def set_cell_risk(self, cell, risk):
"""Take the risk and add the appropriate text:
title, descripton, comment, measures in place
"""
self.set_cell_risk_title(cell, risk)
self.set_cell_risk_description(cell, risk)
self.set_cell_risk_measures(cell, risk)
self.set_cell_risk_comment(cell, risk)

cell.add_paragraph(style="Risk Normal")

def set_cell_risk_comment(self, cell, risk):
if risk["comment"] and risk["comment"].strip():
cell.add_paragraph()
cell.add_paragraph(
api.portal.translate(
_(
"report_heading_comments",
default="Comments:",
)
),
style="Risk Italics",
)
self.compiler(risk["comment"], cell, style="Risk Italics")

def set_cell_actions(self, cell, risk):
"""Take the risk and add the appropriate text:
planned measures
"""
cell.paragraphs[0]
for idx, action in enumerate(risk["actions"]):
if idx != 0:
cell.add_paragraph()
self.set_cell_action_text(cell, action)
self.set_cell_action_responsible(cell, action)

def set_cell_action_responsible(self, cell, action):
text_responsible = ""
if action.get("responsible", None):
text_responsible = action["responsible"]

if action.get("planning_end", None):
text_date = api.portal.translate(
_(
"report_end_date_short",
default="by ${date}",
mapping={"date": action["planning_end"]},
)
)
text_responsible = " – ".join((text_responsible, text_date))
if text_responsible:
paragraph = cell.add_paragraph(
text_responsible,
style="Measure Indent",
)
paragraph.runs[0].italic = True
8 changes: 8 additions & 0 deletions src/euphorie/client/docx/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
layer="euphorie.client.interfaces.IClientSkinLayer"
/>

<browser:page
name="oira-report-short.docx"
for="euphorie.client.adapters.session_traversal.ITraversedSurveySession"
permission="zope2.View"
class=".views.ActionPlanShortDocxView"
layer="euphorie.client.interfaces.IClientSkinLayer"
/>

<browser:page
name="identification-report.docx"
for="euphorie.client.adapters.session_traversal.ITraversedSurveySession"
Expand Down
Binary file not shown.
5 changes: 5 additions & 0 deletions src/euphorie/client/docx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from euphorie.client.docx.compiler import DocxCompilerFrance
from euphorie.client.docx.compiler import DocxCompilerItaly
from euphorie.client.docx.compiler import DocxCompilerItalyOriginal
from euphorie.client.docx.compiler import DocxCompilerShort
from euphorie.client.docx.compiler import IdentificationReportCompiler
from euphorie.client.utils import get_translated_custom_risks_title
from euphorie.content import MessageFactory as _
Expand Down Expand Up @@ -295,6 +296,10 @@ def _filename(self):
return safe_nativestring(filename) + ".docx"


class ActionPlanShortDocxView(ActionPlanDocxView):
_compiler = DocxCompilerShort


class IdentificationReportDocxView(OfficeDocumentView):
"""Generate a report based on a basic docx template."""

Expand Down

0 comments on commit c841177

Please sign in to comment.