Update template with table-styles
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
from redminelib.resources import Issue
|
from redminelib.resources import Issue
|
||||||
from odf.opendocument import load
|
from odf.opendocument import load
|
||||||
@@ -5,7 +6,6 @@ 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]]) -> "OpenDocument":
|
def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
||||||
@@ -21,7 +21,7 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
|||||||
header_paragraph = P(stylename=para_style_name, text=header_text)
|
header_paragraph = P(stylename=para_style_name, text=header_text)
|
||||||
doc.text.addElement(header_paragraph)
|
doc.text.addElement(header_paragraph)
|
||||||
|
|
||||||
# Группировка: project → version → [(issue, hours, status_ru)]
|
# Группировка: project - version - [(issue, hours, status_ru)]
|
||||||
projects = {}
|
projects = {}
|
||||||
for issue, hours in issue_hours:
|
for issue, hours in issue_hours:
|
||||||
project = str(issue.project)
|
project = str(issue.project)
|
||||||
@@ -35,7 +35,7 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
|||||||
projects[project][version] = []
|
projects[project][version] = []
|
||||||
projects[project][version].append((issue, hours, status_ru))
|
projects[project][version].append((issue, hours, status_ru))
|
||||||
|
|
||||||
# Создание таблицы
|
# Создаём таблицу
|
||||||
table = Table(name="Report")
|
table = Table(name="Report")
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
table.addElement(TableColumn())
|
table.addElement(TableColumn())
|
||||||
@@ -50,7 +50,7 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
|||||||
header_row.addElement(cell)
|
header_row.addElement(cell)
|
||||||
table.addElement(header_row)
|
table.addElement(header_row)
|
||||||
|
|
||||||
# Данные: двухуровневая группировка
|
# Данные с двухуровневой группировкой и объединением ячеек
|
||||||
for project, versions in projects.items():
|
for project, versions in projects.items():
|
||||||
total_project_rows = sum(len(rows) for rows in versions.values())
|
total_project_rows = sum(len(rows) for rows in versions.values())
|
||||||
first_version_in_project = True
|
first_version_in_project = True
|
||||||
@@ -62,7 +62,7 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
|||||||
for issue, hours, status_ru in rows:
|
for issue, hours, status_ru in rows:
|
||||||
row = TableRow()
|
row = TableRow()
|
||||||
|
|
||||||
# Ячейка "Проект" — только в первой строке всего проекта
|
# Ячейка "Проект" - только в первой строке всего проекта
|
||||||
if first_version_in_project and first_row_in_version:
|
if first_version_in_project and first_row_in_version:
|
||||||
cell_project = TableCell()
|
cell_project = TableCell()
|
||||||
cell_project.setAttribute("numberrowsspanned", str(total_project_rows))
|
cell_project.setAttribute("numberrowsspanned", str(total_project_rows))
|
||||||
@@ -70,7 +70,7 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
|||||||
cell_project.addElement(p)
|
cell_project.addElement(p)
|
||||||
row.addElement(cell_project)
|
row.addElement(cell_project)
|
||||||
|
|
||||||
# Ячейка "Версия" — только в первой строке каждой версии
|
# Ячейка "Версия" - только в первой строке каждой версии
|
||||||
if first_row_in_version:
|
if first_row_in_version:
|
||||||
cell_version = TableCell()
|
cell_version = TableCell()
|
||||||
cell_version.setAttribute("numberrowsspanned", str(row_span_version))
|
cell_version.setAttribute("numberrowsspanned", str(row_span_version))
|
||||||
@@ -79,7 +79,7 @@ def format_odt(issue_hours: List[Tuple[Issue, float]]) -> "OpenDocument":
|
|||||||
row.addElement(cell_version)
|
row.addElement(cell_version)
|
||||||
first_row_in_version = False
|
first_row_in_version = False
|
||||||
else:
|
else:
|
||||||
# Пропускаем — уже объединена
|
# Пропускаем - уже объединена
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Остальные колонки
|
# Остальные колонки
|
||||||
|
|||||||
BIN
template.odt
BIN
template.odt
Binary file not shown.
Reference in New Issue
Block a user