73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
from typing import List, Tuple
|
|
from redminelib.resources import Issue
|
|
from odf.opendocument import OpenDocumentText
|
|
from odf.style import Style, TableProperties, TableCellProperties, ParagraphProperties
|
|
from odf.text import P
|
|
from odf.table import Table, TableColumn, TableRow, TableCell
|
|
|
|
from .formatter import get_version, hours_to_human, STATUS_TRANSLATION
|
|
|
|
|
|
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> OpenDocumentText:
|
|
doc = OpenDocumentText()
|
|
|
|
# Стили
|
|
table_style = Style(name="Table", family="table")
|
|
table_style.addElement(TableProperties(width="17cm", align="center"))
|
|
doc.styles.addElement(table_style)
|
|
|
|
cell_style = Style(name="Cell", family="table-cell")
|
|
cell_style.addElement(TableCellProperties(border="0.5pt solid #000000"))
|
|
doc.styles.addElement(cell_style)
|
|
|
|
para_style = Style(name="Para", family="paragraph")
|
|
para_style.addElement(ParagraphProperties(textalign="left"))
|
|
doc.styles.addElement(para_style)
|
|
|
|
# Таблица
|
|
table = Table(name="Report", stylename=table_style)
|
|
for _ in range(5): # 5 колонок
|
|
table.addElement(TableColumn())
|
|
|
|
# Заголовок
|
|
header_row = TableRow()
|
|
headers = ["Проект", "Версия", "Задача", "Статус", "Затрачено"]
|
|
for text in headers:
|
|
cell = TableCell(stylename=cell_style)
|
|
p = P(stylename=para_style, text=text)
|
|
cell.addElement(p)
|
|
header_row.addElement(cell)
|
|
table.addElement(header_row)
|
|
|
|
# Данные
|
|
prev_project = None
|
|
prev_version = None
|
|
for issue, hours in issue_hours:
|
|
project = str(issue.project)
|
|
version = get_version(issue)
|
|
status_en = str(issue.status)
|
|
status_ru = STATUS_TRANSLATION.get(status_en, status_en)
|
|
|
|
display_project = project if project != prev_project else ""
|
|
display_version = version if (project != prev_project or version != prev_version) else ""
|
|
|
|
row = TableRow()
|
|
for col_text in [
|
|
display_project,
|
|
display_version,
|
|
f"{issue.id}. {issue.subject}",
|
|
status_ru,
|
|
hours_to_human(hours)
|
|
]:
|
|
cell = TableCell(stylename=cell_style)
|
|
p = P(stylename=para_style, text=col_text)
|
|
cell.addElement(p)
|
|
row.addElement(cell)
|
|
table.addElement(row)
|
|
|
|
prev_project = project
|
|
prev_version = version
|
|
|
|
doc.text.addElement(table)
|
|
return doc
|