Files
redmine-reporter/redmine_reporter/formatter_odt.py
Кокос Артем Николаевич 9a2f753480 Album orient by using templ. doc
2026-01-21 14:22:18 +07:00

75 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import List, Tuple
from redminelib.resources import Issue
from odf.opendocument import load
from odf.text import P
from odf.table import Table, TableColumn, TableRow, TableCell
from .formatter import get_version, hours_to_human, STATUS_TRANSLATION
import os
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
# Загружаем шаблон с альбомной ориентацией
template_path = "template.odt"
# template_path = os.path.join(os.path.dirname(__file__), "..", "template.odt")
if not os.path.exists(template_path):
raise FileNotFoundError("Шаблон template.odt не найден. Создайте его вручную в LibreOffice (альбомная ориентация) и сохраните в корень проекта.")
doc = load(template_path)
# Стили уже есть в шаблоне — просто используем их по имени
para_style_name = "Standard" # или другое имя, если вы задали стиль в шаблоне
table_style_name = "Table1" # LibreOffice обычно даёт такое имя
# Заголовок отчёта
header_text = "Кокос Артём Николаевич. Отчет за месяц Июль."
header_paragraph = P(stylename=para_style_name, text=header_text)
doc.text.addElement(header_paragraph)
# Таблица
table = Table(name="Report", stylename=table_style_name)
for _ in range(5):
table.addElement(TableColumn())
# Заголовки
header_row = TableRow()
headers = ["Наименование Проекта", "Номер версии*", "Задача", "Статус Готовность*", "Затрачено за отчетный период"]
for text in headers:
cell = TableCell()
p = P(stylename=para_style_name, 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()
cells_content = [
display_project,
display_version,
f"{issue.id}. {issue.subject}",
status_ru,
"" # как в скриншоте
]
for col_text in cells_content:
cell = TableCell()
p = P(stylename=para_style_name, text=col_text)
cell.addElement(p)
row.addElement(cell)
table.addElement(row)
prev_project = project
prev_version = version
doc.text.addElement(table)
return doc