Album orient by using templ. doc
This commit is contained in:
@@ -1,40 +1,42 @@
|
|||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
from redminelib.resources import Issue
|
from redminelib.resources import Issue
|
||||||
from odf.opendocument import OpenDocumentText
|
from odf.opendocument import load
|
||||||
from odf.style import Style, TableProperties, TableCellProperties, ParagraphProperties
|
|
||||||
from odf.text import P
|
from odf.text import P
|
||||||
from odf.table import Table, TableColumn, TableRow, TableCell
|
from odf.table import Table, TableColumn, TableRow, TableCell
|
||||||
|
|
||||||
from .formatter import get_version, hours_to_human, STATUS_TRANSLATION
|
from .formatter import get_version, hours_to_human, STATUS_TRANSLATION
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> OpenDocumentText:
|
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
||||||
doc = OpenDocumentText()
|
# Загружаем шаблон с альбомной ориентацией
|
||||||
|
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)
|
||||||
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"))
|
para_style_name = "Standard" # или другое имя, если вы задали стиль в шаблоне
|
||||||
doc.styles.addElement(cell_style)
|
table_style_name = "Table1" # LibreOffice обычно даёт такое имя
|
||||||
|
|
||||||
para_style = Style(name="Para", family="paragraph")
|
# Заголовок отчёта
|
||||||
para_style.addElement(ParagraphProperties(textalign="left"))
|
header_text = "Кокос Артём Николаевич. Отчет за месяц Июль."
|
||||||
doc.styles.addElement(para_style)
|
header_paragraph = P(stylename=para_style_name, text=header_text)
|
||||||
|
doc.text.addElement(header_paragraph)
|
||||||
|
|
||||||
# Таблица
|
# Таблица
|
||||||
table = Table(name="Report", stylename=table_style)
|
table = Table(name="Report", stylename=table_style_name)
|
||||||
for _ in range(5): # 5 колонок
|
for _ in range(5):
|
||||||
table.addElement(TableColumn())
|
table.addElement(TableColumn())
|
||||||
|
|
||||||
# Заголовок
|
# Заголовки
|
||||||
header_row = TableRow()
|
header_row = TableRow()
|
||||||
headers = ["Проект", "Версия", "Задача", "Статус", "Затрачено"]
|
headers = ["Наименование Проекта", "Номер версии*", "Задача", "Статус Готовность*", "Затрачено за отчетный период"]
|
||||||
for text in headers:
|
for text in headers:
|
||||||
cell = TableCell(stylename=cell_style)
|
cell = TableCell()
|
||||||
p = P(stylename=para_style, text=text)
|
p = P(stylename=para_style_name, text=text)
|
||||||
cell.addElement(p)
|
cell.addElement(p)
|
||||||
header_row.addElement(cell)
|
header_row.addElement(cell)
|
||||||
table.addElement(header_row)
|
table.addElement(header_row)
|
||||||
@@ -52,19 +54,19 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> OpenDocumentText:
|
|||||||
display_version = version if (project != prev_project or version != prev_version) else ""
|
display_version = version if (project != prev_project or version != prev_version) else ""
|
||||||
|
|
||||||
row = TableRow()
|
row = TableRow()
|
||||||
for col_text in [
|
cells_content = [
|
||||||
display_project,
|
display_project,
|
||||||
display_version,
|
display_version,
|
||||||
f"{issue.id}. {issue.subject}",
|
f"{issue.id}. {issue.subject}",
|
||||||
status_ru,
|
status_ru,
|
||||||
hours_to_human(hours)
|
"" # как в скриншоте
|
||||||
]:
|
]
|
||||||
cell = TableCell(stylename=cell_style)
|
for col_text in cells_content:
|
||||||
p = P(stylename=para_style, text=col_text)
|
cell = TableCell()
|
||||||
|
p = P(stylename=para_style_name, text=col_text)
|
||||||
cell.addElement(p)
|
cell.addElement(p)
|
||||||
row.addElement(cell)
|
row.addElement(cell)
|
||||||
table.addElement(row)
|
table.addElement(row)
|
||||||
|
|
||||||
prev_project = project
|
prev_project = project
|
||||||
prev_version = version
|
prev_version = version
|
||||||
|
|
||||||
|
|||||||
BIN
template.odt
Normal file
BIN
template.odt
Normal file
Binary file not shown.
Reference in New Issue
Block a user